Ok so I run RVTools and I know it pulls Guest OS from the vmx file (configuration file).
On one VM, it's running Redhat and the vCenter summary tab shows Redhat.
However, the vmx file reports SLES Linux 11. The vmx file has sles-11 via the RVTools report. How can I get a report of the current OS that vCenter is showing.
VM Name, Guest OS Running, datacenter, and cluster?
Sure, just add the properties to the Select-Object cmdlet.
Get-VM |
Select Name,NumCpu,MemoryMB,
@{N='OS';E={$_.Guest.OSFullName}},
@{N='Datacenter';E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}},
@{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}} |
Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
When you create a VM you can specify the OS, via the GuestId parameter on the New-VM cmdlet.
But you can install whatever OS you want in the VM.
Via the VMware Tools you can find the actual OS that was installed (the OSFullName property that is returned by the Get-VMGuest cmdlet).
So you could something like this
Get-VM |
Select Name,
@{N='OS';E={$_.Guest.OSFullName}},
@{N='Datacenter';E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}},
@{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great, one more thing. Can I also get the vmem and vcpu for each VM on this in a csv/excel file?
Sure, just add the properties to the Select-Object cmdlet.
Get-VM |
Select Name,NumCpu,MemoryMB,
@{N='OS';E={$_.Guest.OSFullName}},
@{N='Datacenter';E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}},
@{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}} |
Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is great LucD! Do you know what property I can add the VM folder in vCenter and ESXi host to this?
You can find all properties of the returned objects from Get-VM in the VirtualMachine object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried the script and it doesn't work.
Get-VM |
Select Name,NumCpu,MemoryMB,Folder,VMHost
@{N='OS';E={$_.Guest.OSFullName}},
@{N='Datacenter';E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}},
@{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}} |
Export-Csv report.csv -NoTypeInformation -UseCulture
When I run it from powercli, it outputs in the cmd box, name, cpu, memory, folder, host. However, when I open up the csv file, I get this:
IsReadOnly | IsFixedSize | IsSynchronized | Keys | Values | SyncRoot | Count |
FALSE | FALSE | FALSE | System.Collections.Hashtable+KeyCollection | System.Collections.Hashtable+ValueCollection | System.Object | 2 |
FALSE | FALSE | FALSE | System.Collections.Hashtable+KeyCollection | System.Collections.Hashtable+ValueCollection | System.Object | 2 |
FALSE | FALSE | FALSE | System.Collections.Hashtable+KeyCollection | System.Collections.Hashtable+ValueCollection | System.Object | 2 |
I suspect you might have forgotten a comma after VMHost
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OMG, thanks. You are a life saver.