I'm trying to write a simple PS script to get the list of VM's on a Hyper-V host and for some reason Notes
are not always returned when -ExpandProperty NetworkAdapters
is used. See Screenshot:
Here are two different commands I'm using:
Get-VM | Select-Object -ExpandProperty NetworkAdapters | Select-Object VMName,Status, IPAddresses,ComputerName, Hostname, Notes | Format-Table -AutoSize
Get-VM | Select-Object VMName,IPAddresses,ComputerName, Hostname, Notes | Format-Table -AutoSize
I'm trying to get:
VMName
)Status
seems to work ok)IPAddresses
)ComputerName
and Hostname
aren't currently working, I'll figure this out later)Notes
doesn't always return a value)So any idea why Notes do not always return?
If you try and pipe Get-VM | Select-Object -ExpandProperty NetworkAdapters
to get-member it will not return the Notes Property. And thats why you can´t get it to display the notes.
You could instead make a pscustomobjet, maybe something like this.
$vms = Get-VM
ForEach ($vm in $vms) {
[PSCustomObject][ordered]@{
'VMName' = $vm.Name
'VM Status ' = $vm.Status
'IP addresse' = ($vm | Select-Object -ExpandProperty NetworkAdapters).ipaddresses
'Bytes Total/sec Ethernet' = $vm.computername
'Bytes Total/sec WiFi' = $vm.notes
}
}
/Anders