Hello,
I'm trying to get Network-Adapter status with OS details with the below script.
everything is collected except the OS Full Name and OS family not sure where's the issue
Get-VM |
Sort-Object -Property Name -PipelineVariable vm |
ForEach-Object -Process {
Get-NetworkAdapter -VM $vm |
Where-Object { $_.ConnectionState.StartConnected -ne $true} |
Select-Object @{N = "VM Name"; E = {$vm.Name }},
@{N = "Power State"; E = { $vm.PowerState } },
@{N = "Interface"; E = {$_.Name }},
@{N = 'ConnectionState'; E={if($_.ConnectionState.Connected){'Connected'}else{'NotConnected'}}},
@{N = "Type"; E = {$_.Type }},
@{N = "Connect on Boot"; E = {$_.ConnectionState.StartConnected}},
@{N = "OS Full Name"; E = {$_.ExtensionData.Guest.guestFullName}},
@{N= "OS Family"; E = {{$_.ExtensionData.Guest.guestFamily}}
}
} | Export-Csv -Path .\NetAdapterStartUp.csv -NoTypeInformation -UseCulture
Get-VM |
Sort-Object -Property Name -PipelineVariable vm |
ForEach-Object -Process {
Get-NetworkAdapter -VM $vm |
Where-Object { $_.ConnectionState.StartConnected -eq $true} |
Select-Object @{N = "VM Name"; E = {$vm.Name }},
@{N = "Power State"; E = { $vm.PowerState } },
@{N = "Interface"; E = {$_.Name }},
@{N = 'ConnectionState'; E={if($_.ConnectionState.Connected){'Connected'}else{'NotConnected'}}},
@{N = "Type"; E = {$_.Type }},
@{N = "Connect on Boot"; E = {$_.ConnectionState.StartConnected}},
#@{N = "OS Full Name"; E = {$_.ExtensionData.Guest.guestFullName}},
@{N="Operating System"; E={@($vm.guest.OSFullName)}},
#@{N= "OS Family"; E = {{$_.ExtensionData.Guest.guestFamily}}
@{N="OS Family"; E={@($vm.guest.guestFamily)}}
}| Export-CSV $outputFile -NoTypeInformation -Append
I tested the script in my environment, following are the exported result, I have thousands of VMs, just part of the result.
| VM Name | Power State | Interface | ConnectionState | Type | Connect on Boot | Operating System | OS Family |
| VM001 | PoweredOn | Network adapter 1 | Connected | e1000 | TRUE | Red Hat Enterprise Linux 5 (64-bit) | linuxGuest |
| VM002 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Red Hat Enterprise Linux 7 (64-bit) | linuxGuest |
| VM003 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Red Hat Enterprise Linux 6 (64-bit) | linuxGuest |
| VM004 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | CentOS 7 (64-bit) | linuxGuest |
| VM005 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
| VM006 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Red Hat Enterprise Linux 7 (64-bit) | linuxGuest |
| VM007 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
| VM008 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2016 or later (64-bit) | windowsGuest |
| VM009 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2016 or later (64-bit) | windowsGuest |
| VM010 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Red Hat Enterprise Linux 8 (64-bit) | linuxGuest |
| VM011 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
| VM012 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
| VM013 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2016 or later (64-bit) | windowsGuest |
| VM014 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2016 or later (64-bit) | windowsGuest |
| VM015 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
Get-VM |
Sort-Object -Property Name -PipelineVariable vm |
ForEach-Object -Process {
Get-NetworkAdapter -VM $vm |
Where-Object { $_.ConnectionState.StartConnected -eq $true} |
Select-Object @{N = "VM Name"; E = {$vm.Name }},
@{N = "Power State"; E = { $vm.PowerState } },
@{N = "Interface"; E = {$_.Name }},
@{N = 'ConnectionState'; E={if($_.ConnectionState.Connected){'Connected'}else{'NotConnected'}}},
@{N = "Type"; E = {$_.Type }},
@{N = "Connect on Boot"; E = {$_.ConnectionState.StartConnected}},
#@{N = "OS Full Name"; E = {$_.ExtensionData.Guest.guestFullName}},
@{N="Operating System"; E={@($vm.guest.OSFullName)}},
#@{N= "OS Family"; E = {{$_.ExtensionData.Guest.guestFamily}}
@{N="OS Family"; E={@($vm.guest.guestFamily)}}
}| Export-CSV $outputFile -NoTypeInformation -Append
thank you for your assistance, unfortunately the details aren't retrieved ![]()
I tested the script in my environment, following are the exported result, I have thousands of VMs, just part of the result.
| VM Name | Power State | Interface | ConnectionState | Type | Connect on Boot | Operating System | OS Family |
| VM001 | PoweredOn | Network adapter 1 | Connected | e1000 | TRUE | Red Hat Enterprise Linux 5 (64-bit) | linuxGuest |
| VM002 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Red Hat Enterprise Linux 7 (64-bit) | linuxGuest |
| VM003 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Red Hat Enterprise Linux 6 (64-bit) | linuxGuest |
| VM004 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | CentOS 7 (64-bit) | linuxGuest |
| VM005 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
| VM006 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Red Hat Enterprise Linux 7 (64-bit) | linuxGuest |
| VM007 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
| VM008 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2016 or later (64-bit) | windowsGuest |
| VM009 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2016 or later (64-bit) | windowsGuest |
| VM010 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Red Hat Enterprise Linux 8 (64-bit) | linuxGuest |
| VM011 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
| VM012 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
| VM013 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2016 or later (64-bit) | windowsGuest |
| VM014 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2016 or later (64-bit) | windowsGuest |
| VM015 | PoweredOn | Network adapter 1 | Connected | Vmxnet3 | TRUE | Microsoft Windows Server 2012 (64-bit) | windowsGuest |
Tank you for your help it's working ![]()
Good to know it is working for you as well!![]()
