Automation

 View Only
  • 1.  Script to connet portgroup for multiple VM

    Posted Jan 08, 2021 10:41 AM

    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

     



  • 2.  RE: Script to connet portgroup for multiple VM

    Posted Jan 08, 2021 03:36 PM

    are you using SRM?



  • 3.  RE: Script to connet portgroup for multiple VM

    Posted Jan 10, 2021 08:37 PM

    I do not have SRM, that is why looking for script if one can help



  • 4.  RE: Script to connet portgroup for multiple VM

    Posted Jan 11, 2021 04:50 PM

    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?



  • 5.  RE: Script to connet portgroup for multiple VM

    Posted Jan 12, 2021 09:14 PM

    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



  • 6.  RE: Script to connet portgroup for multiple VM

    Posted Jan 16, 2021 10:45 AM
    # 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