eeg3
Commander
Commander

Replacing VMHostID with Host's Name

Jump to solution

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:

VMHostIdNameVirtualSwitchVirtualSwitchNameVLanId
HostSystem-host-97975Service ConsolevSwitch0vSwitch00

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?

Blog: http://blog.eeg3.net
Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership

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

View solution in original post

0 Kudos
eeg3
Commander
Commander

That works perfectly; thanks, sir!

Blog: http://blog.eeg3.net
0 Kudos
FrancoNero1
Contributor
Contributor

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