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
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}}
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}}
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}}
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.
Okay. thanks a lot.