VMware Cloud Community
VJ_VMware_111
Enthusiast
Enthusiast
Jump to solution

PowerCLI Help

Hey Guys,

I am trying to get OS, CPU, RAM, Disk information of a set of VMs from a text file. But the below script does not give OS. Can you please check it, and tell what can be wrong?

Connect-VIServer vcenter

Get-VM -Name (Get-Content "C:\VMs.txt") |

Select Name, @{N="OS";E={Get-View $_.config.guestFullName}}, @{N="CPU";E={$_.numCPU}}, @{N="RAM";E={$_.memoryMB}}, @{N="HardDiskSizeGB";E={(Get-HardDisk -VM $_. | Measure-Object -Sum CapacityGB).Sum}}

Thanks,

VJ

1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can get the OS with the following PowerCLI script:

Connect-VIServer vcenter

Get-VM -Name (Get-Content "C:\VMs.txt") |

Select Name, @{N="OS";E={$_.Guest.OSFullName}}, @{N="CPU";E={$_.numCPU}}, @{N="RAM";E={$_.memoryMB}}, @{N="HardDiskSizeGB";E={(Get-HardDisk -VM $_. | Measure-Object -Sum CapacityGB).Sum}}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
4 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can get the OS with the following PowerCLI script:

Connect-VIServer vcenter

Get-VM -Name (Get-Content "C:\VMs.txt") |

Select Name, @{N="OS";E={$_.Guest.OSFullName}}, @{N="CPU";E={$_.numCPU}}, @{N="RAM";E={$_.memoryMB}}, @{N="HardDiskSizeGB";E={(Get-HardDisk -VM $_. | Measure-Object -Sum CapacityGB).Sum}}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
VJ_VMware_111
Enthusiast
Enthusiast
Jump to solution

Thanks it works. I am not sure why '$_.config.guestFullName' does not yield the OS though. I tried with and without Get-View, as shown below. It works in my other script (without get-view), but not in this one.

@{N="OS";E={$_.config.guestFullName}}

@{N="OS";E={Get-View $_.config.guestFullName}}

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You could also use:

@{N="OS";E={$_.ExtensionData.config.guestFullName}}

or:

@{N="OS";E={(Get-View $_).config.guestFullName}}

In your other script, the value in $_ is probably of type VMware.Vim.VirtualMachine instead of VirtualMachineImpl or UniversalVirtualMachineImpl.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
VJ_VMware_111
Enthusiast
Enthusiast
Jump to solution

Okay. thanks a lot.

Reply
0 Kudos