Im using this script to change the Port Group on all VM's on a single host, Im looking for a script that will change all the PG's on all VM's under a specific folder, rather than the whole entire host.
# Change the port group for all VM's on a host
$vmhost = "VMHOST NAME"
$OldNetwork = "VMNetwork"
$NewNetwork = "VLAN-1091"
Get-VMHost $vmhost |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $OldNetwork } |Set-NetworkAdapter -NetworkName $NewNetwork -Confirm:$false
If you replace the Get-VMHost with a Get-Folder you should be there.
Get-Folder -Name MyFolder | Get-VM | ....
Or do you mean something different ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I couldnt thing of the Get-Folder cmdlet... that should work.
In my script I have it using the VMNetwork PG, but its actually Invalid Backing (since it came from a vDS that doesnt exist in the new cluster). Is there a way to set the PG regardless of the OLD Network name?
I actually just removed the $OldNetwork and it worked fine.