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>]
Description
Set-AzKeyVaultSecret Cmdlet 會在 Azure 金鑰保存庫的金鑰保存庫中建立或更新秘密。 如果秘密不存在,此 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 的金鑰保存庫中名為 secret1 的秘密值。
範例 4:透過模組 Microsoft.PowerShell.SecretManagement 中的命令 Set-Secret 在 Azure 金鑰保存庫中建立秘密
# 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 金鑰保存庫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
秘密物件
InputObject
Position: 0
必要: True
來自管線的值: True
來自管線按屬性名稱的值: False
來自剩餘引數的值: False
-Name
指定要修改的密碼名稱。 此 Cmdlet 會根據此參數指定的名稱、金鑰保存庫的名稱,以及您目前的環境,建構秘密的完整網域名稱 (FQDN)。
參數屬性
類型: String
預設值: None
支援萬用字元: False
不要顯示: False
別名: 秘密名稱
參數集
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=“值2”}
參數屬性
類型: Hashtable
預設值: None
支援萬用字元: False
不要顯示: False
別名: Tags
參數集
(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 。
輸出