Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Do you prefer Powershell?
8 points by nodra on Jan 20, 2023 | hide | past | favorite | 10 comments
I’ve used it here and there throughout the years for small tasks and didn’t think much of it. The last 2 weeks, I’ve been using it more cause I have to do some work on a Windows VM and it’s nice! I’ll go back to bash after I’m done with this work cause that’s what everyone uses. I wouldn’t mind the switch though.

I know bash is the standard but does anyone opt for powershell even on a Linux vm?




It works when it works but when it doesn't it is a pain.

I recently was looking at doing some backup software in Powershell for Windows 10 and 11. My chosen method was to use a VHDX file (Windows backup does this). Now in powershell there are commands to create a VHD or VHDX file but they are tied to the Hyper-V package in Windows being installed. In Windows 11 this package has been totally removed and can no longer be downloaded or installed.

So next I tried to find another way to use VHDX files in Windows 11 from Powershell. So I discovered that the diskpart command line utility can create/attach/partition etc VHDX files. Diskpart however is not integrated into powershell. In order to use it you need to create a text file with the commands to run. Execute diskpart with that text file. Then you have to search the text output for the results.

At this point I felt like I should have been using a Unix shell anyway.


This is a strange rant. It has zero things to do with Powershell.


I am having to learn it to write some scripts for a customer who insists on using Windows. It’s very neat. I’m especially impressed with the ability to create GUIs. [1]

Coming from bash the language is awkward. I would like to spend some time learning it more and running it on my main macOS machine.

[1] https://lazyadmin.nl/powershell/powershell-gui-howto-get-sta...


I had no ideas about the GUIs. Thanks so much for the link. Makes me want to use it even more.


I use pwsh on all platforms. All automation is done with it, and in many cases web app functionality depends on it running in background all the time (for large public services).

Even our GitLab runner uses pwsh.

To organizse build/scripts we use Invoke-Build, a cross-platform task runner: https://github.com/nightroman/Invoke-Build


It's pretty nice. I've made my small career so far out of being pretty at home in both *nix and Windows environments, and I prefer PoSH to bash mostly because it feels more like a really terse programming language than a shell. I also find that after I run it through `Edit-DTWBeautify` or the like, and all the aliases get deanonymized, it's one of the easiest scripting languages for me to return to and understand just by reading it.

There is a bit of a painful paradigm shift, though, where you have to stop thinking in terms of text streams and more in terms of shuttling objects with properties around. It's not a great idea to try to work with PowerShell exactly the same way you might construct a pipeline around `awk` and `grep`, because text streams just aren't the real primitive in this environment. For that reason I think it usually makes sense to just a stick with whichever shell environment you grew up with, unless work or something forces your hand.


Disclaimer: I'm inexperienced with bash and powershell.

I just converted a bash script to a powershell script. Some things are a lot easier (like writing errors or info messages in different colors). But I had a lot of problems getting the exit codes from maven calls to determine the exit result. Checking for 0 in shell works fine all the time, in powershell checking $LASTERRORCODE works sometimes but not always. I'm using try catch now but it's a bit of a hassle (which is ironic, comic from a java developer).


$LASTERRORCODE is not the same as $?

It works only on native executable errors. Some executables like git also write logs on error stream (this is a problem on linux too).


I like it for scripting shell but not for daily interactive shell.


I love it and use it almost every day.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: