You are not aiming in the right direction.
First identify the best format for the report.
Only after that start to think on how to script it.
Spending time in the first step will reduce the work in the second step drastically.
Starting with “Get-HardDisk” to collect network information will never be a good idea.
A VM can have many disks, and be attached to many networks.
Do you really want to have duplicate information in your report?
Moreover it will not be easy to work with the network data from the report, it will be necessary to filter out duplicates.
Best approach is to generate two reports:
One focused only on the network.
One focused only on the disks.
(Or only one if using XML format and two “branches”, but this is a totally different topic)
The chapter “Data Normalization” in the book “Access 2013 Bible” is providing many concepts similar to the above that can be reused to identify the best format to use for any report created with PowerShell.
I will have similar needs in the future so I have created a script to do the “network only” report.
One line per network connection.
It is based on some concepts from the script pointed by LucD.
get-vm | foreach-object{
$VM = $_
$VM | get-virtualportgroup | foreach-object{
if ($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
$PortGroupType = "DistributedPortGroupImpl"
Switch ($_.extensiondata.config.defaultportconfig.vlan){
VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec {
$VLANType = 'PvlanSpec'
$VLAN = $_.PvlanID
}
VMware.Vim.VmwareDistributedVirtualSwitchTrunkVlanSpec {
$VLANType = 'TrunkVlanSpec'
$VLAN = "$($_.VLANID.Start) - $($_.VLANID.End)"
}
VMware.Vim.VmwareDistributedVirtualSwitchVlanIdSpec {
$VLANType = 'VlanIdSpec'
$VLAN = $_.VLANID
}
}
}
Else{
$PortGroupType = "VirtualPortGroupImpl"
$Vlan = $_.VlanId
$VLANType = "NA standard vSwitch"
}
$Output = New-Object -Type PSObject -Prop ([ordered]@{
'VM'= $VM
'NetworkName' = $_.Name
'$PortGroupType' = $PortGroupType
'Vlan' = $Vlan
'VLANType' = $VLANType
})
Return $Output
}
} | ogv
PvlanSpec is a private VLAN in a distribued vSwitch
TrunkVlanSpec... as the name suggest a trunk of many VLAN in a distribued vSwitch
VlanIdSpec...the most standard, one VLAN ID per distributed port group.