VMware Cloud Community
SurajRawat
Contributor
Contributor
Jump to solution

Script for DVSwitch Configuration

Hello,

Does anyone have a script to get the VDS information on the host level as to which nic is connected to which uplink ?

Also to remove any portgroups created in the VDS switch for the host and then to recreate the portgroups as they were after connecting the host to a diff vCenter ?

Also any script to copy the resource pools across VCenter ?

Thanks,

Suraj Rawat

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The following script will export the VDS information for the uplinks, the port they are on and which pNIC is used per ESXi node.

$report = foreach($dvSw in Get-VDSwitch){

  foreach($esx in (Get-View -id $dvSw.ExtensionData.Summary.HostMember)){

    $proxy = $esx.Config.Network.ProxySwitch | where{$_.DvsUuid -eq $dvSw.ExtensionData.Uuid}

    $pnicTab = @{}

    $proxy.Spec.Backing.PnicSpec | %{

      $pnicTab.Add($_.UplinkPortKey,$_.PnicDevice)

    }

    $proxy.UplinkPort |

    Select @{N='vdSwitch';E={$dvSw.Name}},

      @{N='VMHost';E={$esx.Name}},

      @{N='vNIC';E={$pnicTab[$_.Key]}},

      @{N='Uplink';E={$_.Value}},

      @{N='Port';E={$_.Key}}

  }

}

$report | Export-Csv C:\dvSw-Uplink.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

The following script will export the VDS information for the uplinks, the port they are on and which pNIC is used per ESXi node.

$report = foreach($dvSw in Get-VDSwitch){

  foreach($esx in (Get-View -id $dvSw.ExtensionData.Summary.HostMember)){

    $proxy = $esx.Config.Network.ProxySwitch | where{$_.DvsUuid -eq $dvSw.ExtensionData.Uuid}

    $pnicTab = @{}

    $proxy.Spec.Backing.PnicSpec | %{

      $pnicTab.Add($_.UplinkPortKey,$_.PnicDevice)

    }

    $proxy.UplinkPort |

    Select @{N='vdSwitch';E={$dvSw.Name}},

      @{N='VMHost';E={$esx.Name}},

      @{N='vNIC';E={$pnicTab[$_.Key]}},

      @{N='Uplink';E={$_.Value}},

      @{N='Port';E={$_.Key}}

  }

}

$report | Export-Csv C:\dvSw-Uplink.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
pargit
Enthusiast
Enthusiast
Jump to solution

Hi,

Thanks for this script, but i need to add the MAC of the vmnic for each line.

i tried adding this line but it keeps giving empty result

@{N='Mac';E={Get-VMHostNetworkAdapter -VMHost $(Get-VMHost -name $esx.Name)| Where-Object {$_.Name -eq $pnicTab[$_.Key]} |select Mac}},

what am i missing?

thanks

Mordechai

Reply
0 Kudos