• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Clatent

Technology | Fitness | Food

  • About
  • Resources
  • Contact

Quick Use of OpenAI – End Processes

September 27, 2023 by ClaytonT Leave a Comment

Here is a quick use of OpenAI / ChatGPT to remove Windows processes. If it doesn’t get it right the first time, it usually is a good enough base to only need an edit or 2 for simpler scripts. Not bad for going 2/2 on no edits needed!

PROMPT 1:

Me:

You are a powershell expert, can you write me a script to find all processes running then show me them in a window and I can select which ones I want to delete?

ChatGPT:

Certainly! Here’s a PowerShell script that will retrieve all running processes, display them in a GUI window using Out-GridView, and then terminate the selected processes:


# Get all running processes
$processes = Get-Process | Select-Object Id, Name, CPU, Path

# Display processes in a GridView for selection
$selectedProcesses = $processes | Out-GridView -Title "Select processes to terminate" -PassThru

# Terminate selected processes
$selectedProcesses | ForEach-Object {
    try {
        Stop-Process -Id $_.Id -Force
        Write-Host "Terminated process: $($_.Name) with ID: $($_.Id)"
    } catch {
        Write-Warning "Failed to terminate process: $($_.Name) with ID: $($_.Id)"
    }
}

Steps:

  1. The script fetches all running processes and selects a few useful properties like Id, Name, CPU, and Path.
  2. The processes are then presented in a GridView window using Out-GridView. You can select multiple processes by holding down the Ctrl key and clicking on them.
  3. After you click “OK”, the script will attempt to terminate the selected processes.

Note: Ensure you have the required permissions to terminate processes. Also, be cautious about which processes you terminate, as some are essential for the proper functioning of your system.

Review 1:

You can see that it created the first prompt perfectly, and no edits were necessary.

Selected the processes and gave me a GUI to delete the ones I don’t need anymore

PROMPT 2:

ME:

Can you make it so I can select which one I want see beween ram and cpu?

ChatGPT:

Of course! We can add an initial prompt to let you select between viewing processes based on RAM or CPU usage.

Here’s the updated script:


# Get all running processes
$processes = Get-Process | Select-Object Id, Name, CPU, WS

# Prompt the user to choose between CPU and RAM
$choice = $host.ui.PromptForChoice("Selection", "Choose the metric to display top 5 processes:", @("CPU", "RAM"), 0)

# Display the top 5 processes based on the selected metric
if ($choice -eq 0) {
    $topProcesses = $processes | Sort-Object CPU -Descending | Select-Object -First 5
} else {
    $topProcesses = $processes | Sort-Object WS -Descending | Select-Object -First 5
}

# Display processes in a GridView for selection
$selectedProcesses = $topProcesses | Out-GridView -Title "Select processes to terminate" -PassThru

# Terminate selected processes
$selectedProcesses | ForEach-Object {
    try {
        Stop-Process -Id $_.Id -Force
        Write-Host "Terminated process: $($_.Name) with ID: $($_.Id)"
    } catch {
        Write-Warning "Failed to terminate process: $($_.Name) with ID: $($_.Id)"
    }
}

Now, when you run the script, it will first prompt you to choose between CPU and RAM. After you make your selection, it will display the top 5 processes based on that metric. You can then select which processes you want to terminate.

Review 2:

As you can see this worked exactly how I wanted it to and gave me the option to pick the top 5 highest of ram or cpu usage, then allowed me to delete.

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
  • Email a link to a friend (Opens in new window) Email
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit

Like this:

Like Loading...

Related

Tagged With: Automation, PowerShell, Windows, Windows Server

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recipe Rating




Primary Sidebar

Clayton Tyger

Tech enthusiast dad who has lost 100lbs and now sometimes has crazy running/biking ideas. Read More…

Find Me On

  • Email
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter

Recent Posts

  • Learning ValidateSet in PowerShell: Valid Values Only
  • Teams Chat and PowerShell – How to add value!
  • EntraFIDOFinder: New Web UI and Over 70 New Authenticators
  • January 19, 2026 Updates to EntraFIDOFinder
  • v0.0.20 EntraFIDOFinder is out

Categories

  • 365
  • Active Directory
  • AI
  • AzureAD
  • BlueSky
  • Cim
  • Dashboards
  • Documentation
  • Entra
  • Get-WMI
  • Learning
  • Module Monday
  • Nutanix
  • One Liner Wednesday
  • Passwords
  • PDF
  • Planner
  • PowerShell
  • Read-Only Friday
  • Reporting
  • Security
  • Uncategorized
  • Windows
  • WSUS

© 2026 Clatent

%d