Solved

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

Posted on 2013-01-15
11
1,118 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Teach the user how to edit .vmx files to add advanced configuration options Open vSphere Web Client: Edit Settings for a VM: Choose VM Options -> Advanced: Add Configuration Parameters:
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

691 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