Hello,
Please i need your support as i'm trying to genertae a performance report for alot of servers on a monthly basis, i need something to generate this report as a bulk report.
we're using powershell 5
Thank you
And would you like fries or rice with that order?
Seriously, this is not a free "write a script for me" community, but a place where community members try to provide answers to questions or specific issues other users might encounter.
At least you could provide some more details on what you are trying to achieve.
And even better, come with a concrete question, showing what you already have and where you got stuck.
Did you even do a search in this community before posting this?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I was definitely not trying to make fun of you, just of the type of question.
We sometimes get some very 'general' questions in here, not specifying any details, which are in fact nothing more than a "do my work for me" kind of request.
Now with your last reply, you asked a practical question.
That is something we can try to help you with.
Some things to check/answer:
$start = (Get-Date).AddDays(-30)
$folders = Get-Folder -Location (Get-Folder -Name vm -Location Datacenters)
# $folders = Get-Folder -Name Folder1,Folder2,Folder3
& { foreach ($folder in $folders)
{
$vms = Get-VM -Location $folder
if ($vms)
{
$stats = Get-Stat -Entity $vms -Stat $metrics -Start $start -ErrorAction SilentlyContinue
if ($stats)
{
$stats | Group-Object -Property { $_.Entity.Name } | % {
New-Object PSObject -Property @{
Folder = $folder.Name
VM = $_.Values[0]
CpuAvg = ($_.Group | where { $_.MetricId -eq "cpu.usage.average" } | Measure-Object -Property Value -Average).Average
MemAvg = ($_.Group | where { $_.MetricId -eq "mem.usage.average" } | Measure-Object -Property Value -Average).Average
DiskAvg = ($_.Group | where { $_.MetricId -eq "disk.usage.average" } | Measure-Object -Property Value -Average).Average
}
}
}
}
} } | Export-Csv C:\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Looks like you have a space between $ and metrics.
The names of variables should not contain spaces.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello,
Thank you for your quick feedback, Ok ill try again and update you with the result.
Thank you
Hello,
it generated an empty CSV file as before.
Thanks
Ok, lets first check if there any VMs in that folder
Does this return anything?
Get-VM -Location (Get-Folder -Name vm -Location Datacenters)
Then we can check if there is statistical data for that period and those VMs.
$start = (Get-Date).AddDays(-30)
Get-VM -Location (Get-Folder -Name vm -Location Datacenters) |
ForEach-Object -Process {
Get-Stat -Entity $_ -Stat $metrics -Start $start
}
Does this return anything?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello,
Apologize for the delay,
We ran the script, please check the below Outputs,
1st script generated output details for the below:
Name PowerState Num CPUs MemoryGB
2nd script returned the below Error (same error for each server):
+ CategoryInfo : ResourceUnavailable: ( cpu.usage.average :String) [Get-Stat], VimException
+ FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation.
ViCore.Cmdlets.Commands.GetViStats
Thank you
Ok, so the VM can be found.
The 2nd script seems to indicate that this specific metric isn't captured for the VM over that period.
Can you check if any of the other metrics is captured with the following?
$start = (Get-Date).AddDays(-30)
Get-VM -Location (Get-Folder -Name vm -Location Datacenters) |
ForEach-Object -Process {
Get-Stat -Entity $_ -Stat $metrics -Start $start -ErrorAction SilentlyContinue
}
The problem could be related to the Statistics Levels you defined on your vCenter.
Another way to check is to look at the Performance tab for VM and check if there is data available for that period for that specific metric.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes when we check like manually per server we get the data, will run the latest script you send and will update you with the result.
Thank you
Hello,
The last script generated a file with CPU, Desk & Memory Usage but not specified to which server.
Is there something disabled from our side?
If not, is there any other way to generate that Bulk Monthly report?
Thank you
That last script was to verify that the data for those 3 metrics is available over that time period (30 days).
Did you get data for the full period?
Did you get data for all metrics?
Did you get data for all VMs?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you get data for the full period?
Yes
Did you get data for all metrics?
I got average usage only for CPU, Desk & Memory --- is there a report to have "System performance, utilization, and capacity"
Did you get data for all VMs?
No, the server part is not available in the output
Ok, can you now try with the following?
$start = (Get-Date).AddDays(-30)
$vms = Get-Folder -Name vm -Location Datacenters | Get-VM
Get-Stat -Entity $vms -Stat $metrics -Start $start -ErrorAction SilentlyContinue |
Group-Object -Property { $_.Entity.Name } |
ForEach-Object -Process {
New-Object PSObject -Property ([ordered]@{
Folder = $_.Group[0].Entity.Folder.Name
VM = $_.Name
CpuAvg = ($_.Group | where { $_.MetricId -eq "cpu.usage.average" } | Measure-Object -Property Value -Average).Average
MemAvg = ($_.Group | where { $_.MetricId -eq "mem.usage.average" } | Measure-Object -Property Value -Average).Average
DiskAvg = ($_.Group | where { $_.MetricId -eq "disk.usage.average" } | Measure-Object -Property Value -Average).Average
})
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference