Thursday, 21 February 2019

Changing VM networks in bulk

WOW Its been a LONG TIME since I wrote a blog post!!

Anyway, a colleague today asked me how to change the vNetwork of hundreds of VMs automagically, so I cannibalized a previous post and came up with this;

The VMs can be on.
Put a list of the VM names into a CSV.
Change PATH-TO-CSV in the below script appropriately i.e. c:\vm_names.csv
Change NETWORK-NAME-HERE in the below script appropriately
Save the below as a .ps1 file and run

Let me know if it doesn't work on your Infrastructure!

$csv = import-csv PATH-TO-CSV

foreach ($line in $csv) {

 write-host **** Changing $line.vm to new network ****

$targetvm = $line.vm

get-vm $line.vm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName "NETWORK-NAME-HERE"
}


1 comment: