I'm looking to see if there is a good basic PowerCLI script, that I can use as a base to get started with reporting in vSphere using Power CLI. Here are the kinds of things it should do:
-Create a list of all virtual machines in the vSphere environment
-Give details about each virtual machine: how much ram, how many vCPU's, hard drive size, the folder it is in, LUN it is stored on, current number of snaphots, OS type / service pack level,
-Prepare the information in comma-delimted format in such a way that it looks nice and presentable when imported into Excel
Any suggestions or Is there a link to good basic script template I should start with?
Thanks!
With the Get-VM cmdlet you have access to most of these properties. The ones that are not in the object can be easily retrieved via other cmdlets.
Get-VM | select Name,MemoryMB,NumCpu, @{N="HDsizeKB";E={($_.Harddisks | Measure-Object -Property CapacityKB -Sum).Sum}},Folder, @{N="Datastore";E={($_ | Get-Datastore).Name}},@{N="#Snapshots";E={($_ | Get-Snapshot).Count}}, @{N="OS Name";E={$_.Guest.OSFullName}} | Export-Csv "C:\report.csv" -NoTypeInformation
The basic report is a cmdlet to retrieve the concerned objects (Get-VM in this case), a Select-Object cmdlet to extract the properties or to calculate the properties you want and the Export-Csv cmdlet to save it to a CSV file.
PS is that simple
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
With the Get-VM cmdlet you have access to most of these properties. The ones that are not in the object can be easily retrieved via other cmdlets.
Get-VM | select Name,MemoryMB,NumCpu, @{N="HDsizeKB";E={($_.Harddisks | Measure-Object -Property CapacityKB -Sum).Sum}},Folder, @{N="Datastore";E={($_ | Get-Datastore).Name}},@{N="#Snapshots";E={($_ | Get-Snapshot).Count}}, @{N="OS Name";E={$_.Guest.OSFullName}} | Export-Csv "C:\report.csv" -NoTypeInformation
The basic report is a cmdlet to retrieve the concerned objects (Get-VM in this case), a Select-Object cmdlet to extract the properties or to calculate the properties you want and the Export-Csv cmdlet to save it to a CSV file.
PS is that simple
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Works great - thanks!