Hi all,
Trying to put together a script, I took the following from Virtu-Al and this works but for one set of variables, For the life of me I cant get this to work for more than just one portgroup
$OldNetwork = "PG1 192.168.0"
$NewNetwork = "PG2 10.1.1"
Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $OldNetwork} |Set-NetworkAdapter -NetworkName $NewNetwork -Confirm:$false
what I would like is something like
$OldNetwork1 = "PG1 192.168.0"
$NewNetwork1= "PG2 10.1.1"
$OldNetwork2 = "PG10"
$NewNetwork2= "PG2 "
so if the first "where" statement wouldn't match it would go on and try to match another old portgroup from the list of variables. Any help much appreciated tired of seeing red
thanks
Try like this
$OldNetwork1 = "PG1 192.168.0"
$NewNetwork1= "PG2 10.1.1"
$OldNetwork2 = "PG10"
$NewNetwork2= "PG2 "
Get-VM |Get-NetworkAdapter | %{
$_ | Where {$_.NetworkName -eq $OldNetwork1} |Set-NetworkAdapter -NetworkName $NewNetwork1 -Confirm:$false
$_ | Where {$_.NetworkName -eq $OldNetwork2} |Set-NetworkAdapter -NetworkName $NewNetwork2 -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
$OldNetwork1 = "PG1 192.168.0"
$NewNetwork1= "PG2 10.1.1"
$OldNetwork2 = "PG10"
$NewNetwork2= "PG2 "
Get-VM |Get-NetworkAdapter | %{
$_ | Where {$_.NetworkName -eq $OldNetwork1} |Set-NetworkAdapter -NetworkName $NewNetwork1 -Confirm:$false
$_ | Where {$_.NetworkName -eq $OldNetwork2} |Set-NetworkAdapter -NetworkName $NewNetwork2 -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, I couldn't get this thing to iterate through. Thanks again! as simple as it is, it saves me a whole load of man hours. although you can migrate an entire portgroup via vm networking not so simple when selecting individual guests a couple of hundred at a time.