Photo by Daniil Komov on Unsplash
So I was knee-deep in a migration project a few months back — moving user profiles across a hundred-something machines — and a junior admin on my team was doing it manually. One. Machine. At. A. Time. I honestly had to step away and breathe for a second. That's the kind of situation where PowerShell scripting either saves your weekend or you don't have one. I pulled together a script in about 20 minutes and we were done before lunch.
That experience reminded me how many people treat PowerShell like a last resort instead of a first instinct. So here are the commands and tricks I actually use — not a rehashed list of beginner stuff you've seen on every Microsoft docs page.
1. Stop Typing Full Cmdlet Names — Use Tab Completion Smartly
This sounds obvious but most people don't realize PowerShell's tab completion works on parameters too, not just cmdlets. Start typing a parameter name and hit Tab. It'll cycle through valid options. Pair that with Show-Command and you've got a GUI popup that fills in parameters for you:
Show-Command Get-EventLog
Genuinely useful when you're working with a cmdlet you don't use every day and don't want to keep alt-tabbing to docs.
2. Profile Scripts Are Your Best Friend
Your PowerShell profile is basically your personal config file that loads every time you open a session. Most people don't set one up. Here's how to check if yours exists and open it:
Test-Path $PROFILE
notepad $PROFILE
Inside that file I keep aliases, custom functions, and default directory changes. For example, I always jump straight to my scripts folder on startup:
Set-Location C:\Scripts
Add that one line to your profile and you'll never have to navigate there again. Small thing, but you'd be amazed how much friction it removes over a workday.
3. Get-Help Is Actually Good Now
I know, I know — documentation. But PowerShell's built-in help is legitimately solid, especially with the -Examples flag. Run this first to make sure you have the latest version:
Update-Help -Force
Then try:
Get-Help Get-ADUser -Examples
Real working examples, right in your terminal. I've solved "what does this cmdlet even do" questions in 30 seconds doing this instead of Googling for five minutes.
4. Pipeline Filtering — Do It Earlier, Not Later
Here's something I see constantly that drives me nuts. People pull back massive datasets and then filter at the end:
# Don't do this
Get-Process | Where-Object { $_.CPU -gt 100 }
That's fine for processes, but with something like Active Directory queries or large log files, filtering at the source is dramatically faster:
Get-ADUser -Filter {Department -eq "Finance"} -Properties Department
Use the -Filter parameter whenever it's available on the cmdlet itself. The difference in execution time on large environments is not subtle.
5. Splatting — Clean Up Ugly Long Commands
Honestly one of the most underused features in PowerShell scripting. Instead of writing a command that wraps around three lines:
New-ADUser -Name "John Smith" -GivenName "John" -Surname "Smith" -SamAccountName "jsmith" -UserPrincipalName "jsmith@company.com" -Path "OU=Users,DC=company,DC=com" -Enabled $true
Use a hashtable and splat it:
$params = @{
Name = "John Smith"
GivenName = "John"
Surname = "Smith"
SamAccountName = "jsmith"
UserPrincipalName = "jsmith@company.com"
Path = "OU=Users,DC=company,DC=com"
Enabled = $true
}
New-ADUser @params
Way easier to read, way easier to modify later. If you're building scripts other people will maintain, this is basically mandatory.
6. Error Handling That Actually Tells You Something
Default PowerShell errors are sometimes helpful. Sometimes they're a cryptic wall of red text. Wrap critical commands in try/catch blocks and control what you see:
try {
Stop-Service -Name "NonExistentService" -ErrorAction Stop
}
catch {
Write-Host "Failed: $($_.Exception.Message)" -ForegroundColor Red
}
The key is -ErrorAction Stop — without it, the catch block won't fire on non-terminating errors. Burned me more than once early on.
7. Measure-Command — Know What's Slow
If your script is taking forever and you don't know why, wrap sections in Measure-Command:
Measure-Command { Get-ChildItem C:\Windows -Recurse }
It spits out the actual execution time. Great for comparing two approaches to the same task — like figuring out whether your filter-early strategy actually helped (spoiler: it almost always does).
8. Export Data Cleanly — Don't Just Dump Text
I've seen scripts that output results using Write-Host into a file by piping everything to Out-File. That's going to give you garbage someone has to parse later. Use structured exports:
Get-Process | Select-Object Name, CPU, WorkingSet | Export-Csv -Path "C:\Reports\processes.csv" -NoTypeInformation
-NoTypeInformation strips that annoying type header line from the CSV. If you're handing data to someone who'll open it in Excel, this is just basic courtesy at this point.
9. Insider Trick — $PSDefaultParameterValues
This one took me embarrassingly long to discover. You can set default parameter values for any cmdlet so you don't have to type them every time. Stick this in your profile:
$PSDefaultParameterValues = @{
'Export-Csv:NoTypeInformation' = $true
'Get-ADUser:Properties' = '*'
}
Now every time you run Export-Csv, it automatically skips the type info header. Every Get-ADUser pulls all properties. You can override these per-call whenever you need to. It's a tiny thing that silently saves a thousand keystrokes over a month.
10. Scheduled Tasks From PowerShell — Skip the GUI
Registering a scheduled task through the GUI takes like eight clicks and is weirdly confusing. From PowerShell:
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File C:\Scripts\cleanup.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At 3am
Register-ScheduledTask -TaskName "NightlyCleanup" -Action $action -Trigger $trigger -RunLevel Highest
Done. Scriptable, repeatable, and you can paste it into your documentation so someone else can recreate it in 10 seconds. That last part matters more than people realize when you're handing off systems.
One last insider tip — if you're new to writing longer automation scripts, enable Set-StrictMode -Version Latest at the top. It'll catch undefined variables and sloppy coding habits that work fine now but blow up on edge cases in production. Future you will be grateful.
Hope this saves you a few hours — or at least a weekend.
Related: PowerShell Tips and Tricks: Commands Every Developer Should Know
๋๊ธ
๋๊ธ ์ฐ๊ธฐ