Created
June 26, 2018 02:50
-
-
Save rajcheval/adfbb85294ebb7087c43040d33b296f0 to your computer and use it in GitHub Desktop.
Sample script showing how to update VM instances in VMSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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