Fix ‘Install-Module Is Not Recognized’ in PowerShell and CMD

Fix Install-Module is not recognized as an internal or external command

“‘Install-Module’ is not recognized as an internal or external command” means you typed the command into Command Prompt, not PowerShell. Open PowerShell and run it there, or call it from cmd like this: If PowerShell itself says the term isn’t recognized, the cause is different. I reproduced each one below in PowerShell 7 and Windows … Read more

How to Restart a Windows Service Using PowerShell (7 and 5.1)

Restart a Windows service using PowerShell

To restart a Windows service using PowerShell, open PowerShell as administrator and run Restart-Service with the service name: Restart-Service stops the service and starts it again in one step. It works the same in PowerShell 7 and Windows PowerShell 5.1, but remote restarts and services with dependents need a little more care. Find the service … Read more

How to Set a Service to Automatic Using PowerShell (7 and 5.1)

Set a service to Automatic using PowerShell

To set a service to automatic using PowerShell, open PowerShell as administrator and run Set-Service with the service name and -StartupType Automatic: That one line works in PowerShell 7 and Windows PowerShell 5.1. Delayed start, checking the result and remote servers don’t work the same in both, and that’s where most scripts break. Find the … Read more

How to Create Local Users in Windows Using PowerShell

Create local users in Windows using PowerShell

To create a local user in Windows with PowerShell, open PowerShell as administrator and run New-LocalUser with a name and a secure password: Then add the account to a group with Add-LocalGroupMember. Below I cover options, name rules, bulk creation from a CSV file, and the Access denied error. Create a local user account with … Read more

How to Throw an Exception with a Message in PowerShell

PowerShell throw exception with a custom message

To throw an exception with a message in PowerShell, put your text after the throw keyword. It stops the script right there, and a try/catch block can read the text back from $_.Exception.Message: A plain string is enough most of the time. Below I’ll show what the error looks like in PowerShell 7 and Windows … Read more

How to Split a String and Get the Second Element in PowerShell

Split a string and get the second element in PowerShell

To split a string and get the second element in PowerShell, split it with -split and read index [1], because arrays start at 0: The parentheses matter: they finish the split before PowerShell applies the index. Below I cover the .Split() method, extra spaces, special delimiters, missing values and whole files, with the spots where … Read more

7 Best PowerShell Extensions for VS Code (2026)

Best PowerShell extensions for Visual Studio Code

Search the VS Code Marketplace for PowerShell and you get dozens of results, some of them abandoned years ago. We sorted out which ones still earn a spot in a scripting setup. Quick answer: the best PowerShell extensions for VS Code start with Microsoft’s PowerShell extension (ms-vscode.powershell), which already includes IntelliSense, PSScriptAnalyzer, formatting and the … Read more

How to Create a PowerShell Module (Step by Step)

Create a PowerShell module with a .psm1 file and a manifest

To create a PowerShell module, save your functions in a .psm1 file inside a folder with the same name, then load it with Import-Module. That’s the whole minimum: Below I build a small real module step by step: export rules, a manifest, a Public/Private layout, the right install folder and auto-loading. I ran each step … Read more

PowerShell Array Parameters: Pass Arrays to Functions

PowerShell array parameters

To make a PowerShell array parameter, give the parameter an array type such as [string[]]. Callers can then pass several values separated by commas, or just one value: Output: With [string[]], a single value still arrives as an array with one item, so the same foreach loop handles both calls. I tested every example in … Read more

PowerShell Switch Parameter (With Examples)

PowerShell switch parameter with examples

A PowerShell switch parameter is a parameter of type [switch] that’s on when you include it and off when you leave it out. It takes no value, like -Force or -Recurse: Output: Below I cover how to pass an explicit value, tell whether the caller used the switch, forward it to another function and name … Read more