Share via

Set-AzVMExtension Command without handler version

Azuretech 95 Reputation points
2023-09-25T14:07:12.7233333+00:00

I have to use Set-AzVMExtension command to install extension like this

Set-AzVMExtension -ResourceGroupName "ResourceGroup11" -Location "West US" -VMName "VirtualMachine22" -Name "ContosoTest" -Publisher "Contoso.Compute" -ExtensionType "CustomScriptExtension" -TypeHandlerVersion "1.1" -Settings $Settings -ProtectedSettings $ProtectedSettings;

but I dont want to restrict the handlerversion to fixed value. I want that command should pick the latest handler version .Can you please let me know what the modification for it.

-

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Tushar Kumar 3,396 Reputation points MVP
    2023-09-25T15:12:12.5966667+00:00

    Hi Azuretech,

    Thank You for asking your question in Microsoft QnA.

    The Below code will provide you the latest version for any extension ;

    $Location = "West US"
    $Publisher = "Microsoft.Compute"
    $ExtensionType = "CustomScriptExtension"
    
    # Get the latest version of the Extension 
    $LatestVersion = (Get-AzVMExtensionImage -Location $Location -PublisherName $Publisher -Type $ExtensionType | Sort-Object -Property Version -Descending | Select-Object -First 1).Version
    

    You can use the same with your script to automatically fetch and feed in the latest version of extension.

    Please Click "Accept as answer" if this helps

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.