你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Set-AzKeyVaultSecret
在密钥保管库中创建或更新机密。
语法
Set-AzKeyVaultSecret
[-VaultName] <String>
[-Name] <String>
[-SecretValue] <SecureString>
[-Disable]
[-Expires <DateTime>]
[-NotBefore <DateTime>]
[-ContentType <String>]
[-Tag <Hashtable>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Set-AzKeyVaultSecret
[-Id] <String>
[-SecretValue] <SecureString>
[-Disable]
[-Expires <DateTime>]
[-NotBefore <DateTime>]
[-ContentType <String>]
[-Tag <Hashtable>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Set-AzKeyVaultSecret
[-InputObject] <PSKeyVaultSecretIdentityItem>
[-SecretValue] <SecureString>
[-Disable]
[-Expires <DateTime>]
[-NotBefore <DateTime>]
[-ContentType <String>]
[-Tag <Hashtable>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
Set-AzKeyVaultSecret cmdlet 在 Azure Key Vault 的密钥保管库中创建或更新机密。 如果机密不存在,则此 cmdlet 会创建它。 如果机密已存在,此 cmdlet 将创建该机密的新版本。
示例
示例 1:使用默认属性修改机密的值
$Secret = ConvertTo-SecureString -String "****" -AsPlainText -Force
Set-AzKeyVaultSecret -VaultName 'Contoso' -Name 'ITSecret' -SecretValue $Secret
Vault Name : Contoso
Name : ITSecret
Version : 8b5c0cb0326e4350bd78200fac932b51
Id : https://contoso.vault.azure.net:443/secrets/ITSecret/8b5c0cb0326e4350bd78200fac932b51
Enabled : True
Expires :
Not Before :
Created : 5/25/2018 6:39:30 PM
Updated : 5/25/2018 6:39:30 PM
Content Type :
Tags :
第一个命令使用 ConvertTo-SecureString cmdlet 将字符串转换为安全字符串,然后将该字符串存储在$Secret变量中。 有关详细信息,请键入 Get-Help ConvertTo-SecureString
。
第二个命令修改名为 Contoso 的密钥保管库中名为 ITSecret 的机密的值。 机密值将成为存储在$Secret中的值。
示例 2:使用自定义属性修改机密的值
$Secret = ConvertTo-SecureString -String "****" -AsPlainText -Force
$Expires = (Get-Date).AddYears(2).ToUniversalTime()
$NBF =(Get-Date).ToUniversalTime()
$Tags = @{ 'Severity' = 'medium'; 'IT' = 'true'}
$ContentType = 'txt'
Set-AzKeyVaultSecret -VaultName 'Contoso' -Name 'ITSecret' -SecretValue $Secret -Expires $Expires -NotBefore $NBF -ContentType $ContentType -Disable -Tags $Tags
Vault Name : Contoso
Name : ITSecret
Version : a2c150be3ea24dd6b8286986e6364851
Id : https://contoso.vault.azure.net:443/secrets/ITSecret/a2c150be3ea24dd6b8286986e6364851
Enabled : False
Expires : 5/25/2020 6:40:00 PM
Not Before : 5/25/2018 6:40:05 PM
Created : 5/25/2018 6:41:22 PM
Updated : 5/25/2018 6:41:22 PM
Content Type : txt
Tags : Name Value
Severity medium
IT true
第一个命令使用 ConvertTo-SecureString cmdlet 将字符串转换为安全字符串,然后将该字符串存储在$Secret变量中。 有关详细信息,请键入 Get-Help ConvertTo-SecureString
。
下一个命令定义到期日期、标记和上下文类型的自定义属性,并将属性存储在变量中。
最后一个命令使用前面指定为变量的值,修改名为 Contoso 的密钥保管库中名为 ITSecret 的机密的值。
示例 3:使用默认属性修改机密的值(使用 Uri)
$Secret = ConvertTo-SecureString -String "****" -AsPlainText -Force
Set-AzKeyVaultSecret -Id 'https://contoso.vault.azure.net/secrets/ITSecret' -SecretValue $Secret
Vault Name : Contoso
Name : ITSecret
Version : 8b5c0cb0326e4350bd78200fac932b51
Id : https://contoso.vault.azure.net:443/secrets/ITSecret/8b5c0cb0326e4350bd78200fac932b51
Enabled : True
Expires :
Not Before :
Created : 5/25/2018 6:39:30 PM
Updated : 5/25/2018 6:39:30 PM
Content Type :
Tags :
此命令使用机密的 URI 在名为 Contoso 的 Key Vault 中设置或更新名为 secret1 的机密的值。
示例 4:通过模块 Microsoft.PowerShell.SecretManagement 中的命令 Set-Secret 在 Azure Key Vault 中创建机密
# Install module Microsoft.PowerShell.SecretManagement
Install-Module Microsoft.PowerShell.SecretManagement -Repository PSGallery -AllowPrerelease
# Register vault for Secret Management
Register-SecretVault -Name AzKeyVault -ModuleName Az.KeyVault -VaultParameters @{ AZKVaultName = 'test-kv'; SubscriptionId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }
# Set secret for vault AzKeyVault
$secure = ConvertTo-SecureString -String "****" -AsPlainText -Force
Set-Secret -Name secureSecret -SecureStringSecret $secure -Vault AzKeyVault
None
此示例通过模块 Microsoft.PowerShell.SecretManagement
中的命令 Set-Secret
在 azure Key Vault 中设置名为 secureSecret
的机密 test-kv
。
参数
-Confirm
在运行 cmdlet 之前,提示你进行确认。
类型: | SwitchParameter |
别名: | cf |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-ContentType
指定机密的内容类型。 若要删除现有内容类型,请指定一个空字符串。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-DefaultProfile
用于与 azure 通信的凭据、帐户、租户和订阅
类型: | IAzureContextContainer |
别名: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Disable
指示此 cmdlet 禁用机密。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Expires
指定此 cmdlet 更新的机密的过期时间(DateTime 对象)。
此参数使用协调世界时(UTC)。 若要获取 DateTime 对象,请使用 Get-Date cmdlet。 有关详细信息,请键入 Get-Help Get-Date
。
类型: | DateTime |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Id
KeyVault 机密的 URI。
请确保它遵循以下格式:https://<vault-name>.vault.azure.net/secrets/<secret-name>/<version>
类型: | String |
别名: | SecretId |
Position: | 0 |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-InputObject
Secret 对象
类型: | PSKeyVaultSecretIdentityItem |
Position: | 0 |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-Name
指定要修改的机密的名称。 此 cmdlet 基于此参数指定的名称、密钥保管库的名称和当前环境构造机密的完全限定域名(FQDN)。
类型: | String |
别名: | SecretName |
Position: | 1 |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-NotBefore
将时间指定为 DateTime 对象,在该对象之前无法使用机密。 此参数使用 UTC。 若要获取 DateTime 对象,请使用 Get-Date cmdlet。
类型: | DateTime |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-SecretValue
将机密的值指定为 SecureString 对象。 若要获取 SecureString 对象,请使用 ConvertTo-SecureString cmdlet。 有关详细信息,请键入 Get-Help ConvertTo-SecureString
。
类型: | SecureString |
Position: | 2 |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-Tag
以哈希表的形式进行键值对。 例如:@{key0=“value0”;key1=$null;key2=“value2”}
类型: | Hashtable |
别名: | Tags |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-VaultName
指定此机密所属的密钥保管库的名称。 此 cmdlet 基于此参数指定的名称和当前环境构造密钥保管库的 FQDN。
类型: | String |
Position: | 0 |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 cmdlet 未运行。
类型: | SwitchParameter |
别名: | wi |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |