Ongoing monitoring ensures your optimizations remain effective and helps identify new performance issues before they impact users.
Install Windows Admin Center for centralized monitoring:
# Download and install Windows Admin Center
$wacUrl = "https://aka.ms/WACDownload"
$wacPath = "$env:TEMP\WindowsAdminCenter.msi"
Invoke-WebRequest -Uri $wacUrl -OutFile $wacPath
Start-Process msiexec.exe -ArgumentList "/i $wacPath /quiet" -Wait
Create custom performance counter data collector sets:
# Create a new data collector set for server monitoring
$dataCollectorSet = New-Object -ComObject Pla.DataCollectorSet
$dataCollectorSet.DisplayName = "Server Performance Monitoring"
$dataCollectorSet.Duration = 86400 # 24 hours
$dataCollectorSet.Subdirectory = "ServerPerf"
$dataCollectorSet.Commit("ServerPerf", $null, 0x0003)
Set up PowerShell-based monitoring script for critical metrics:
# Create monitoring script
$monitorScript = @'
$counters = @(
"\Processor(_Total)\% Processor Time",
"\Memory\Available MBytes",
"\PhysicalDisk(_Total)\% Disk Time",
"\Network Interface(*)\Bytes Total/sec"
)
$samples = Get-Counter -Counter $counters -SampleInterval 60 -MaxSamples 1440
$samples | Export-Counter -Path "C:\PerfLogs\DailyPerf_$(Get-Date -Format 'yyyyMMdd').blg"
'@
$monitorScript | Out-File -FilePath "C:\Scripts\DailyMonitoring.ps1" -Encoding UTF8
Create scheduled task for automated monitoring:
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\DailyMonitoring.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At "12:00AM"
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
Register-ScheduledTask -TaskName "Daily Performance Monitoring" -Action $action -Trigger $trigger -Settings $settings -RunLevel Highest
Configure Windows Event Log monitoring for performance-related events:
# Monitor for critical system events
Get-WinEvent -FilterHashtable @{LogName='System'; Level=1,2,3; StartTime=(Get-Date).AddHours(-24)} |
Select-Object TimeCreated, Id, LevelDisplayName, Message |
Export-Csv -Path "C:\Logs\SystemEvents_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation
Pro tip: Set up email alerts using PowerShell and SMTP when critical thresholds are exceeded. Create a baseline during normal operations, then alert when metrics exceed 150% of baseline values.
Create performance baseline for comparison:
# Capture baseline performance data
$baseline = Get-Counter -Counter $counters -SampleInterval 5 -MaxSamples 720 # 1 hour baseline
$baseline | Export-Counter -Path "C:\PerfLogs\Baseline_$(Get-Date -Format 'yyyyMMdd').blg"
Verification: Check that scheduled tasks are running with Get-ScheduledTask -TaskName "Daily Performance Monitoring" and verify log files are being created in C:\PerfLogs directory.