VMware Cloud Community
pamiller21
Enthusiast
Enthusiast

Report to show invaild network backings

Hey all,

I am looking to make a script to output a report that shows if any VMs have invalid network backings or just blank network labels.  We have had some issues in the past where VMs have trouble and come back online and either have invalid or nothing in the network field and we don't find them fast enough.  If I had a report this might save the day.

Thanks all!

0 Kudos
13 Replies
LucD
Leadership
Leadership

How would you determine an invalid networkname ?

Just by looking at the list of all available portgroups ?

If yes, you might do something like this

$pgs = Get-VirtualPortGroup | Select -ExpandProperty Name

Get-VM | where{$pgVM = Get-NetworkAdapter -VM $_ | Select -ExpandProperty NetworkName;

               $pgs -notcontains $pgVM -or $pgVM -eq $null -or $pgVM -eq ''} |

Select Name


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

pamiller21
Enthusiast
Enthusiast

I would determine if it is invalid if it shows a greyed out network label and says invalid.  The script you have there just outputted all my VMs names, not even their portgroups.  Not sure where the mix up is, but thank you for giving me a shout!

0 Kudos
LucD
Leadership
Leadership

Can you try like this ?

Btw, do your VMs have more than 1 vNIC ?

$pgs = Get-VirtualPortGroup | Select -ExpandProperty Name

foreach($vm in Get-VM){

    $pgVM = Get-NetworkAdapter -VM $vm | select -ExpandProperty NetworkName

    if($pgs -notcontains $pgVM){

        Select @{N='VM';E={$vm.Name}},@{N='Portgroup';E={$pgVM}}

    }

}

You should also check what is in $pgs.

That should contain the names of all the Portgroups in your environment (to which you are connected).


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

0 Kudos
pamiller21
Enthusiast
Enthusiast

That outputs nothing...but that might be correct as there are no invalid backings now.

0 Kudos
LucD
Leadership
Leadership

And can you simulate an invalid backing ?

Just to test


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

0 Kudos
pamiller21
Enthusiast
Enthusiast

I did some hunting and found an example that is around

0 Kudos
LucD
Leadership
Leadership

Great, so what does the following return ?

Get-VirtualPortGroup -Name Corp_130


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

0 Kudos
pamiller21
Enthusiast
Enthusiast

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership

That would mean it's not in the $pgs array, and the VM with that portgroup should show up from the report.


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

0 Kudos
pamiller3
Contributor
Contributor

We are using D switches so that might be a reason.

0 Kudos
LucD
Leadership
Leadership

Is that portgroup returned by Get-VDPortgroup ?


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

0 Kudos
pamiller3
Contributor
Contributor

It does show with that command.

0 Kudos
LucD
Leadership
Leadership

Give this one a try

$pgs = @()

$pgs += Get-VirtualPortGroup | Select -ExpandProperty Name

$pgs += Get-VDPortgroup | select -ExpandProperty Name

Get-VM | Get-NetworkAdapter | where{$pgs -notcontains $_.NetworkName} |

Select @{N='VM';E={$_.Parent.Name}},NetworkName


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

0 Kudos