VMware Cloud Community
golddiggie
Champion
Champion
Jump to solution

Gather dvSwitch inventory from target vCenter script?

I'm looking to gather the portgroup list for all dvSwitches on target vCenters (vCSA) in our environment. Output should be to a csv file so that we can pull them into Excel and filter the data as needed. Or (perhaps) pull it into ansible sometime later.

If we only had a handful of portgroups in the dvSwitch, this wouldn't be an issue. But, our setup has a range of as few as 50 portgroups to over 1500 (in a single vCSA configuration). So you see the desire to get this output into a file to filter. Smiley Wink

Hoping the scripting GOD (aka LucD) can come up with something easy and fast. Smiley Wink

Worst case, we can log into a set vCSA via PowerCLI/PowerShell and then run the script. Or add a run parameter to the command to run it. Even if it needs to be the full vCSA name (FQDN, short name, or IP, whichever works).

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

In that case, just use Export-Csv instead

& { foreach ($vc in $global:DefaultVIServers)

   {

   Get-VDSwitch -Server $vc |

   Get-VDPortgroup | select @{N = 'vCenter'; E = { $vc.Name } },

   @{N = 'vdSwitch'; E = { $_.VDSwitch.Name } },

   @{N = 'vdPortgroup'; E = { $_.Name } }

   } } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture

-------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

If you only need to see the names of vCenter, vdSwitch and vdPortgroup, you can do something like this.

Note that when you install the ImportExcel module, you can export directly to an .XLSX file.

If you don't need the Uplinks portgroup in the result, those can be filtered out with a Where-clause.
The script assumes you are connected to all the vCenters before running the script.

&{foreach($vc in $global:DefaultVIServers){

   Get-VDSwitch -Server $vc |

   Get-VDPortgroup | select @{N='vCenter';E={$vc.Name}},

   @{N='vdSwitch';E={$_.VDSwitch.Name}},

   @{N='vdPortgroup';E={$_.Name}}

}} | Export-Excel -Path .\report.xlsx -WorksheetName vdPortgroup -Show


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

Reply
0 Kudos
golddiggie
Champion
Champion
Jump to solution

Actually, just wanted it saved as a csv so we can do whatever we want with it. Since I'm sure we'll probably save the files for use later. Or as a check done after a environment build in a 'true-up' effort. Mostly because we're seeing cases where our production and recovery sides are not in sync.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

In that case, just use Export-Csv instead

& { foreach ($vc in $global:DefaultVIServers)

   {

   Get-VDSwitch -Server $vc |

   Get-VDPortgroup | select @{N = 'vCenter'; E = { $vc.Name } },

   @{N = 'vdSwitch'; E = { $_.VDSwitch.Name } },

   @{N = 'vdPortgroup'; E = { $_.Name } }

   } } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture

-------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

golddiggie
Champion
Champion
Jump to solution

Thanks... I used some of the information from a previous script you provided to add the vCenter name to the output file. Since we could be running this against over a dozen vCenters, keeping it clear as to which it's run against is not a minor thing.

Reply
0 Kudos