Set-AzKeyVaultSecret
语法
Default (默认值)
Set-AzKeyVaultSecret
[-VaultName] <String>
[-Name] <String>
[-SecretValue] <SecureString>
[-Disable]
[-Expires <DateTime>]
[-NotBefore <DateTime>]
[-ContentType <String>]
[-Tag <Hashtable>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
BySecretUri
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
本示例通过模块secureSecret中的命令test-kv设置 Azure Key Vault Set-Secret 中命名Microsoft.PowerShell.SecretManagement的机密。
参数
-Confirm
在运行 cmdlet 之前,提示你进行确认。
参数属性
参数集
(All)
Position: Named
必需: False
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-ContentType
指定机密的内容类型。
若要删除现有内容类型,请指定一个空字符串。
参数属性
类型: String
默认值: None
支持通配符: False
不显示: False
参数集
(All)
Position: Named
必需: False
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-DefaultProfile
用于与 azure 通信的凭据、帐户、租户和订阅
参数属性
参数集
(All)
Position: Named
必需: False
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-Disable
指示此 cmdlet 禁用机密。
参数属性
参数集
(All)
Position: Named
必需: False
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-Expires
指定此 cmdlet 更新的机密的过期时间(作为 DateTime 对象)。
此参数使用协调世界时(UTC)。 若要获取 DateTime 对象,请使用 Get-Date cmdlet。 有关详细信息,请键入 Get-Help Get-Date。
参数属性
参数集
(All)
Position: Named
必需: False
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-Id
KeyVault 机密的 URI。
请确保它遵循以下格式: https://<vault-name>.vault.azure.net/secrets/<secret-name>/<version>
参数属性
类型: String
默认值: None
支持通配符: False
不显示: False
别名: SecretId
参数集
BySecretUri
Position: 0
必需: True
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
Secret 对象
InputObject
Position: 0
必需: True
来自管道的值: True
来自管道的值(按属性名称): False
来自剩余参数的值: False
-Name
指定要修改的机密的名称。 此 cmdlet 基于此参数指定的名称、密钥保管库的名称和当前环境构造机密的完全限定域名(FQDN)。
参数属性
类型: String
默认值: None
支持通配符: False
不显示: False
别名: SecretName
参数集
Default
Position: 1
必需: True
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-NotBefore
将时间指定为 DateTime 对象,在该对象之前无法使用机密。 此参数使用 UTC。 若要获取 DateTime 对象,请使用 Get-Date cmdlet。
参数属性
参数集
(All)
Position: Named
必需: False
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-SecretValue
将机密的值指定为 SecureString 对象。 若要获取 SecureString 对象,请使用 ConvertTo-SecureString cmdlet。 有关详细信息,请键入 Get-Help ConvertTo-SecureString。
参数属性
参数集
(All)
Position: 2
必需: True
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-Tag
以哈希表的形式进行键值对。 例如:@{key0=“value0”;key1=$null;key2=“value2”}
参数属性
类型: Hashtable
默认值: None
支持通配符: False
不显示: False
别名: 标记
参数集
(All)
Position: Named
必需: False
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-VaultName
指定此机密所属的密钥保管库的名称。 此 cmdlet 基于此参数指定的名称和当前环境构造密钥保管库的 FQDN。
参数属性
类型: String
默认值: None
支持通配符: False
不显示: False
参数集
Default
Position: 0
必需: True
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
-WhatIf
显示 cmdlet 运行时会发生什么情况。
命令脚本未运行。
参数属性
参数集
(All)
Position: Named
必需: False
来自管道的值: False
来自管道的值(按属性名称): False
来自剩余参数的值: False
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters 。
输出