I'm running the following command:
Get-VMHost | Get-VirtualPortGroup | Select VMHostId,Name,VirtualSwitch,VirtualSwitchName,VLanId | Export-Csv "PathHere"
Which returns all of the information I want, except it puts the VMHostId instead of the actual host's name:
VMHostId | Name | VirtualSwitch | VirtualSwitchName | VLanId |
HostSystem-host-97975 | Service Console | vSwitch0 | vSwitch0 | 0 |
I don't see Parent or any other similar options under the Select from within the Get-VirtualPortGroup. What is the proper way to get the Host's actual name instead of the VMHostId?
The Tee-Object cmdlet is your friend in these cases :smileycool:
Get-VMHost | ForEach-Object -Process { Tee-Object -InputObject $_ -Variable Temp | Get-VirtualPortGroup | Select @{N="VMHost";E={$Temp.Name}},Name,VirtualSwitch,VirtualSwitchName,VLanId
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The Tee-Object cmdlet is your friend in these cases :smileycool:
Get-VMHost | ForEach-Object -Process { Tee-Object -InputObject $_ -Variable Temp | Get-VirtualPortGroup | Select @{N="VMHost";E={$Temp.Name}},Name,VirtualSwitch,VirtualSwitchName,VLanId
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That works perfectly; thanks, sir!
Hallo LucD,
thx also for your solution. It helps me a lot.
But for me it is not working 100% properly because in the first loop the E={$Temp.Name} stays empty.
In the 2nd loop the E={$Temp.Name} has the name of the first VM from Loop 1 and so on.
Maybee you have an Idea ?
I am using Powershell Version 2 on an Windows Server 2008 R2