【发布时间】:2020-12-28 03:43:02
【问题描述】:
我有一个 Powershell 脚本,它使用 Azure Powershell 更新虚拟机规模集(在 Azure Service Fabric 下),以添加/删除关联的 Service Fabric 虚拟机使用的证书。此脚本按预期工作,我有以下命令(我已删除一些其他逻辑以专注于该问题):
# This gets the Virtual Machine Scale Set object
$virtualMachineScaleSet = Get-Azvmss -ResourceGroupName $myResourceGroupName -VMScaleSetName $myVMScaleSetName
# Example of removing items from certificate items from the VMSS object.
$virtualMachineScaleSet.VirtualMachineProfile.osProfile.Secrets[$mySecretIndex].VaultCertificates.RemoveAt($myCertificateIndexThatIWantToRemove)
# Example of creating new certificate config
$newCertificateUrl = (Get-AzKeyVaultCertificate -VaultName $myKeyvaultName -Name $myCertificateName).SecretId
$newCertificateConfig = New-AzvmssVaultCertificateConfig -CertificateUrl $newCertificateUrl -CertificateStore "My"
# Example of adding new certificate to the VMSS object
$virtualMachineScaleSet.VirtualMachineProfile.OsProfile.Secrets[$mySecretIndex].VaultCertificates.Add($newCertificateConfig)
# Committing the update to VMSS
Update-Azvmss -ResourceGroupName $myResourceGroupName -VirtualMachineScaleSet $virtualMachineScaleSet -VMScaleSetName $myVMScaleSetName
上面的脚本工作正常。但是,我现在正尝试将上述每个命令转换为 Azure CLI。脚本调用的方式意味着我不能在同一个脚本中混合和匹配 Azure Powershell 和 Azure CLI 命令。到目前为止我的命令导致问题:
# This gets me the Virtual Machine Scale Set object
$virtualMachineScaleSet = az vmss show --name $myVMScaleSetName --resource-group $myResourceGroupName | ConvertFrom-Json
# Trying to RemoveAt gives the error: MethodInvocationException: Exception calling "RemoveAt" with "1" argument(s): "Collection was of a fixed size."
$virtualMachineScaleSet.VirtualMachineProfile.osProfile.Secrets[$mySecretIndex].VaultCertificates.RemoveAt($myCertificateIndexThatIWantToRemove)
# Not sure the CLI equivalent commands of this
$newCertificateUrl = (Get-AzKeyVaultCertificate -VaultName $myKeyvaultName -Name $myCertificateName).SecretId
$newCertificateConfig = New-AzvmssVaultCertificateConfig -CertificateUrl $newCertificateUrl -CertificateStore "My"
# Trying to Add gives the error: MethodInvocationException: Exception calling "RemoveAt" with "1" argument(s): "Collection was of a fixed size."
$virtualMachineScaleSet.VirtualMachineProfile.OsProfile.Secrets[$mySecretIndex].VaultCertificates.Add($newCertificateConfig)
所以我的问题是。
- Azure Powershell 脚本的 CLI 等效命令是什么?
- 为什么 Azure CLI 脚本中的 VMSS 对象看起来不一样? (至少我无法更改 VaultCertificates 数组)
提前谢谢你
【问题讨论】:
-
当我使用 Az Powershell 运行
$virtualMachineScaleSet.VirtualMachineProfile.osProfile.Secrets[0].VaultCertificates.RemoveAt(0)时,它显示相同的错误Exception calling "RemoveAt" with "1" argument(s): "Collection was of a fixed size."您能否再次确认此 cmd 与 Az Powershell 一起正常工作? -
您好,您解决了这个问题吗?如果是,您可以发布答案吗?
-
这个问题还有更多更新吗?它能解决你的问题吗?
-
什么原因没有回复?!如果可行,则接受它,如果不可行,请给出问题,这是一个简单的响应。
标签: azure powershell azure-service-fabric azure-powershell azure-vm-scale-set