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?
Try something like this
Where{ Get-NetworkAdapter -VM $_ | Where-object {($_.ConnectionState.Connected ) -and (-not $_.ConnectionState.StartConnected)}} |
Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Where{ Get-NetworkAdapter -VM $_ | Where-object {($_.ConnectionState.Connected ) -and (-not $_.ConnectionState.StartConnected)}} |
Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
The Foreach statement doesn't place anything on the pipeline.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do
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
Thanks man!