PowerShell Invoke-WebRequest: GET, POST, Download and Error Examples

PowerShell Invoke-WebRequest examples

PowerShell Invoke-WebRequest sends an HTTP or HTTPS request and returns the full response: status code, headers, content and links. The simplest call is a GET request to a URL: Below I cover GET and POST requests, custom headers, downloading files, calling a REST API and handling errors. I tested these against real sites in PowerShell … Read more

How to List Local Users with PowerShell (Get-LocalUser)

List local users with PowerShell

To list local users with PowerShell, run Get-LocalUser. It returns every local account on the PC, including the built-in ones, with whether each is enabled: Output: Below I filter enabled accounts, compare Get-LocalUser with net user and CIM, export a report and check remote PCs. I masked my own account names in the output. What … Read more

How to Use curl in PowerShell: curl.exe vs. the Alias

Use curl in PowerShell

To use curl in PowerShell, type curl.exe instead of curl. Windows 10 and 11 include the real curl, and the .exe makes sure you get it rather than an alias: Output: In Windows PowerShell 5.1, plain curl is an alias for Invoke-WebRequest, so your curl options fail. Below I show the difference, send JSON without … 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

PowerShell Not Equal Operator (-ne) With Examples

PowerShell not equal operator

The not equal operator in PowerShell is -ne. It returns True when two values are different, and it ignores case for text: Output: PowerShell doesn’t support !=. Writing if (5 != 3) fails with “Unexpected token ‘!=’ in expression or statement.” I ran every example in PowerShell 7.6 and Windows PowerShell 5.1, with the same … Read more

Fix: The File Is Not Digitally Signed. You Cannot Run This Script

Fix the file is not digitally signed error in PowerShell

The “file is not digitally signed. You cannot run this script on the current system” error means your execution policy only runs signed scripts, and this one isn’t signed. For a script you trust, the quickest fix is to unblock it: Below I reproduce the error, show why it happens, and walk through four fixes … Read more

Delete User Profiles Older Than 30 Days with PowerShell

Delete user profiles older than 30 days using PowerShell

To delete user profiles older than 30 days with PowerShell, find them with Win32_UserProfile, skip system and loaded profiles, and remove each one with Remove-CimInstance. Run it as administrator, with -WhatIf first: Remove-CimInstance deletes the profile folder and its registry entry together. Below I explain each filter, test it on sample data, and cover remote … Read more

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 Open PowerShell in a Folder (Windows 11 and 10)

Open PowerShell in a folder

To open PowerShell in a folder, open the folder in File Explorer, click the address bar, type pwsh (or powershell for Windows PowerShell 5.1) and press Enter. PowerShell starts with that folder as its location. In Windows 11 you can also right-click inside the folder and choose Open in Terminal. Below I cover shortcuts, command-line … Read more

How to List Local Administrators Using PowerShell

List local administrators using PowerShell

To list local administrators with PowerShell, run Get-LocalGroupMember on the Administrators group. It works without admin rights in PowerShell 7 and 5.1: Below I run it, make it work on any language of Windows, use net localgroup as a fallback, check remote PCs and explain why an admin account isn’t always running as admin. List … Read more