How to Enable BitLocker with PowerShell (Step by Step)

Enable BitLocker with PowerShell

To enable BitLocker with PowerShell, open PowerShell as administrator, add a recovery password, back it up, then run Enable-BitLocker with a TPM protector: Encryption then runs in the background. Below I cover the checks to do first, every protector type, data drives, backing up the recovery key and tracking progress. I ran the read-only checks … Read more

How to Clear PowerShell History (Session and PSReadLine)

Clear PowerShell history with Clear-History and the PSReadLine history file

To clear PowerShell history completely, clear the session list and delete the PSReadLine history file, which is what the Up arrow reads from: Then close and reopen PowerShell. Below I show both kinds of history, how to remove only one sensitive line, and how to stop PowerShell from saving commands. PowerShell keeps two kinds of … Read more

How to Remove a Computer from a Domain Using PowerShell

Remove a computer from a domain with PowerShell

To remove a computer from a domain with PowerShell, run Remove-Computer as administrator, name the workgroup to join and restart: The credential needs rights to remove the computer account. Below I check the join state, preview the command, remove remote PCs and clean up AD. My test PC isn’t on a domain, so I used … Read more

Set Password Never Expires for a Local User in PowerShell

Set password never expires for a local user with PowerShell

To set a local user’s password to never expire, run Set-LocalUser with -PasswordNeverExpires $true in PowerShell as administrator: It works in PowerShell 7 and Windows PowerShell 5.1. Below I check which accounts already never expire, preview the change, show two other ways and cover domain accounts. I didn’t change any accounts on my PC. Check … Read more

How to Change the Wallpaper with PowerShell

Change the wallpaper with PowerShell

To change the wallpaper with PowerShell, call the Windows SystemParametersInfo function with the image path. Add-Type makes it available, and the change shows right away without signing out: It returns True when Windows accepts the image, affects only the signed-in user and needs no admin rights. Below I set the fit style, wrap it in … 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

Try Catch in PowerShell (With Finally and Examples)

Try catch in PowerShell

In PowerShell, try/catch runs the code in try and jumps to catch when a terminating error happens. For cmdlets, add -ErrorAction Stop so their errors reach the catch block: Output: Inside catch, $_ is the error record, and $_.Exception.Message is the readable message. Below I explain why catch sometimes doesn’t run, catch specific error types, … 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

How to Find the Location of an Executable in PowerShell

Find the location of an executable in PowerShell

To find the location of an executable in PowerShell, run Get-Command and read its Source property. It searches the folders in your PATH, just like running the program does: Output: Below I look up several programs at once, list every copy with -All and where.exe, and find where a running program lives. I used only … Read more

How to Get the Last Reboot Time Using PowerShell

Get the last reboot time with PowerShell

To get the last reboot time with PowerShell, read LastBootUpTime from Win32_OperatingSystem. Subtract it from the current time to get the uptime: Output: Get-CimInstance returns a normal DateTime, so no conversion is needed. Below I show the shorter PowerShell 7 cmdlet, the reboot history from the event log, remote PCs and one Fast Startup catch. … Read more