BZDEX1979
Contributor
Contributor

Get-NetworkAdapter ConnectionState.StartConnected

Hello

 

I've created the below script unfortunately each time I run it it append the same VM that was previously configured with Network Adapter not started connected.

The idea is to get VMs with some details espacily the option if the VM has the NetAdapter is started connected or not and it's possible to add the NetworkAdapter type used?

 

Get-VM |Sort-Object -Property name|

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

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

@{N="VM Name";E={$_.Parent}},
@{N="NIC Name";E={$_.Name}},
@{N="NIC Type";E={$_.Type}},
@{N="Network Name";E={$_.NetworkName}},
@{N="Connection State";E={$_.ConnectionState}},
@{N="MAC Address";E={$_.MacAddress}},
@{N="WakeOnLan Enabled";E={$_.WakeOnLanEnabled}}|

Export-Csv –append –path .\NetAdapterStartUp.csv -NoTypeInformation -UseCulture
0 Kudos
7 Replies
LucD
Leadership
Leadership

I'm not sure what you actually want to do.
Perhaps a mockup of the desired output could help?


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

0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast

I'm trying to collect the below information for VMs

  • vCenter
  • VmName
  • PowerState
  • GuestId
  • NetWorkAdapter Name
  • Type
  • StartConnected

 

0 Kudos
LucD
Leadership
Leadership

Isn't that what the original code in this thread is doing?
Or am I missing something?

PS: I notice 2 different accounts, are you the same person?


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

0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast

Yep, I'm the same person and I think it's due to change that I made on my profile earlier, sorry about that😊

Regarding the script when I execute it not provide VMs that they have the network adapter set to false despite that I changed some VM to start without the network connected in order to be sure if I can get them in the csv or not

0 Kudos
LucD
Leadership
Leadership

When I run the following I get all the VMs that do not have the StartConnected set to true.

Get-VM |
Get-NetworkAdapter | Where-object {-not $_.ConnectionState.StartConnected} |
Select-Object @{N = 'vCenter'; E = { ([uri]$_.Parent.ExtensionData.Client.ServiceUrl).Host }},
@{N="VM Name";E={$_.Parent}},
@{N="NIC Name";E={$_.Name}},
@{N="NIC Type";E={$_.Type}},
@{N="Network Name";E={$_.NetworkName}},
@{N="Connection State";E={$_.ConnectionState}},
@{N="MAC Address";E={$_.MacAddress}},
@{N="WakeOnLan Enabled";E={$_.WakeOnLanEnabled}} |
Sort-Object -Property 'VM Name' |
Export-Csv -Path .\NetAdapterStartUp.csv -NoTypeInformation -UseCulture


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

0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast

On my side it's not working and it return a VM that I'm 100% sure that the option is set to true

 

0 Kudos
LucD
Leadership
Leadership

Is that VM powered on?
Did you restart that VM after you changed the setting?


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

0 Kudos