PowerCLI

 View Only
  • 1.  Get VMs with net adapter not connected

    Posted Oct 28, 2020 08:34 PM

    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?



  • 2.  RE: Get VMs with net adapter not connected
    Best Answer

    Posted Oct 28, 2020 08:49 PM

    Try something like this

    Get-VM |

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

    Select Name



  • 3.  RE: Get VMs with net adapter not connected

    Posted Oct 29, 2020 04:27 PM

    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



  • 4.  RE: Get VMs with net adapter not connected

    Posted Oct 29, 2020 04:34 PM

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



  • 5.  RE: Get VMs with net adapter not connected

    Posted Oct 29, 2020 05:09 PM

    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



  • 6.  RE: Get VMs with net adapter not connected

    Posted Oct 30, 2020 03:25 PM

    Thanks man! :smileyhappy: