你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Add-AzVmssSecret

Adds a secret to a VMSS.

Syntax

Add-AzVmssSecret
   [-VirtualMachineScaleSet] <PSVirtualMachineScaleSet>
   [[-SourceVaultId] <String>]
   [[-VaultCertificate] <VaultCertificate[]>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

The Add-AzVmssSecret cmdlet adds a secret to the Virtual Machine Scale Set (VMSS). The secret must be stored in an Azure Key Vault. For more information relating to Key Vault, see What is Azure Key Vault? (https://learn.microsoft.com/azure/key-vault/general/basic-concepts). For more information about the cmdlets, see Azure Key Vault Cmdlets or the Set-AzKeyVaultSecret cmdlet.

Examples

Example 1: Add a secret to the VMSS using the Azure Key Vault virtual machine extension

# 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

To install certificates on a virtual machine it is recommended to use the Azure Key Vault virtual machine extension for Linux or the Azure Key Vault virtual machine extension for Windows.

Example 2: Add a secret to the VMSS using Add-AzVmssSecret

$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

This example adds a secret to the VMSS. The first command uses the Get-AzKeyVault cmdlet to get a vault secret from the vault named ContosoVault and stores the result in the variable named $Vault. The second command uses the New-AzVmssVaultCertificateConfig cmdlet to create a Key Vault certificate configuration using the specified certificate URL from the certificate store named Certificates and stores the results in the variable named $CertConfig. The third command uses the New-AzVmssConfig cmdlet to create a VMSS configuration object and stores the result in the variable named $VMSS. The fourth command adds a secret to the VMSS using the vault secret using the key resource ID and the vault certificate stored in the $Vault and $CertConfig variables.

Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-SourceVaultId

Specifies the resource ID of the Key Vault that contains the certificates that you can add to the virtual machine. This value also acts as the key for adding multiple certificates. This means that you can use the same value for the SourceVaultId parameter when you add multiple certificates from the same Key Vault.

Type:String
Position:1
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-VaultCertificate

Specifies the Vault Certificate object that contains the certificate URL and certificate name. You can use the New-AzVmssVaultCertificateConfig cmdlet to create this object.

Type:VaultCertificate[]
Position:2
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-VirtualMachineScaleSet

Specifies the VMSS object. You can use the New-AzVmssConfig cmdlet to create this object.

Type:PSVirtualMachineScaleSet
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

PSVirtualMachineScaleSet

String

VaultCertificate[]

Outputs

PSVirtualMachineScaleSet