4 Replies Latest reply on Aug 20, 2019 8:42 AM by golddiggie

    Gather dvSwitch inventory from target vCenter script?

    golddiggie Virtuoso

      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.

       

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

       

      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. Re: Gather dvSwitch inventory from target vCenter script?
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          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

          • 2. Re: Gather dvSwitch inventory from target vCenter script?
            golddiggie Virtuoso

            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.

            • 3. Re: Gather dvSwitch inventory from target vCenter script?
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              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

              1 person found this helpful
              • 4. Re: Gather dvSwitch inventory from target vCenter script?
                golddiggie Virtuoso

                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.