salasos3
Enthusiast
Enthusiast

Get VMs with net adapter not connected

Jump to solution

Hi all,

I'm trying to get all the VMs that are "connected" state(to exclude maintenance mode ones) and the "Connect at power on" network adapter setting disabled.

This is what I have but seems to be not working properly Im not getting any result even when I know there are VMs with this setting disabled:

Get-VM | Get-NetworkAdapter | Where-object {($_.ConnectionState.Connected ) -and ($_.ConnectionState.StartConnected -ne "True")}

Any idea?

Tags (2)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this

Get-VM |

Where{ Get-NetworkAdapter -VM $_ | Where-object {($_.ConnectionState.Connected ) -and (-not $_.ConnectionState.StartConnected)}} |

Select Name


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

5 Replies
LucD
Leadership
Leadership

Try something like this

Get-VM |

Where{ Get-NetworkAdapter -VM $_ | Where-object {($_.ConnectionState.Connected ) -and (-not $_.ConnectionState.StartConnected)}} |

Select Name


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

salasos3
Enthusiast
Enthusiast

That worked fine LucD thanks.

Googling I found another script that I have modified a little bit to get the vcenter name as well:

Get-VM |sort name| Get-NetworkAdapter | Where-object {$_.ConnectionState.StartConnected -ne "True"} |

foreach ($_) {Write-Host $_.Uid.Split('@')[1].Split(':')[0] $_.Parent.Name "("$_.Name") type:" $_.Type "Startconnected:" $_.ConnectionState.StartConnected} |

Export-Csv –append –path H:\Desktop\NetAdapterStartUp.csv -NoTypeInformation -UseCulture

I'm trying to export the output to a CSV file but seems to be not working, I just get an empty .csv

0 Kudos
LucD
Leadership
Leadership

The Foreach statement doesn't place anything on the pipeline.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership

You could do

Get-VM |Sort-Object -Property name|

Get-NetworkAdapter | Where-object {-not $_.ConnectionState.StartConnected} |

Select @{N='vCenter';E={([uri]$_.Parent.ExtensionData.Client.ServiceUrl).Host}},

    @{N='VM';E={$_.Parent.Name}},Name,Type,

    @{N='StartConnected';E={$_.ConnectionState.StartConnected}} |

Export-Csv –append –path H:\Desktop\NetAdapterStartUp.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

salasos3
Enthusiast
Enthusiast

Thanks man! Smiley Happy

0 Kudos