This guide provides a complete, practical command book for Windows PowerShell, a powerful automation engine and scripting language built into Windows. It enables users to perform complex tasks, manage system configurations, and automate repetitive processes with precision. To use this command book effectively, you need a Windows operating system (Windows 10, 11, Server 2016, or later) and administrative privileges for many commands.
What You'll Need
- A computer running Windows 10, 11, or a supported Windows Server version.
- Administrator rights to execute commands that modify system settings, services, or install software.
- A basic understanding of file paths and system terminology.
- An internet connection is not strictly required for core commands, but it is necessary for online help, updates, and downloading modules.
Step-by-Step
- Open the Windows PowerShell Terminal. Press the Windows key, type "PowerShell" or "Windows Terminal," and select the appropriate application from the list. For administrative tasks, right-click the application in the start menu and choose "Run as administrator" to avoid permission errors.
- Understand the Prompt. The command prompt is the text line at the top of the window. It typically displays the current directory, user name, and computer name (e.g., PS C:\Users\Admin>). Anything you type must be entered after this prompt.
- Get Help for a Command. PowerShell has extensive built-in documentation. To learn how a specific command works, type the command followed by the help flag. For example, type
Get-Help Get-Processto view documentation on the Get-Process cmdlet, which retrieves information about running processes. - Retrieve System Information. Use the
Get-ComputerInfocmdlet to fetch a comprehensive view of the computer's configuration, including OS version, BIOS data, and hardware details. This is an excellent starting point for diagnosing system issues. - List Running Processes. Type
Get-Processto see a list of all applications and services currently running on the system. You can filter this list by typingGet-Process | Where-Object {$_.CPU -gt 100}to find processes using more than 100 seconds of CPU time. - Start and Stop a Service. Services are background applications. To start a service, use the
Start-Servicecmdlet followed by the service name. For example,Start-Service Spoolerstarts the Print Spooler service. To stop it, useStop-Service Spooler. Always verify the service name usingGet-Servicefirst, as names can vary. - Manage Local Users. To create a new local user account, use the
New-LocalUsercmdlet. An example command isNew-LocalUser -Name "NewAdmin" -Password (Read-Host -AsSecureString). This command prompts you to type a password securely. To add this user to the Administrators group, pipe the result toAdd-LocalGroupMember. - Copy and Move Files. Unlike older command prompts, PowerShell uses cmdlets for file operations. To copy a file, use
Copy-Item "C:\Source\file.txt" "D:\Destination\". To move a file, replaceCopy-ItemwithMove-Item. Wildcards like*can be used to copy multiple files at once. - View and Modify Environment Variables. Environment variables store system-wide settings. Type
Get-ChildItem Env:to list all variables. To view a specific variable, type$env:Path. You can add a new path to the system PATH variable by modifying it in the environment properties or using a command, though this often requires a restart or a new terminal session to take effect. - Execute a Command Script. PowerShell scripts have the
.ps1extension. To run a script, you must first enable script execution. TypeSet-ExecutionPolicy RemoteSignedand confirm the prompt. Then, run the script by typing its path, such as.\MyScript.ps1.
Common Mistakes
One of the most common errors is confusing cmdlets with executable commands. Cmdlets are verbs followed by nouns (e.g., Get-Service), whereas executables are programs (e.g., net.exe). While PowerShell can run executables, it is more efficient to use the native cmdlets. Another frequent mistake is neglecting to escape special characters in strings, such as quotes or backticks.
Tips
PowerShell is case-insensitive, so Get-Process and get-process produce the same result. However, using CamelCase for cmdlets (e.g., Get-Process) makes your scripts easier to read and maintain. You can use the Tab key to auto-complete cmdlets and parameter names, which speeds up command entry and reduces typos.
Troubleshooting
If a command returns an error stating "Access is denied," it means the current user account does not have sufficient permissions to perform the action. You must run the PowerShell window as an administrator. If a command is not recognized, check for typos or ensure the module containing the cmdlet is loaded. For example, if a specific hardware command fails, it might be missing from the default installation and require an additional module download.
Frequently Asked Questions
Is PowerShell only for advanced users?
No, while it is powerful, basic commands like Get-Process and Get-Service are accessible to beginners for checking system status.
How do I exit PowerShell?
Type Exit and press Enter, or simply close the window.
Can I use PowerShell on Windows 7?
Yes, PowerShell 5.1 is included with Windows 7 SP1, though it is less feature-rich than the version included in Windows 10 and 11.
What is the difference between PowerShell and Command Prompt?
PowerShell is an object-oriented shell, meaning it manipulates objects rather than just text, allowing for more sophisticated data processing and automation.
Are PowerShell scripts safe?
Scripts can contain malicious code. Only run scripts from trusted sources, and always review the code before execution.
Can I run PowerShell commands on a remote computer?
Yes, using the Invoke-Command cmdlet allows you to run scripts and commands on remote machines.