Situatie
This script does the following:
- Retrieves a list of running processes.
- Filters the processes to include only those with a certain amount of memory usage.
- Sorts the processes based on memory usage.
- Outputs the top processes to a text file.
Solutie
# Set the threshold for memory usage in MB
$memoryThreshold = 100
# Get the list of processes
$processes = Get-Process | Where-Object { $_.WorkingSet -gt $memoryThreshold * 1MB }
# Sort the processes based on memory usage
$sortedProcesses = $processes | Sort-Object WorkingSet -Descending
# Define the output file path
$outputFilePath = “C:\TopProcesses.txt”
# Output the top processes to a text file
$sortedProcesses | Select-Object -First 10 | Out-File -FilePath $outputFilePath
# Display a summary
Write-Host “Top 10 Processes with Memory Usage > $memoryThreshold MB:”
$sortedProcesses | Select-Object -First 10 | Format-Table -Property Id, ProcessName, WorkingSet -AutoSize
Write-Host “Results saved to $outputFilePath”
Leave A Comment?