question

DeHavenGraham-3555 avatar image
0 Votes"
DeHavenGraham-3555 asked tbgangav-MSFT commented

Bulk Enable Azure Hybrdid Benefit for Windows VMs

How would I go about using the below script to enable multiple vms instead of one at a time?

$vm = Get-AzVM -ResourceGroup "rg-name" -Name "vm-name"
$vm.LicenseType = "Windows_Server"
Update-AzVM -ResourceGroupName rg-name -VM $vm
windows-server-powershellazure-automationazure-cloud-servicesdotnet-cli
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @DeHavenGraham-3555,

Did you get chance to check my earlier response? Let me know if you have further queries with regards to it.

0 Votes 0 ·

1 Answer

tbgangav-MSFT avatar image
1 Vote"
tbgangav-MSFT answered tbgangav-MSFT edited

Hi @DeHavenGraham-3555,

You can do the bulk changes for all VM's under a resource group with the help of below script.

 $VMs = Get-AzVM -ResourceGroupName xxxxxxxxxxxxxx | ?{$_.StorageProfile.OsDisk.OsType -eq "Windows"}
 foreach ($VM in $VMs){
 $VM.LicenseType = "Windows_Server"
 Update-AzVM -ResourceGroupName xxxxxxxxxxxxxx -resources -VM $VM
 }

Illustration:
204539-image.png

In the same way,

  1. you may do it at subscription level for all VMs by removing -ResourceGroupName parameter section in Get-AzVM line or

  2. you may do it at subscription level for specific list of VMs by removing Get-AzVM line and by having the list of VM's in an input csv file and using Import-CSV cmdlet you may call them one by one in an foreach block.

Let me know if you need any further clarification.


image.png (95.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.