Hello
Tried that approach before and got a ton of errors, tried now and managed to get past all the issues. Thank you very much for pointing out the correct path.
The CPUusage table must be created before the script can work. Strangely, it does append the data in the table.
Updated script:
$Hosts = @(
"xx.xx.xx.1",
"xx.xx.xx.2",
"xx.xx.xx.3")
$Counter = 10
$Path = get-location
foreach ($Server in $Hosts){
Start-Job -ScriptBlock { param ($Server, $Counter) Add-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue set-location $Path . .\out-datatable.ps1 . .\write-datatable.ps1 Connect-VIServer -Server $Server -user xxx -password "xxx" | Out-Null $vms = Get-Vm | where {$_.PowerState -eq "PoweredOn"} $Check = @() $Check = $Check + $Server + $vms for ($i=0; $i -lt $counter; $i++){ $startdate = Get-date $alldata = @() $stats = Get-Stat -Entity $Check -Realtime -Stat cpu.usage.average -MaxSamples 1 $stats | Group-Object -Property Entity | %{ $stat = "" | Select Date, HostName, VMName, CPUAvg $stat.Date = Get-date $stat.VmName = $_.name $stat.HostName = $Server if ($stat.VmName -eq $Server) {$stat.VmName = $null} $cpu = $_.Group | Measure-Object -Property value -Average $stat.CPUAvg = [int]$cpu.Average $alldata += $stat } $dt = $alldata | Out-DataTable Write-DataTable -ServerInstance "(local)" -Database "CPUStats" -TableName "CPUusage" -Data $dt $enddate = Get-date $delay = $startdate.AddSeconds(30) - $enddate Start-Sleep -s $delay.seconds Clear-Variable -Name alldata } Disconnect-VIServer * -Force -Confirm:$false } -Name $Server -ArgumentList ($Server, $Counter, $Path)
}
It seems to be quite CPU heavy, so I will probably need a different solution, going to try the Get-esxtop approach next. Thank you for all the help.
Regards
Genoan