How to Delete User Profiles Using PowerShell in Windows 11

Delete user profiles using PowerShell in Windows 11

To delete user profiles using PowerShell in Windows 11, find the profile with Get-CimInstance Win32_UserProfile and pipe it to Remove-CimInstance in an elevated window. That removes the folder and the registry entry together: Deleting a profile can’t be undone, so below I list profiles safely, find stale ones and preview the removal with -WhatIf. I … Read more

How to Generate SSH Keys with PowerShell (ssh-keygen on Windows)

Generate SSH keys with PowerShell

To generate SSH keys with PowerShell, run ssh-keygen, which ships with Windows 10 and 11 as part of the built-in OpenSSH client. Ed25519 is the recommended key type: It asks where to save the key and for a passphrase, then creates a private key and a .pub public key. Below I check OpenSSH is installed, … Read more

How to Enable WinRM Using PowerShell (Enable-PSRemoting)

Enable WinRM using PowerShell

To enable WinRM using PowerShell, run Enable-PSRemoting in an elevated window. It starts the WinRM service, sets it to start automatically, creates a listener and opens the firewall: Before you run it, check the current state and the two things that usually make it fail: a Public network and missing firewall rules. I ran these … Read more

How to Keep Your Screen Active with a PowerShell Script

Keep your screen active with a PowerShell script

To keep your screen active with a PowerShell script, ask Windows directly with the SetThreadExecutionState API. It keeps the display and PC awake while the script runs, and everything goes back to normal when it stops: That’s better than the common trick of pressing a fake key every minute. Below I check your current timeouts, … Read more

How to Open a File in PowerShell (Default App, Notepad, Console)

Open a file in PowerShell

To open a file in PowerShell with its default app, run Invoke-Item with the file’s path. It works like double-clicking the file in File Explorer: Below I show how to preview what will open, open a file in a specific app, and read files right in the console. I tested each command in PowerShell 7.6 … Read more

How to Set Folder Permissions Using PowerShell (Get-Acl, Set-Acl)

Set folder permissions using PowerShell

To set folder permissions using PowerShell, read the folder’s ACL with Get-Acl, add a FileSystemAccessRule, and write it back with Set-Acl. This grants the Users group Modify on a folder and everything inside it: Below I view permissions, grant and remove access, control inheritance and do the same with icacls. I tested everything on a … Read more

PowerShell Regex: How to Use Regular Expressions (With Examples)

PowerShell regex examples

PowerShell regex (regular expressions) lets you match, extract, replace and split text by pattern. The operators -match, -replace and -split all take a regex, and $Matches holds what -match found: Output: Below I cover case sensitivity, named groups, replacing, splitting, finding every match, Select-String and switch -Regex. Every example ran in PowerShell 7.6 and 5.1, … Read more

How to Get the .NET Version Using PowerShell (Framework and .NET)

Get the .NET version using PowerShell

To get the .NET version using PowerShell, check two things: the .NET Framework version in the registry, and the modern .NET runtimes with dotnet –list-runtimes. Windows can have both installed side by side. Below I show both checks, plus how to see which .NET your PowerShell session runs on. I ran them on Windows 11 … Read more

How to Get the BIOS Serial Number Using PowerShell

Get the BIOS serial number using PowerShell

To get the BIOS serial number using PowerShell, read the SerialNumber property of the Win32_BIOS class. One line does it, with no admin rights needed: Output: That’s the same number printed on the sticker of most laptops and desktops. Below I compare the other places Windows stores serials, replace the old wmic command, and collect … Read more

How to Get an IP Address Using PowerShell in Windows

Get an IP address using PowerShell

To get your IP address using PowerShell, run Get-NetIPConfiguration and read the IPv4 address of the adapter that has a default gateway. That’s the address your PC uses on the network: Below I list every address, get the main one with its gateway, return just the address for scripts, and check remote PCs and your … Read more