Solved

Need a powercli one liner to find VMs with nics not connected

Posted on 2013-01-15
11
1,066 Views
Last Modified: 2013-04-10
I am trying to make an easy way to see if we have any VMs that do not have their networking connection connected... I am trying this:

get-vm | Get-NetworkAdapter | Where-Object {$_.ConnectionState -eq "NotConnected"}
get-vm | Get-NetworkAdapter | Where-Object {$_.ConnectionState -eq "NotConnected, GuestControl, StartConnected"}

Open in new window


But it is not finding my test VM:

get-vm test777 | Get-NetworkAdapter | fl


MacAddress       : 00:xx.xx.xx.xx.xx
WakeOnLanEnabled : True
NetworkName      : 3112_dev_F5_IPR-10.48.xxx.xx
Type             : Vmxnet3
ParentId         : VirtualMachine-vm-74653
Parent           : TEST777
Uid              vm-74653/NetworkAdapter=4000/
ConnectionState  : NotConnected, GuestControl, StartConnected
ExtensionData    : VMware.Vim.VirtualVmxnet3
Id               : VirtualMachine-vm-74653/4000
Name             : Network adapter 1

Open in new window


Any ideas?
0
Comment
Question by:Thaidog
  • 5
  • 5
11 Comments
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
can u try with -contains instead of -eq
0
 

Author Comment

by:Thaidog
Comment Utility
Did not seem to work:

PS C:\Users> get-vm | Get-NetworkAdapter | Where-Object {$_.ConnectionState -contains "NotConnected"}
PS C:\Users>
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
if you run this line:
get-vm | Get-NetworkAdapter | fl

Open in new window


do you get the test vm?
0
 

Author Comment

by:Thaidog
Comment Utility
Yes

PS C:\Users> get-vm test777 | Get-NetworkAdapter | fl


MacAddress       : 00:xx.xx.xx.xx.xx
WakeOnLanEnabled : True
NetworkName      : 3112_dev_F5_IPR-10.48.xxx.xx
Type             : Vmxnet3
ParentId         : VirtualMachine-vm-74653
Parent           : TEST777
Uid              : /VirtualMachine=VirtualMachine-vm-74653/NetworkAdapter=4000/
ConnectionState  : NotConnected, GuestControl, StartConnected
ExtensionData    : VMware.Vim.VirtualVmxnet3
Id               : VirtualMachine-vm-74653/4000
Name             : Network adapter 1
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
thats not what i was asking, if you run
get-vm | Get-NetworkAdapter | fl

Open in new window

do u get it?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:Thaidog
Comment Utility
I've got 1800 VMs on this vcenter... not going to have time to run that ;)
0
 

Author Comment

by:Thaidog
Comment Utility
This works:

 get-vm | Get-NetworkAdapter | Where-Object {$_.ConnectionState -match "NotConnected"}
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
how is that working and -contains does not???
as long as you got it working
0
 

Author Comment

by:Thaidog
Comment Utility
not sure bu it is... would like to pipe the mac address output to an array... know how?

Get-VM | Get-NetworkAdapter | Where-Object {$_.ConnectionState -match "NotConnected"} | Select-Object -Property MacAddress
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
it seems it returns MacAddress, what do u mean?
0
 
LVL 5

Accepted Solution

by:
coraxal earned 500 total points
Comment Utility
I'm going to guess and say that you're trying to collect the MAC addresses in an array....if that's the case, you can do something like this:
$macaddresses = @()

Get-VM | % {$macaddresses += @(Get-NetworkAdapter $_.Name | ? {$_.ConnectionState -match "NotConnected"} | select macaddress)}

Open in new window

0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
Will try to explain how to use the VMware feature TAGs in the VMs and create Veeam Backup Jobs using TAGs. Since this article is too long, I will create second article for the Veeam tasks.
This Micro Tutorial walks you through using a remote console to access a server and install ESXi 5.1. This example is showing remote access and installation using a Dell server. The hypervisor is the very first component of your virtual infrastructu…
This video shows you how easy it is to boot from ISO images for virtual machines with the ISO images stored on a local datastore on the ESXi host.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now