VMware Cloud Community
jvlach
Enthusiast
Enthusiast

Script to collect from all VM adapters - portgroup (network), VLAN ID, subnet mask, gateway address

This info is not all in one place, which adds to the complexity. I need to gather from all VM's info on all adapters portgroup and I need the VLAN ID, the gateway address, and the subnet mask. The reason for this is we want to gather portgroup info about both VLAN and network (subnet and gateway).

31 Replies
AlbertWT
Virtuoso
Virtuoso

LucD​,

I got this error: WARNING: The NetworkName property of the NicInfo type is deprecated and will be removed in a future release. Use.Device.NetworkName instead.

Portgroup, VLANId, VLAN Type and SwitchType column is also not populating.

is it due to the older version of the command:

Get-PowerCLIVersion

PowerCLI Version

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

   VMware PowerCLI 11.0.0 build 10380590

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

Component Versions

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

   VMware Cis Core PowerCLI Component PowerCLI Component 11.0 build 10335701

   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.0 build 10336080

PowerCLI Version

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

   VMware PowerCLI 11.0.0 build 10380590

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

Component Versions

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

   VMware Cis Core PowerCLI Component PowerCLI Component 11.0 build 10335701

   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.0 build 10336080

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership

No, this is just a warning (which you can suppress with the DisplayDepreciationWarnings switch on the Set-PowerCLIConfiguration cmdlet).

Or use the newer setup.
Replace every occurrence (2) of

$vnic.NetworkName

with

$vnic.Device.NetworkName

I'm not sure why you are not getting the other properties.

Are you using VSS or VDS in the environment?


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

AlbertWT
Virtuoso
Virtuoso

LucD​,
I'm using vDS for production network and normal vSS for the vCenter.

The error after replacing "$vnic.Device.NetworkName"

Get-VirtualPortGroup : 6/08/2020 10:09:08 AM Get-VirtualPortGroup VirtualPortGroup with name 'dvportgroup-8876' was not found using the specified filter(s).

At line:7 char:23

+ ...       $pg = Get-VirtualPortGroup -Name $vnic.Device.NetworkName -VM $ ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (:) [Get-VirtualPortGroup], VimException

    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVirtualPortGroup

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership

Looks like that specific VM might have aNIC connection to a portgroup that doesn't exist anymore.

Can you check?


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

Reply
0 Kudos
Mel13
Contributor
Contributor

Hi LucD

I am tryign to run your script but have no luck in pulling Portgroup.

I tried as below

$vm = Get-VM -Name "vicar-scaa-auth-02"

$vnic = $vm.Guest.Nics

$vnic

Device               NetworkName          Connected  IPAddress          

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

Network adapter 4    dvportgroup-686      True       {fe80::250:56ff:f...

C:\> $vnic.NetworkName

dvportgroup-686

dvportgroup-686

dvportgroup-45

dvportgroup-676

So above i can see the the agrumnet "$vnic.NetworkName" is pulling the portgroup details

But when i ran this query ..I am gettign the error with parameter "Name"

Get-VirtualPortGroup -Name $vnic.NetworkName -VM $vm

Get-VirtualPortGroup : Cannot validate argument on parameter 'Name'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a

collection that does not contain any null values and then try the command again.

At line:16 char:28

+ Get-VirtualPortGroup -Name $vnic.NetworkName -VM $vm

+                            ~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-VirtualPortGroup], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVirtualPortGroup

Reply
0 Kudos
LucD
Leadership
Leadership

What does $vm.Guest.Nics.Count return?


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

Reply
0 Kudos
Mel13
Contributor
Contributor

Hi LuCD

Thanks for address my request. The count is 6

PS\> $vm.Guest.Nics.Count

6

Reply
0 Kudos
LucD
Leadership
Leadership

There are obviously some ghost NIC inside the Guest OS.

Looks like the VM has at least 4 vNICs, inside the Guest OS only one is apparently visible.

Some entries in $vm.Guest.Nics have an empty ($null) entry for NetworkName, which explains the error.

Not sure how the script can fix this, except for testing for $null and skipping those entries.

You should probably clean up your NICs inside the Guest OS.


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

Reply
0 Kudos
Mel13
Contributor
Contributor

Thank you very much for your help.

I tried on one more VM , which hs only 1 count but still throwing error.

PS C:\> $vm.Guest.Nics.Count

1

PS C:\> $vnic.NetworkName

dvportgroup-45

PS C:\> $vm

Name                 PowerState Num CPUs MemoryGB      

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

vvarctap-v02      PoweredOn  4        12.000        

Get-VirtualPortGroup -Name $vnic.NetworkName -VM $vm

Get-VirtualPortGroup : 11/08/2020 9:04:44 PM Get-VirtualPortGroup VirtualPortGroup with name 'dvportgroup-45' was not found using the specified filter(s).

At line:17 char:1

+ Get-VirtualPortGroup -Name $vnic.NetworkName -VM $vm

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (:) [Get-VirtualPortGroup], VimException

    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVirtualPortGroup

Reply
0 Kudos
LucD
Leadership
Leadership

That is not the same error.

And you are not running the script, but individual lines.


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

Reply
0 Kudos
Mel13
Contributor
Contributor

Hi LucD

Since the script didn't pullable to pull port group details, I am trying to find why it cant.  So these tests are individual lines not via your script to narrow down my issue.

Reply
0 Kudos
Mel13
Contributor
Contributor

Hi LucD

Yes , I running this as individual lines to narrow down the issue of no capturing portgroup details via your script.

Reply
0 Kudos