Dear Team,
I want PCLI script which will capture current CPU , Memory DISk and Network utilization for all Production VMs.
with the help of custom attributes(Annotations) I have defined different category such as production / staging / UAT / Exclude . PFA below snap
my pruprose is I will run this script on daily basis to capture production VMs utilization.
need ur help to achieve this.
regards
Mr VMware
The statistics report would in fact be the same as the one I gave in your other thread, but the selection of the VMs would be different.
Something like this
$vm = Get-VM |
where {(Get-Annotation -Entity $_ -Name Project | Select -ExpandProperty Value) -eq "Exclude"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I showed in Re: How to capture CPU, Mem , Disk , Network performance
how to group the results in 3 hour intervals.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear LUCD.
I have ran the below script but it also capture other VMs details as we want only EXCLUDE VMs details.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
$start = (Get-Date).AddDays(-1)
$stat = "cpu.usage.average","mem.usage.average","disk.usage.average","net.usage.average"
$vms = Get-VM
where {(Get-Annotation -Entity $_ -Name Project | Select -ExpandProperty Value) -eq "Exclude"}
&{Get-Stat -Entity $vms -Start $start -Stat $stat |
Group-Object -Property EntityId,{[math]::Floor($_.Timestamp.Hour/3)} | %{
New-Object PSObject -Property @{
Time = $_.Group[0].Timestamp
VM = $_.Group[0].Entity.Name
CPU = $_.Group | where {$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} |
Measure-Object -Property Value -Average | Select -ExpandProperty Average
Mem = $_.Group | where {$_.MetricId -eq "mem.usage.average" -and $_.Instance -eq ""} |
Measure-Object -Property Value -Average | Select -ExpandProperty Average
Disk = $_.Group | where {$_.MetricId -eq "disk.usage.average" -and $_.Instance -eq ""} |
Measure-Object -Property Value -Average | Select -ExpandProperty Average
Net = $_.Group | where {$_.MetricId -eq "net.usage.average" -and $_.Instance -eq ""} |
Measure-Object -Property Value -Average | Select -ExpandProperty Average
}
}} | Select Time,VM,CPU,Mem,Disk,Net | Export-Csv vm-report.csv -NoTypeInformation -UseCulture
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
What wrong I m doing here ??? plz help
You seem to have forgotten the pipe symbol (|) at the end of the 1st line
$vms = Get-VM |
where {(Get-Annotation -Entity $_ -Name Project | Select -ExpandProperty Value) -eq "Exclude"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
after adding the pipe scripts works it throws below error.
need ur assistance to resolve
It looks as if the annotation "Project" is not available on all VMs.
Is that the case ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Project Annotation is visible on all VMs....
Can you check with the following
foreach($vm in Get-VM){
Try{
Get-Annotation -Entity $vm -Name 'Project' -ErrorAction Stop
}
Catch{
Write-Warning "No Project annotation on $($vm.Name)"
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference