• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1213
  • Last Modified:

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

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
Thaidog
Asked:
Thaidog
  • 5
  • 5
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
can u try with -contains instead of -eq
0
 
ThaidogAuthor Commented:
Did not seem to work:

PS C:\Users> get-vm | Get-NetworkAdapter | Where-Object {$_.ConnectionState -contains "NotConnected"}
PS C:\Users>
0
 
Meir RivkinFull stack Software EngineerCommented:
if you run this line:
get-vm | Get-NetworkAdapter | fl

Open in new window


do you get the test vm?
0
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
ThaidogAuthor Commented:
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
 
Meir RivkinFull stack Software EngineerCommented:
thats not what i was asking, if you run
get-vm | Get-NetworkAdapter | fl

Open in new window

do u get it?
0
 
ThaidogAuthor Commented:
I've got 1800 VMs on this vcenter... not going to have time to run that ;)
0
 
ThaidogAuthor Commented:
This works:

 get-vm | Get-NetworkAdapter | Where-Object {$_.ConnectionState -match "NotConnected"}
0
 
Meir RivkinFull stack Software EngineerCommented:
how is that working and -contains does not???
as long as you got it working
0
 
ThaidogAuthor Commented:
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
 
Meir RivkinFull stack Software EngineerCommented:
it seems it returns MacAddress, what do u mean?
0
 
coraxalCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now