Skip to content


Cambiar VMs PortGroups en bloque (bulk)

I have a cluster with 129 Vlans distributed portgroups, and I need to move this cluster to another Vcenter
Using different pieces (thanks LucD and many others) I put together a script to perform this action. Its available at GitHub – Vidanez/Migrate-vCenter-with-vDS: Migrate from one vcenter to another a Esxi host
The resume is that the script pass everything from one vcenter to another changing in the fly VDS to VSS and respecting folders, permissions and DRS rules.
The problem come when you need to move 129 portgroups. My code change VM by VM base on the information saved and this is really slow.

Note: during the migration the portgroups which are named as VLAN-XXX got VSS as Mig-VLANXXX

So I tried another 3 methods:

1. I got a list of port on a file vlans

cat vlans | foreach { $value=$_ ; Get-Cluster CLUSTER01 |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq "Mig-"$value } |Set-NetworkAdapter -RunAsync -NetworkName $value -Confirm:$false }

2. I wrote a little script:

$VMadpts = Get-Cluster CLUSTER01 |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -like "Mig-*" }
foreach ( $VMadpt in $VMadpts)
{
$val = $VMadpt.NetworkName.TrimStart("Mig-")
Set-NetworkAdapter -NetworkAdapter $VMadpt -RunAsync -NetworkName $val -Confirm:$false
}

3. I used a command:

Get-Cluster CLUSTER01 |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -like "Mig-*" } | foreach { $val=$_ ; $valnet=$_.NetworkName.TrimStart("Mig-"); Set-NetworkAdapter -NetworkAdapter $val -NetworkName $valnet -RunAsync -Confirm:$false }

Which do you think would be the faster one? and why?

Also I need to refactor my script for high number of vlans environments and also it has a error creating distributed portgroup that left them without active uplink.

Posted in SCRIPTING, VMWARE.

Tagged with , , , , , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.