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

Clatent

Technology | Fitness | Food

  • About
  • Resources
  • Contact

Windows

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.

Tagged With: Automation, PowerShell, Windows, Windows Server

One-Liner Wednesday March 29, 2023

March 29, 2023 by ClaytonT 2 Comments

Can you believe it’s Wednesday already? I can’t either, week is flying by. Could it be the excitement of the PowerShell + Devops Global Summit coming up in a few weeks? Quite possibly! If you haven’t gotten your ticket yet, I highly recommend it. With that said, these next 3 weeks I’ll be highlighting speakers and topics from the summit.

Today’s one-liner is a great one for troubleshooting from Jeff Hicks. He will be heading the Onramp program for attendees who are just getting into IT. It is such a great program and wished it was around when I was getting into IT!

Get-WinEvent -FilterHashtable @{Logname = 'System';Level=1} -MaxEvents 10 | sort-Object ProviderName,TimeCreated

What this one-liner does is searches the System Event Log for the last 10 “Critical” events. Then sorts them by the Provider name and date/time. You could change the level for “lesser” events if needed. Also if you need to check on a remote computer you can add the -ComputerName parameter, but remember that it only takes 1 computer at a time. If you need to connect to multiple computers, you can use ForEach to reach out to all computers needed.

Hope this one-liner helps you out and hope to see you at the PowerShell + DevOps Summit!

Jeff Hicks:
Blog

PowerShell + DevOps Global Summit:
Global Summit

Microsoft Learn:
Get-WinEvent

Tagged With: Automation, Event Log, One Liner Wednesday, PowerShell, Reporting, Windows, Windows Server

One-Liner Wednesday March 15, 2023

March 15, 2023 by ClaytonT Leave a Comment

Today’s one-liner may not be a direct PowerShell command, but it can be run inside the PowerShell terminal. Are you using Intune, or looking into using Intune? If your already using it, you know by default when you add a user it sets them as a local administrator(I’m not sure exactly why, but that can be a topic for another blog post), and of course we don’t want our users to be local administrators on their computers. To resolve this issue, all you need to do is remove them from the local administrators group like below.

net localgroup administrators azuread\user@domain.com /delete

The only change needed is changing “User@domain.com” to their login address. I’d recommend adding this to your new device script, and if you do not have a new device script, I’d start one now, so you can keep adding and automating things to save you time and have consistent deployments.

Also, take a look at Azure Functions to see how you can deploy code and automate things on a bigger scale.

Tagged With: AzureAD, Intune, One Liner Wednesday, PowerShell, Windows

Module Monday January 9, 2023

January 9, 2023 by ClaytonT Leave a Comment

It’s another Module Monday, but this time it isn’t really a module, but a script, that I think in the future could be turned into a module with even more functionality. I came across this script when I was looking for a quick way to download Window ISOs easily. I mean, who isn’t tired of going through all the clicks just to get a Window’s ISO from Microsoft?

This script finds Windows 11 ISOs and goes all the way back to Windows 7, but hoping you don’t need those for your own sanity. It does only cover home, business, and education, but that is becauase those are the most common.

It’s so nice just type in .\fido.ps1 win 11 -rel latest and this will download the latest version of Windows 11 for you? Why not put it in a scheduled task, so you don’t have to worry about downloading the latest version? Or if you or someone on your team needs a certain version you can just type in -win 10 -rel 21H1 and you know you have the right one? It also downloads very quickly as well.

Hope this saves you as much time as it has for me!

GitHub:
Fido

Tagged With: Automation, ISO, Module Monday, PowerShell, Windows

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