I am looking for a way to get a resource report for a set of VMs. Things like CPUs assigned, RAM assigned, HDD assigned, & HDD used, but I want to be able to point it at a VM folder so it will dynamically grow as the group does. Looking for any ideas on how to do this.
Thanks,
Andy
How about something like this.. Also if you want to run this as a schedule you might consider encrypting the credentials like this
Get-Credential –Credential “administrator@vsphere.local” | Export-Clixml C:\Scripts\mycreds.xml
$vc = 'vca.vsphere.local'
$folder = 'VM_folder'
$reportpath = 'c:\vm_report\vms.csv'
$Cred = Get-Credential
#$Cred = Import-Clixml C:\Scripts\mycreds.xml
Connect-VIServer $VC -Credential $Cred
$vms = Get-Folder $folder | Get-VM
$vms | Select-Object @{e={$_.name};L="VM Name"},
@{e={$_.NumCpu};L="Number of vCPU's"},
@{e={$_.MemoryGB};L="Allocated Memory GB"},
@{n="Total Disk Size GB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},
@{n="Total Disk Space Used GB"; e={[math]::round( $_.UsedSpaceGB )}}|
Export-Csv -Path $reportpath -NoTypeInformation
Disconnect-VIServer $vc -Force -Confirm:$false
Remove-Variable * -Force -ErrorAction SilentlyContinue
As a concept, the core of that script could look something like this.
And yes, it doesn't provide the metrics you mentioned, but just to verify this is what you want.
You would also need to know over which time interval you want the script to collect these statistics.
And does the script need to average the statistical data, or produce a line per time at which statistics are available?
$folderName = 'MyFolder'
$entity = Get-Folder -Name $folderName | Get-VM
Get-Stat -Entity $entity -Realtime -MaxSamples 1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Well I am not looking for an over time report, just a report showing how much resources are being allocated at a point in time. Again just CPU, RAM, and HDD allocations and then how much HDD is being used at that point in time. We really would only run this quarterly I believe and be kicked off manually.
Luc probably has a better way but something like this perhaps.
$folder = 'MyFolderName'
$vms = Get-Folder $folder | Get-VM
$vms | Select-Object Name,MemoryGB,NumCpu,
@{n="TotalHDSizeGB"; e={(Get-HardDisk -VM $_ |Measure-Object -Sum CapacityGB).Sum}},
@{ n="SpaceUsedGB"; e={[math]::round( $_.UsedSpaceGB )}}
Looking good, can you output this to a CSV so we can add them together quickly and tell the dept to pay up :smileysilly:
How about something like this.. Also if you want to run this as a schedule you might consider encrypting the credentials like this
Get-Credential –Credential “administrator@vsphere.local” | Export-Clixml C:\Scripts\mycreds.xml
$vc = 'vca.vsphere.local'
$folder = 'VM_folder'
$reportpath = 'c:\vm_report\vms.csv'
$Cred = Get-Credential
#$Cred = Import-Clixml C:\Scripts\mycreds.xml
Connect-VIServer $VC -Credential $Cred
$vms = Get-Folder $folder | Get-VM
$vms | Select-Object @{e={$_.name};L="VM Name"},
@{e={$_.NumCpu};L="Number of vCPU's"},
@{e={$_.MemoryGB};L="Allocated Memory GB"},
@{n="Total Disk Size GB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},
@{n="Total Disk Space Used GB"; e={[math]::round( $_.UsedSpaceGB )}}|
Export-Csv -Path $reportpath -NoTypeInformation
Disconnect-VIServer $vc -Force -Confirm:$false
Remove-Variable * -Force -ErrorAction SilentlyContinue
@nicholas1982 Thank you so much for explaining how to properly hide my creds that is another project I was working on. And the script is nearly perfect!
Thank you for the help!