VMware Cloud Community
sjesse
Leadership
Leadership

some vms not showing with networks

   I'm using this script

$vms=Get-VM

$vmList=@()

foreach($vm in $vms)

{

   

    $networks= $vm | Get-VirtualPortGroup

    $hasNasInterface=$false;

    foreach($network in $networks)

    {

        if($network.Name -eq "VLAN 298 - NAS" -or $network.Name -eq "VLAN 298 - NAS")

        {

 

            $hasNasInterface=$true;

            $break;    

        }

    }

    if(!$hasNasInterface)

    {

       

        $networks= $vm | Get-VirtualPortGroup

      

        if($networks.Length -lt 1)

        {

            Write-Host $vm.Name

        }

        $vmList+=$vm

    }

   

}

$vmList |Export-csv C:\users\sjesse\desktop\no_nas_int.csv

I'm trying to find out what vms that aren't on our 298 network, and about 5-10 are showing with no networks, but in the interface they are. Is there something I'm missing

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

When you for example renamed or recreated portgroups, the VM might still be showing the old portgroup name and a portnumber.

But on the portgroup itself you will not find the VM as connected.

Could that explain the ones that you see?


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

Reply
0 Kudos
sjesse
Leadership
Leadership

I think I figured it out. Most of these are protected by SRM, so I'm getting results for the SRM placeholder vms which aren't connected to the networks yet, the rest actually don't have networks assigned to them. I'm pretty sure I can update this to filter out the SRM protected ones..

Reply
0 Kudos
LucD
Leadership
Leadership

Don't they have Tags you could use for the filtering?


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

Reply
0 Kudos
sjesse
Leadership
Leadership

Not a tag exactly, they are specially managed by vcenter, I just found this. It brings back any vm that isn't managed by SRM.

Get-VM | Where-Object {$_.ExtensionData.Config.ManagedBy.ExtensionKey -ne 'com.vmware.vcDr'}

Reply
0 Kudos