10 Most Useful PowerShell Commands for Everday Users

Summary

  • Use PowerShell in Windows to automate tasks, troubleshoot your device, and extend Windows functionality.
  • Always inspect or verify scripts before running them, and only relax restrictions for trusted code.
  • Use Show-Command, Get-Help and Get-Command to learn about PowerSgell cmdlets.

Scripting is often seen as something only IT admins do to lengthen their coffee breaks, but home users can benefit from command line automation, too. Here are 10 PowerShell commands you can use to write scripts to lighten your workload, troubleshoot problems, and uncover new functionality.

Never Trust a Script You Find Online

It goes without saying, you should check what any script (or bit of code) actually does before running it—internet pranksters have been known to plant helpful-looking (but actually malicious) code online, knowing that someone might unintentionally run it.

There’s a serious cybersecurity risk, too, if that code does something like deleting your files or stealing financial info. You should look up what each command in a script does, or, if it’s a confusing jumble of statements, you can use ChatGPT to help untangle them and discover their purpose. You can even get it to help write your PowerShell scripts for you (much the way you can with Excel formulas).

Of course, before you start, you’ll need to open PowerShell on your Windows device, or create a PowerShell script to run. It’s also helpful to know the lingo—in PowerShell parlance, a cmdlet is another word for a command (in this case, one that performs a single specific task).

Test-NetConnection Helps You Troubleshoot Connectivity Issues

Test-NetConnection in Windows PowerShell.

tnc for short, Test-NetConnection shows diagnostic info about a connection to another network device. This is handy for troubleshooting connectivity to your router (to make sure you’re getting the best connection for your next gaming session), your wireless printer, or your NAS box.

tnc -computername -port 

You can also run tnc -InformationLevel “Detailed” for more information.

Get-NetIPConfiguration and Get-NetIPAddress will also show useful information about your current network connections.

Get-NetIPConfiguration in Windows PowerShell.

Restart-Computer and Stop-Computer Do Just What They Say

These commands do just what they say. Seemingly trivial, they’re super useful to add to a script that updates software or drivers, or to add to your desktop if you find the frequent need to reset your device and find the whole Ctrl+Alt+Del thing inconvenient.

Just run Restart-Computer -force or Stop-Computer -force and watch the life quickly drain from your monitor.

Demystify cmdlets With Get-Help, Get-Command and Get-Member

Get-Help and Get-Command in Windows PowerShell.

Documentation at your fingertips! Most PowerShell cmdlets can be described using the Get-Help command, which will show you information about a command. Just run Get-Help CommandName or Get-Help -examples to see some examples.

As for Get-Command and Get-Member, why not use Get-Help to check them out?

Learn PowerShell With Show-Command

Show-Command in PowerShell.

Put Show-Command in front of any other command, and you’ll receive a graphical interface with all the available parameters, and you can even run the command from that interface. Run on its own, it’ll show all commands available. It’s like Get-Help on steroids, if you don’t mind breaking out of the command line interface a bit.

Clear Stuck Print Jobs With Stop-Service and Start-Service

Windows and printers have never been a match made in heaven, and even IT gurus have spent countless hours trying to troubleshoot even simple issues.

PowerShell can help here, just use Stop-Service and Start-Service in a script to stop the printer spooler (the Windows service that manages print jobs), in conjunction with Remove-Item (that deletes files, in this case queued print jobs) and hope that it clears whatever inexplicable issue is stopping you from printing.

Stop-Service spooler
Remove-Item -recurse -force C:\Windows\System32\Spool\PRINTERS*
Start-Service spooler

Notice that -recurse flag in the Remove-Item command: this is why it’s vital to always carefully read all commands and check all paths are correct, as running a recursive delete on the wrong folder could destroy your system or delete valuable data.

Run Your Own PowerShell Scripts With Set-ExecutionPolicy

If you try and run a PowerShell script, even one you wrote yourself, it’ll most likely be blocked by the default execution policy that only allows scripts cryptographically signed by known developers. Set-ExecutionPolicy overrules this, and running Set-ExecutionPolicy Bypass Process -Force will let you run any script for the current session. Just make sure they’re trustworthy.

Speak Your Computer’s Mind With SAPI.SpVoice

SAPI.SpVoice brings text to speech to the command line! Do useful things like read out email notifications, or frustrate yourself by having your PC read out failed print jobs, or just annoy your cubicle mate. Combine it with Invoke-RestMethod to grab a random useless fact and read it out:

( New-Object -com SAPI.SpVoice ).speak(( Invoke-RestMethod -Uri ' ).text )

Copy Files With Copy-Item

Super simple syntax to do a simple file copy with Copy-Item!

Copy-Item  

I’ll divert from the ‘strictly PowerShell’ vibe of this article to recommend robocopy for anything more than basic copy tasks.

robocopy   /MIR /R:5

View the Full Contents of a Folder (And Subfolders) Using Get-ChildItem

Get-ChildItem gets all the files in a folder, and can be run recursively. For example, here’s how to list the files in the current folder and its subfolders by size:

Get-ChildItem -Recurse | Sort-Object Length -Descending | Select-Object FullName, Length -First 10

Monitor Performance With Get-Process

Get-Process in Windows PowerShell.

If you don’t want to leave the Task Manager open, you can always run Get-Process for a quick look at what your Windows PC is up to.

Get-Process | Sort CPU -Descending | Select -First 5 Name,Id,CPU,WS

The above PowerShell command uses pipes (the vertical bar character that looks like this |) to pass the output from one command to another, letting you chain them together.

You’ve Only Just Begun Your Scripting Journey

OK, most of these use-cases are quite trivial, but the power of scripting is in solving your own unique problems that aren’t already covered by your operating system’s user interface.

It’s less about which specific commands are most useful for regular users, and what commands you can find that can do the specific thing you want to do (shout out to Show-Command again as a good starting point to see what commands are available for you to work with). Combined with the Task Scheduler, you can script daily system maintenance or backup tasks, and then set them to run at a convenient time.

If you want to automate beyond the confines of your device, IFTT works on your mobile device and can also interact with many web services.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top