How to check running processes with PowerShell

Configurare noua (How To)

Situatie

This script does the following:

  1. Retrieves a list of running processes.
  2. Filters the processes to include only those with a certain amount of memory usage.
  3. Sorts the processes based on memory usage.
  4. 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”

Tip solutie

Permanent

Voteaza

(2 din 5 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?