Skip to content

Instantly share code, notes, and snippets.

@rajcheval
Created June 26, 2018 02:50
Show Gist options
  • Save rajcheval/adfbb85294ebb7087c43040d33b296f0 to your computer and use it in GitHub Desktop.
Save rajcheval/adfbb85294ebb7087c43040d33b296f0 to your computer and use it in GitHub Desktop.
Sample script showing how to update VM instances in VMSS
$PowershellScript =
@{
commandId = "RunPowerShellScript"
script =
@(
"Write-Output $env:computername",
"Get-Location"
)
}
$resourceGroupName = "iotci"
$vmssname = "rajvmss"
$vmss = get-azurermvmss -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssname
$vmcount = $vmss.sku.capacity
Write-Output "VMSS VM Count is $vmcount"
For ($i=0; $i -lt $vmcount; $i++) {
$vmid = $vmss.id + "/virtualMachines/$i"
Write-Output "VM ID is $vmid"
Write-Output "begin: invoking script against vmss instance $i"
Invoke-AzureRmResourceAction -ResourceId $vmid -Action runCommand -Parameters $PowershellScript -ApiVersion 2017-12-01 -force
Write-Output "finish: invoking script against vmss instance $i"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment