Windows PowerShell vs CMD: Key Differences With Examples

Windows PowerShell vs CMD

Windows PowerShell vs CMD comes down to one difference: CMD passes plain text between commands, while PowerShell passes .NET objects you can filter, sort and format. For anything beyond a quick one-liner, PowerShell is the better choice. CMD (cmd.exe, the Command Prompt) is still around for batch files and old habits. Below I compare the … Read more

How to Unblock Files Recursively Using Unblock-File in PowerShell

Unblock files recursively in PowerShell

To unblock files recursively in PowerShell, list every file in the folder with Get-ChildItem -Recurse and pipe them to Unblock-File: Only do this for files you trust. Below I show how Windows marks downloads, how to find blocked files first, and how to unblock only scripts, all tested in PowerShell 7.6 and 5.1. Why Windows … Read more

How to Disable Windows Defender Using PowerShell (and Turn It Back On)

Disable Windows Defender using PowerShell

To disable Windows Defender real-time protection using PowerShell, run Set-MpPreference in an elevated window, after turning off Tamper Protection in Windows Security: Microsoft Defender Antivirus is the current name for Windows Defender. Turning it off leaves the PC unprotected, so do it only briefly while troubleshooting. Below I cover checking the status, why the command … Read more

How to Change Directory in PowerShell (cd and Set-Location)

Change directory in PowerShell

To change directory in PowerShell, use Set-Location, or its short alias cd, followed by the folder path. Get-Location shows where you are now: Output: Below I cover relative paths, folders with spaces, going back to the previous folder, and a .NET gotcha that trips up scripts. Every example ran in PowerShell 7.6 and Windows PowerShell … Read more

How to Install Git on Windows Using PowerShell

Install Git on Windows using PowerShell

To install Git on Windows using PowerShell, run one winget command. winget is the Windows Package Manager, built into Windows 11 and current Windows 10 releases: That’s the command the Git project itself recommends. -e matches the ID exactly, so winget can’t pick a similarly named package. Below I cover checking the install, updating, setting … Read more

PowerShell Test-NetConnection: Test Ports, Ping and Routes

PowerShell Test-NetConnection examples

Test-NetConnection checks whether your computer can reach another host, and whether a specific TCP port on it is open. Give it a computer name and a port: Output: TcpTestSucceeded True means the port accepted a connection. I selected three properties because the full output also lists your own IP address and network adapter. Every example … Read more

How to Install Windows Updates Using PowerShell

Install Windows updates using PowerShell

To install Windows updates using PowerShell, use the Windows Update Agent built into Windows, or the community PSWindowsUpdate module. PSWindowsUpdate is the quickest. In an elevated window, install it once, then install every available update: -AutoReboot restarts the PC if an update needs it, so leave it off on machines people are using. Below I … Read more

PowerShell Get-WindowsAutopilotInfo: Collect and Upload the Hardware Hash

PowerShell Get-WindowsAutopilotInfo

Get-WindowsAutopilotInfo is a PowerShell script that collects a device’s hardware hash and serial number for Windows Autopilot. Install it from the PowerShell Gallery, then save the hash to a CSV or upload it to Intune. Microsoft documents these commands for an elevated window: The file lands in C:\HWID\AutopilotHWID.csv, ready to import into Intune. Below I … Read more

How to Retrieve Your Windows Product Key Using PowerShell

Retrieve the Windows product key using PowerShell

To retrieve your Windows product key using PowerShell, read the OA3xOriginalProductKey property of the SoftwareLicensingService class. It returns the key your PC’s maker stored in the firmware: It doesn’t need administrator rights. In my examples below I mask the keys with a small Hide-Key function before printing them, because a product key is a license … Read more

How to Check the PowerShell Version (Windows, Scripts and Remote)

How to check the PowerShell version

To check the PowerShell version, run $PSVersionTable.PSVersion. It works in every version on Windows, macOS and Linux. Here it is in PowerShell 7: Output in PowerShell 7.6: The same command in Windows PowerShell 5.1 shows a different layout, with Build and Revision instead of Patch: Most Windows 11 PCs have both: Windows PowerShell 5.1 is … Read more