All VM network/port groups in DR site after array based replication gets disconnected as per vmware design, Need help to find script to connect all VM in DR site with their correct port group from file as per primary site
Thanks
are you using SRM?
I do not have SRM, that is why looking for script if one can help
are your replicated VMs onto a single vCluster or virtual DC? Do you use distributed vSwitches? Is the recovery site under the same vCenter server?
I have built the new vCenter in DR site with same build like production Site and did export/import network configuration(Distributed Switch) from Primary site into DR Vcenter. Added all replicated VM into DR Vcenter and have to attach each VM every time replication is stopped.
looking for Script to connect each vm in DR site with same port group like primary site and yes they are in single Virtual Cluster in DR Site
# this part runs on the protected site and fills a csv file
Get-Cluster <clusterName> | Get-VM | Select Name, @{N='PortgroupVlanId';E={(Get-VirtualPortGroup -Name (Get-NetworkAdapter -VM $_).NetworkName -VMHost $_.VMHost).VlanId -join '|'}} |
Export-Csv -Path C:\Test\report.csv -NoTypeInformation -UseCulture
# this part runs on the recovery site
$VMs = Import-Csv -Path C:\Test\report.csv
forEach($vm in $VMs){
$VDPortGroup = Get-VMHost -VM (Get-VM $vm.Name) | Get-VDSwitch | Get-VDPortgroup | Where-Object{$_.VlanConfiguration -match "VLAN $($vm.PortgroupVlanId)"}
Get-VM -Name $vm.Name | Get-NetworkAdapter |
Set-NetworkAdapter -Connected:$true -StartConnected $true -Confirm:$false |
Set-NetworkAdapter -Portgroup $VDPortGroup -Confirm:$false
}
I'm travelling sorry... the script above should do it but I wrote it without an environment to test it over. I gave for granted you use dvSwitches