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