Additional Script Updates
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# Detection Script: Detect_SystemPerformance.ps1
|
||||
|
||||
# Define thresholds for high usage
|
||||
$cpuThreshold = 80
|
||||
$memoryThreshold = 80
|
||||
$diskThreshold = 80
|
||||
|
||||
# Get current CPU usage
|
||||
$cpuUsage = Get-Counter '\Processor(_Total)\% Processor Time' | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue
|
||||
|
||||
# Get current memory usage
|
||||
$memoryUsage = (Get-Counter '\Memory\% Committed Bytes In Use').CounterSamples.CookedValue
|
||||
|
||||
# Get current disk usage
|
||||
$diskUsage = Get-Counter '\LogicalDisk(_Total)\% Disk Time' | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue
|
||||
|
||||
# Check if any usage exceeds the threshold
|
||||
if ($cpuUsage -gt $cpuThreshold -or $memoryUsage -gt $memoryThreshold -or $diskUsage -gt $diskThreshold) {
|
||||
Write-Output "High system resource usage detected: CPU=$cpuUsage%, Memory=$memoryUsage%, Disk=$diskUsage%"
|
||||
exit 1
|
||||
} else {
|
||||
Write-Output "System resource usage is within acceptable limits: CPU=$cpuUsage%, Memory=$memoryUsage%, Disk=$diskUsage%"
|
||||
exit 0
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
# Remediation Script: Remediate_SystemPerformance.ps1
|
||||
|
||||
# Clear temporary files
|
||||
$TempFolder = "$env:Temp"
|
||||
Remove-Item "$TempFolder\*" -Recurse -Force -ErrorAction SilentlyContinue
|
||||
|
||||
# Clear Windows Update cache
|
||||
$WindowsUpdateCache = "C:\Windows\SoftwareDistribution\Download"
|
||||
Remove-Item "$WindowsUpdateCache\*" -Recurse -Force -ErrorAction SilentlyContinue
|
||||
|
||||
# Optimize disk space
|
||||
Start-Process -FilePath "cleanmgr.exe" -ArgumentList "/sagerun:1" -NoNewWindow -Wait
|
||||
|
||||
# Defragment the disk (if not SSD)
|
||||
$diskType = Get-PhysicalDisk | Where-Object MediaType -eq "HDD"
|
||||
if ($diskType) {
|
||||
Optimize-Volume -DriveLetter C -Defrag -Verbose
|
||||
}
|
||||
|
||||
Write-Output "System performance optimization tasks completed."
|
||||
Reference in New Issue
Block a user