azure - 在 Azure KeyVault 机密版本上编辑现有标记值
问题描述
我的目标是在我的 KeyVault 中创建特定机密的新版本,并将当前版本的所有标签复制到新版本。但是,在这样做的同时,我想更改其中一个标签的值并保持其余标签不变。
$CurrentSecret = Get-AzKeyVaultSecret -VaultName $VaultName -Name $SecretName -IncludeVersions
$ActiveSecret = $CurrentSecret[0]
$NewSecret = New-AzServiceBusKey -Name $SecretName -ResourceGroup $ResourceGroupName -Namespace $SBNameSpace -RegenerateKey PrimaryKey
$NewSecretValue = $NewSecret.PrimaryKey
$SecureStringNewKey = ConvertTo-SecureString -String $NewSecretValue -AsPlainText -Force
$EndDate = (Get-Date).AddMonths(12)
$SecretObject = Set-AzKeyVaultSecret -VaultName $VaultName -Name $SecretName -SecretValue $SecureStringNewKey -Expires $EndDate -ContentType $ActiveSecret.ContentType -Tag $ActiveSecret.Tags
PS E:\XXX> $SecretObject.Tags
Name Value
---- -----
KeyType Primary
SecretType ServiceBusKey
我想将“KeyType”的值更改为“Secondary”并保持一切不变。
我尝试了以下方法,但它按预期覆盖了该值:
$Tags = @{ 'KeyType' = 'Secondary'}
$New = Update-AzKeyVaultSecret -VaultName $VaultName -Name $SecretName -Expires $EndDate -ContentType $ActiveSecret.ContentType -Enable $True -Tag $Tags -PassThru
$New.Tags
Name Value
---- -----
KeyType Secondary
最终,原始版本中的标签将增加到 10 个左右。我不期待在更新标签时将枚举器中的所有内容指定为代码中的核心值的方法。我尝试查看 $New.Tags.KeyType。(Length,Clone,GetEnumerator,GetHashCode,CompareTo,Contains,CopyTo,EndsWith,Equals) 但找不到仅将 KeyType 标记的值更新为“次要”的方法
解决方案
好吧,如果我理解你的意思,你已经创建了新版本的秘密,你想Tag
现在更新它,请在之后尝试下面的命令Set-AzKeyVaultSecret
。
$sec = Get-AzKeyVaultSecret -VaultName $VaultName -Name $SecretName
$sec.Tags.KeyType = "Secondary"
Update-AzKeyVaultSecret -VaultName $VaultName -Name $VaultName -Tag $sec.Tags
或者你可以直接使用下面的命令,它也可以工作。
$SecretObject = Set-AzKeyVaultSecret -VaultName $VaultName -Name $SecretName -SecretValue $SecureStringNewKey -Expires $EndDate -ContentType $ActiveSecret.ContentType -Tag $ActiveSecret.Tags
$SecretObject.Tags.KeyType = "Secondary"
Update-AzKeyVaultSecret -VaultName $VaultName -Name mySecret123 -Tag $SecretObject.Tags
推荐阅读
- node.js - 将环境连接到猫鼬时出现错误
- javascript - 通过将嵌套属性与搜索词进行比较来过滤
- c# - 我可以在 C# 的 2 个不同的类中使用相同的枚举吗?
- node.js - node js cron作业在每个月的第一天都不工作
- php - ACF 自定义字段、自定义帖子类型和引导轮播
- flutter - Flutter:强制modalBottomSheet仅在单击按钮时关闭
- javascript - 输入文本框“on the fly”过滤列表
- go - 如何使用 ListenTCP 收听 0.0.0.0:8080
- batch-file - 编辑脚本以便它只为存在的文件创建快捷方式?
- r - 如何更改 R 中空白的千位分隔符?