你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Add-AzVmssSecret
将机密添加到 VMSS。
语法
Add-AzVmssSecret
[-VirtualMachineScaleSet] <PSVirtualMachineScaleSet>
[[-SourceVaultId] <String>]
[[-VaultCertificate] <VaultCertificate[]>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
Add-AzVmssSecret cmdlet 向虚拟机规模集(VMSS)添加机密。 机密必须存储在 Azure Key Vault 中。 有关 Key Vault 的详细信息,请参阅 什么是 Azure Key Vault?(https://learn.microsoft.com/azure/key-vault/general/basic-concepts)。 有关 cmdlet 的详细信息,请参阅 Azure Key Vault Cmdlet 或 Set-AzKeyVaultSecret cmdlet。
示例
示例 1:使用 Azure Key Vault 虚拟机扩展将机密添加到 VMSS
# Build settings
$settings = @{
secretsManagementSettings = @{
pollingIntervalInS = "<pollingInterval>"
certificateStoreName = "<certStoreName>"
certificateStoreLocation = "<certStoreLoc>"
observedCertificates = @("<observedCert1>", "<observedCert2>")
}
} | ConvertTo-Json
$extName = "KeyVaultForLinux"
$extPublisher = "Microsoft.Azure.KeyVault"
$extType = "KeyVaultForLinux"
# Add Extension to VMSS
$vmss = Get-AzVmss -ResourceGroupName <ResourceGroupName> -VMScaleSetName <VmssName>
Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name $extName -Publisher $extPublisher -Type $extType -TypeHandlerVersion "2.0" -Setting $settings
# Start the deployment
Update-AzVmss -ResourceGroupName <ResourceGroupName> -VMScaleSetName <VmssName> -VirtualMachineScaleSet $vmss
若要在虚拟机上安装证书,建议使用适用于 Linux 的
示例 2:使用 Add-AzVmssSecret 向 VMSS 添加机密
$Vault = Get-AzKeyVault -VaultName "ContosoVault"
$CertConfig = New-AzVmssVaultCertificateConfig -CertificateUrl "http://keyVaultName.vault.contoso.net/secrets/secretName/secretVersion" -CertificateStore "Certificates"
$VMSS = New-AzVmssConfig
Add-AzVmssSecret -VirtualMachineScaleSet $VMSS -SourceVaultId $Vault.ResourceId -VaultCertificate $CertConfig
此示例将机密添加到 VMSS。 第一个命令使用 Get-AzKeyVault cmdlet 从名为 ContosoVault 的保管库中获取保管库机密,并将结果存储在名为$Vault的变量中。 第二个命令使用 New-AzVmssVaultCertificateConfig cmdlet 从名为 Certificates 的证书存储区使用指定的证书 URL 创建 Key Vault 证书配置,并将结果存储在名为 $CertConfig 的变量中。 第三个命令使用 New-AzVmssConfig cmdlet 创建 VMSS 配置对象,并将结果存储在名为$VMSS的变量中。 第四个命令使用密钥资源 ID 和存储在$Vault和$CertConfig变量中的保管库证书将机密添加到 VMSS。
参数
-Confirm
在运行 cmdlet 之前,提示你进行确认。
类型: | SwitchParameter |
别名: | cf |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-DefaultProfile
用于与 Azure 通信的凭据、帐户、租户和订阅。
类型: | IAzureContextContainer |
别名: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-SourceVaultId
指定 Key Vault 的资源 ID,其中包含可添加到虚拟机的证书。 此值还充当添加多个证书的密钥。 这意味着,从同一 Key Vault 添加多个证书时,可以为 SourceVaultId 参数使用相同的值。
类型: | String |
Position: | 1 |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-VaultCertificate
指定包含证书 URL 和证书名称的 Vault Certificate 对象。 可以使用 New-AzVmssVaultCertificateConfig cmdlet 来创建此对象。
类型: | VaultCertificate[] |
Position: | 2 |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-VirtualMachineScaleSet
指定 VMSS 对象。 可以使用 New-AzVmssConfig cmdlet 来创建此对象。
类型: | PSVirtualMachineScaleSet |
Position: | 0 |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 cmdlet 未运行。
类型: | SwitchParameter |
别名: | wi |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |