Bulk Enable Azure Hybrdid Benefit for Windows VMs

DeHaven Graham 101 Reputation points
2022-05-20T20:11:44.277+00:00

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
Azure Cloud Services
Azure Cloud Services
An Azure platform as a service offer that is used to deploy web and cloud applications.
636 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,114 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
322 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,364 questions
{count} votes

1 answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,381 Reputation points
    2022-05-23T07:28:11.42+00:00

    Hi @DeHaven Graham ,

    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.

    1 person found this answer helpful.
    0 comments No comments