$ConnectedExp = @{ Name = "Connected"; Expr = { ($_ | Get-NetworkAdapter).ConnectionState.Connected } } get-vm | select name, $ConnectedExp
Or, just to get the disconnected ones:
get-vm | select name, $ConnectedExp | where-object { !$_.Connected }
Added bonus:
Get-VirtualSwitch -vmhost Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
$ConnectedExp = @{ Name = "Connected"; Expr = { ($_ | Get-NetworkAdapter).ConnectionState.Connected } } get-vm | select name, $ConnectedExp
Or, just to get the disconnected ones:
get-vm | select name, $ConnectedExp | where-object { !$_.Connected }
Added bonus:
Get-VirtualSwitch -vmhost Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Yep is working fine. How are you going with your book?
Only problem with script below, it is showing me all VM(s) with two or more network cards but I can filter them by using (findstr False)
get-vm | select name, $ConnectedExp | where-object { !$_.Connected }
Thanks,
Hi,
I am getting this error message when i try to tun these scripts
C:\> get-vm | select name, $ConnectedExp | where-object { !$_
.Connected }
Select-Object : Null parameter. Expecting one of the following types: {System.S
tring, System.Management.Automation.ScriptBlock}.
At line:1 char:16
+ get-vm | select <<<< name, $ConnectedExp | where-object { !$_.Connected }
+ CategoryInfo : InvalidArgument: ( , NotSupport
edException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Co
mmands.SelectObjectCommand
C:\> get-vm | select name, $ConnectedExp | where-object { !$_
.Connected }
Select-Object : Null parameter. Expecting one of the following types: {System.S
tring, System.Management.Automation.ScriptBlock}.
At line:1 char:16
+ get-vm | select <<<< name, $ConnectedExp | where-object { !$_.Connected }
+ CategoryInfo : InvalidArgument: ( , NotSupport
edException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Co
mmands.SelectObjectCommand
It looks as if you didn't execute the line
$ConnectedExp = @{ Name = "Connected"; Expr = { ($_ | Get-NetworkAdapter).ConnectionState.Connected } }
first. In that line you state how $ConnectedExp is obtained.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
Can you please tell how can I find out.. how can i find out the disconnected network adapters for VM's??.. the below script doesn't show me any thing.
Can you please tell me how can i find out which VM's are diconnected..
$ConnectedExp = @{ Name = "Connected"; Expr = { ($_ | Get-NetworkAdapter).ConnectionState.Connected } }
Thanks for your help
The two lines Hal gave are ok, but you have to execute them both.
First you store in the $ConnectedExp variable how the property is calculated.
Then you use it in the Select cmdlet.
$ConnectedExp = @{ Name = "Connected"; Expr = { ($_ | Get-NetworkAdapter).ConnectionState.Connected } } get-vm | select name, $ConnectedExp | where-object { !$_.Connected }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks work great.. appreciate your help always