Solved

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

Posted on 2013-01-15
11
1,072 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
ID: 38778701
can u try with -contains instead of -eq
0
 

Author Comment

by:Thaidog
ID: 38778853
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
ID: 38778864
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
ID: 38779507
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
ID: 38779619
thats not what i was asking, if you run
get-vm | Get-NetworkAdapter | fl

Open in new window

do u get it?
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

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

Author Comment

by:Thaidog
ID: 38779796
This works:

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

Expert Comment

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

Author Comment

by:Thaidog
ID: 38779971
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
ID: 38781649
it seems it returns MacAddress, what do u mean?
0
 
LVL 5

Accepted Solution

by:
coraxal earned 500 total points
ID: 38824041
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Teach the user how to use vSphere Update Manager to update the VMware Tools and virtual machine hardware version Open vSphere Client: Review manual processes for updating VMware Tools and virtual hardware versions: Create a new baseline group in vSp…
This video shows you how to use a vSphere client to connect to your ESX host as the root user. Demonstrates the basic connection of bypassing certification set up. Demonstrates how to access the traditional view to begin managing your virtual mac…

920 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

15 Experts available now in Live!

Get 1:1 Help Now