Set-AzureRmVMExtension

Updates extension properties or adds an extension to a virtual machine.

Warning

The AzureRM PowerShell module has been officially deprecated as of February 29, 2024. Users are advised to migrate from AzureRM to the Az PowerShell module to ensure continued support and updates.

Although the AzureRM module may still function, it's no longer maintained or supported, placing any continued use at the user's discretion and risk. Please refer to our migration resources for guidance on transitioning to the Az module.

Syntax

Set-AzureRmVMExtension
   -Publisher <String>
   -ExtensionType <String>
   [-Settings <Hashtable>]
   [-ProtectedSettings <Hashtable>]
   [-AsJob]
   [-ResourceGroupName] <String>
   [-VMName] <String>
   [-Name <String>]
   [-TypeHandlerVersion <String>]
   [-Location <String>]
   [-DisableAutoUpgradeMinorVersion]
   [-ForceRerun <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-AzureRmVMExtension
   -Publisher <String>
   -ExtensionType <String>
   [-SettingString <String>]
   [-ProtectedSettingString <String>]
   [-AsJob]
   [-ResourceGroupName] <String>
   [-VMName] <String>
   [-Name <String>]
   [-TypeHandlerVersion <String>]
   [-Location <String>]
   [-DisableAutoUpgradeMinorVersion]
   [-ForceRerun <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

The Set-AzureRmVMExtension cmdlet updates properties for existing Virtual Machine Extensions or adds an extension to a virtual machine.

Examples

Example 1: Modify settings by using hash tables

PS C:\> $Settings = @{"fileUris" = "[]"; "commandToExecute" = ""};
PS C:\> $ProtectedSettings = @{"storageAccountName" = $stoname; "storageAccountKey" = $stokey};
PS C:\> Set-AzureRmVMExtension -ResourceGroupName "ResourceGroup11" -Location "West US" -VMName "VirtualMachine22" -Name "ContosoTest" -Publisher "Contoso.Compute" -Type "CustomScriptExtension" -TypeHandlerVersion "1.1" -Settings $Settings -ProtectedSettings $ProtectedSettings;

The first two commands use standard Windows PowerShell syntax to create hash tables, and then stores those hash tables in the $Settings and $ProtectedSettings variables. For more information, type Get-Help about_Hash_Tables. The second command includes two values previously created and stored in variables. The final command modifies an extension of the virtual machine named VirtualMachine22 in ResourceGroup11 according to the contents of $Settings and $ProtectedSettings. The command specifies other required information that includes the publisher and the extension type.

Example 2: Modify settings by using strings

PS C:\> $SettingsString = '{"fileUris":[],"commandToExecute":""}';
PS C:\> $ProtectedSettingsString = '{"storageAccountName":"' + $stoname + '","storageAccountKey":"' + $stokey + '"}';
PS C:\> Set-AzureRmVMExtension -ResourceGroupName "ResourceGroup11" -Location "West US" -VMName "VirtualMachine22" -Name "CustomScriptExtension" -Publisher "Contoso.Compute" -Type "CustomScriptExtension" -TypeHandlerVersion "1.1" -SettingString $SettingsString -ProtectedSettingString $ProtectedSettingsString ;

The first two commands create strings that contain settings, and then stores them in the $SettingsString and $ProtectedSettingsString variables. The final command modifies an extension of the virtual machine named VirtualMachine22 in ResourceGroup11 according to the contents of $SettingsString and $ProtectedSettingsString. The command specifies other required information that includes the publisher and the extension type.

Parameters

-AsJob

Run cmdlet in the background

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

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
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:AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DisableAutoUpgradeMinorVersion

Indicates that this cmdlet prevents the Azure guest agent from automatically updating the extensions to a newer minor version. By default, this cmdlet enables the guest agent to update the extensions.

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

-ExtensionType

Specifies the extension type.

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

-ForceRerun

Indicates that this cmdlet forces a rerun of the same extension configuration on the virtual machine without uninstalling and reinstalling the extension. The value can be any string different from the current value. If forceUpdateTag is not changed, updates to public or protected settings are still applied by the handler.

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

-Location

Specifies the location of the virtual machine.

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

-Name

Specifies the name of an extension.

Type:String
Aliases:ExtensionName
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-ProtectedSettings

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

Type:Hashtable
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-ProtectedSettingString

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

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

-Publisher

Specifies the name of the extension publisher. The publisher provides a name when the publisher registers an extension.

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

-ResourceGroupName

Specifies the name of the resource group of the virtual machine.

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

-Settings

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

Type:Hashtable
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-SettingString

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

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

-TypeHandlerVersion

Specifies the version of the extension to use for this virtual machine.

Type:String
Aliases:HandlerVersion, Version
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-VMName

Specifies the name of a virtual machine. This cmdlet modifies extensions for the virtual machine that this parameter specifies.

Type:String
Aliases:ResourceName
Position:1
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:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

String

Hashtable

SwitchParameter

Outputs

PSAzureOperationResponse