Powershell: Change Network Label

I ran into the situation where I needed to change the network label on hundreds of VM’s after acquiring a Nexus switch. There was no way I could have accomplished this manually during a small outage window. You run this script directly from the console; just type the new network label and hit enter and watch the magic. It’s a really short script and pretty self-explanatory.

$NetworkName = Read-Host "Enter the network name"
Get-VM -Location "I used vCenter Folder" | get-networkadapter | set-networkadapter -networkname $NetworkName -Confirm:$false