Edit

Share via


Add-AzVmssExtension

Adds an extension to the VMSS.

Syntax

Default (Default)

Add-AzVmssExtension
    [-VirtualMachineScaleSet] <PSVirtualMachineScaleSet>
    [[-Name] <String>]
    [[-Publisher] <String>]
    [[-Type] <String>]
    [[-TypeHandlerVersion] <String>]
    [[-AutoUpgradeMinorVersion] <Boolean>]
    [[-Setting] <Object>]
    [[-ProtectedSetting] <Object>]
    [-EnableAutomaticUpgrade <Boolean>]
    [-ForceUpdateTag <String>]
    [-ProvisionAfterExtension <String[]>]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The Add-AzVmssExtension cmdlet adds an extension to the Virtual Machine Scale Set (VMSS).

Examples

Example 1: Add an extension to the VMSS

Add-AzVmssExtension -VirtualMachineScaleSet $VMSS -Name $ExtName -Publisher $Publisher -Type $ExtType -TypeHandlerVersion $ExtVer -AutoUpgradeMinorVersion $True

This command adds an extension to the VMSS.

Example 2: Add an extension to the VMSS with settings and protected settings

$Settings = @{"fileUris" = "[]"; "commandToExecute" = ""};
$ProtectedSettings = @{"storageAccountName" = $stoname; "storageAccountKey" = $stokey};

Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name $vmssExtensionName -Publisher $vmssPublisher  `
  -Type $vmssExtensionType -TypeHandlerVersion $ExtVer -AutoUpgradeMinorVersion $True  `
  -Setting $Settings -ProtectedSetting $ProtectedSettings

Example 3: Add an extension to the VMSS with settings and protected settings

$BatchFile = "runbook.sh"
$ResourceGroupName = "HelloRG"
$VMScaleSetName = "HelloVmSS"
$TypeHandlerVersion = 2.1

#Best Practice for secured parameters.
$protectedSettings = @{
"managedIdentity" = @{ "clientId" = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"};
}

$publicSettings = @{
"fileUris"= (,"https://storage.blob.core.windows.net/itfiles/$($BatchFile)");
"commandToExecute"= "sh $($BatchFile)"
}

# Get information about the scale set
$vmss = Get-AzVmss `
            -ResourceGroupName $ResourceGroupName `
            -VMScaleSetName $VMScaleSetName

Add-AzVmssExtension -VirtualMachineScaleSet $vmss `
    -Name "CustomScript" `
    -Publisher "Microsoft.Azure.Extensions" `
    -Type "CustomScript" `
    -TypeHandlerVersion $TypeHandlerVersion `
    -AutoUpgradeMinorVersion $true `
    -Setting $publicSettings `
    -ProtectedSetting $protectedSettings

Update-AzVmss `
    -ResourceGroupName $ResourceGroupName `
    -Name $VMScaleSetName `
    -VirtualMachineScaleSet $vmss

This command adds an extension to the VMSS with a sample bash script on a blob storage, specify the url of blob storage and executable command in settings and security access in protected settings.

Parameters

-AutoUpgradeMinorVersion

Indicates whether the extension version should be automatically updated to a newer minor version.

Parameter properties

Type:

Nullable<T>[Boolean]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:5
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DefaultProfile

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

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-EnableAutomaticUpgrade

Indicates whether the extension should be automatically upgraded by the platform if there is a newer version of the extension available.

Parameter properties

Type:

Nullable<T>[Boolean]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ForceUpdateTag

If a value is provided and is different from the previous value, the extension handler will be forced to update even if the extension configuration has not changed.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Name

Specifies the name of the extension that this cmdlet adds.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:1
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ProtectedSetting

Specifies private configuration for the extension, as a string. This cmdlet encrypts the private configuration.

Parameter properties

Type:Object
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:7
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ProvisionAfterExtension

Collection of extension names after which this extension needs to be provisioned.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Publisher

Specifies the name of the extension publisher. The publisher provides a name when the publisher registers an extension. This can use the Get-AzVMImagePublisher cmdlet to get the publisher.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:2
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Setting

Specifies the public configuration, as a string, for the extension. This cmdlet does not encrypt public configuration.

Parameter properties

Type:Object
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:6
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Type

Specifies the extension type. You can use the Get-AzVMExtensionImageType cmdlet to get the extension type.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:3
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-TypeHandlerVersion

Specifies the version of the extension to use for this virtual machine. You can use the Get-AzVMExtensionImage cmdlet to get the version of the extension.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:4
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-VirtualMachineScaleSet

Specify the VMSS object. You can use the New-AzVmssConfig to create the object.

Parameter properties

Type:PSVirtualMachineScaleSet
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

-WhatIf

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

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

PSVirtualMachineScaleSet

String

Nullable<T>

Object

Outputs

PSVirtualMachineScaleSet