|
| 1 | +<# |
| 2 | +14 February 2019 |
| 3 | +
|
| 4 | +Notes to self: |
| 5 | +1)if the group member is a cluster computer object it will thrown an error, I wasnt able to find |
| 6 | +2) there are servers whose objects cannot be populated. The handlying for these objects are not yet implemented as well. |
| 7 | +3) script runs around 4-5 minutes for 1500 servers, not sure if better error handling helps in decreasing script duration. |
| 8 | +
|
| 9 | +#> |
| 10 | + |
| 11 | +$ErrorActionPreference="SilentlyContinue" |
| 12 | +New-SCOMManagementGroupConnection -ComputerName $ms |
| 13 | +$GroupDisplayName="All Windows Computers" |
| 14 | +$CounterName='% Processor Time' |
| 15 | +$InstanceName='_Total' |
| 16 | +$Objectname='Processor Information' |
| 17 | +$UTCDiff=3 |
| 18 | +#Write-Output "Script Start at $(Get-date -f "HH:m:ss")" |
| 19 | +$Samples = @() |
| 20 | +$Servers=(Get-SCOMGroup -DisplayName $GroupDisplayName).GetRelatedMonitoringObjects() |
| 21 | +#$Exclude=(Get-SCOMClass -Name "Microsoft.Windows.Server.Computer" | Get-SCOMClassInstance | where {($_."[Microsoft.Windows.Server.Computer].IsVirtualNode").Value -eq $true}).DisplayName |
| 22 | +#$servers | ForEach-Object {$_.GetRelatedMonitoringObjects() | where FullName -match "LogicalDisk" | ft -Property Path,DisplayName} |
| 23 | +ForEach ($server in $Servers) { |
| 24 | +$Instances=$Server.GetRelatedMonitoringObjects() | where FullName -match "OperatingSystem" |
| 25 | +if(!$?) |
| 26 | +{ |
| 27 | +Write-Output "Error occured during enumarting instances: $($Server.DisplayName) on disk $($Instance.DisplayName). Error message:$($Error[0].Exception.Message)" | Out-File -FilePath "d:\temp\out.txt" -Append |
| 28 | +} |
| 29 | +foreach ($instance in $Instances) { |
| 30 | +$Data=($Instance.GetMonitoringPerformanceData() | ? {$_.Objectname -eq $Objectname -and $_.CounterName -eq $CounterName -and $_.Instancename -eq $InstanceName}).GetValues((Get-Date).AddHours(-8),(Get-Date)) |
| 31 | +if(!$?) |
| 32 | +{ |
| 33 | +Write-Output "Error occured during enumarting instances: $($Server.DisplayName) on disk $($Instance.DisplayName). Error message:$($Error[0].Exception.Message)" | Out-File -FilePath "d:\temp\out.txt" -Append |
| 34 | +} |
| 35 | +#$property=$LogicalDisk.GetMonitoringProperties() | where {$_.Name -match 'SizeInMB'} |
| 36 | + |
| 37 | + |
| 38 | +$Result=[PSCustomObject]@{ |
| 39 | +Server = $Server.DisplayName |
| 40 | +OS = $Instance.DisplayName |
| 41 | +SampleCount = $Data.Count |
| 42 | +Max = ($Data.SampleValue | Measure-Object -Maximum).Maximum |
| 43 | +Min = ($Data.SampleValue | Measure-Object -Minimum).Minimum |
| 44 | +Avg = ($Data.SampleValue | Measure-Object -Average).Average |
| 45 | +Last = ($Data | Select-Object -Last 1).SampleValue |
| 46 | +LastSampleTime = ($Data | Select-Object -Last 1).TimeSampled.AddHours($UTCDiff) |
| 47 | +LastHourAvg = (($Data | where {$_.TimeSampled.Hour -eq ($Data.TimeSampled | Select-Object -last 1).Hour}).SampleValue | Measure-Object -Average).Average |
| 48 | +Samples = ($Data | Select-Object -Property TimeSampled,SampleValue) |
| 49 | +} |
| 50 | + |
| 51 | +$Samples+=$Result |
| 52 | + |
| 53 | +} |
| 54 | +} |
| 55 | +#Write-Output "Script End at $(Get-date -f "HH:m:ss")" |
| 56 | +$ErrorActionPreference="Continue" |
| 57 | +$Samples | Sort-Object -Descending -Property LastHourAvg |Out-GridView |
| 58 | + |
0 commit comments