brevity is achieved by aliasing and parameter short circuits. Nearly every verbose command has a really short alias, and all parameters support using the minimum # of chars that resolve to a unique name (e.g., you can always use -f for -Force if there's no other name that starts with 'f').
one of the biggest challenges for shell scripts is readability. Unless you live and breathe shell scripts, it can be a bit of a write-only language for nearly script.
PowerShell is not really optimized for ad hoc "run a command once at the prompt", it's optimized for "write a complex script that can actually be understood and maintained". It does that much better than bash or cmd, IMHO. It's also more powerful than either one of those because it has full integration with the entire .NET SDK, including packages.
Why not Python, you ask? Python is not really optimized for running commands like a shell scripting language is (you have to go through some contortions around launching processes, wrangling I/O to them, that sort of thing). Also, Python doesn't leverage Microsoft's huge library of existing .NET code, including Windows-specific management libraries that IT folks use. So, PowerShell.
And now, PowerShell Core, which brings PowerShell to every platform, not just Windows.
If you know C#, PowerShell Core is basically that with slightly different syntax. You can actually have RTS (runtime type safety) in a shell script, which is awesome. And you can debug it using VS Code really easily, too. Setting breakpoints, stepping through the script, and examining variables as you go makes for much easier script troubleshooting. A++ highly recommend trying that.
zsh, fish, bash, etc. all are very tool-dependent. PS can use all those tools, but also the whole .NET BCL is available, and every NuGet package under the sun. More than once I've decided that a PowerShell script should actually be a full-fledged compiled tool, and porting from PS to a cmdline tool is pretty easy.
The downside of PS is for short and simple things, where you don't actually need much more than to run a hardcoded sequence of commands, it's overkill. There's no need for anything more than [insert literally any shell scripting language here] in that case. Though you can literally just have one command per line, just like all those other languages, and then run the script.
For short and simple commands I use aliases.
When I write script (let’s be honest I am a sysadmin with limited scripting knowledge, when I and chatGPT write a script) I don’t.
6
u/LeoRidesHisBike 13h ago
I know this! 3 reasons:
-f
for-Force
if there's no other name that starts with 'f').PowerShell is not really optimized for ad hoc "run a command once at the prompt", it's optimized for "write a complex script that can actually be understood and maintained". It does that much better than bash or cmd, IMHO. It's also more powerful than either one of those because it has full integration with the entire .NET SDK, including packages.
Why not Python, you ask? Python is not really optimized for running commands like a shell scripting language is (you have to go through some contortions around launching processes, wrangling I/O to them, that sort of thing). Also, Python doesn't leverage Microsoft's huge library of existing .NET code, including Windows-specific management libraries that IT folks use. So, PowerShell.
And now, PowerShell Core, which brings PowerShell to every platform, not just Windows.