Solved

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

Posted on 2013-01-15
11
1,095 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Teach the user how to install and configure the vCenter Orchestrator virtual appliance Open vSphere Web Client: Deploy vCenter Orchestrator virtual appliance OVA file: Verify vCenter Orchestrator virtual appliance boots successfully: Connect to the …
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…

730 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