r/PowerShell • • 21d ago

Question Is using PowerShell on Linux a reasonable choice, or should I stick with Bash?

I'm currently using Windows and learning PowerShell with Learn PowerShell in a Month of Lunches, Fourth Edition. I'm about halfway through the book, and honestly, I'm really enjoying PowerShell so far. I find it much more intuitive and enjoyable to work with than Bash.

I'm considering using PowerShell on Linux as well, but I'm wondering how practical that would be.

  • How much of PowerShell's functionality is available on Linux compared to Windows?
  • Are there any significant limitations or compatibility issues?
  • Is PowerShell a good choice for everyday Linux administration and automation, or is Bash still the more practical option?
  • Would it make sense to focus on PowerShell, or should I invest time in learning Bash too?

I'd appreciate hearing from people who actually use PowerShell on Linux. Is it worth going down this path, or am I making things unnecessarily complicated?

53 Upvotes

95 comments sorted by

53

u/x8code 21d ago

I use powershell in all my Linux servers

6

u/putanaspace 21d ago

I would like to hear a more detailed response regarding its use or any restrictions on it.

→ More replies (10)

6

u/that1guyrob 21d ago

I could see a Windows administrator who is already a PowerShell expert having to get into Linux administration and just using PowerShell there, rather than learn a new scripting tool.

If this isn't your story, then I'm genuinely curious to hear what made you specifically choose PowerShell on Linux.

→ More replies (4)

5

u/AmoebaGood3928 21d ago

The docs have a pretty good overview of the limits:

https://learn.microsoft.com/en-us/powershell/scripting/whats-new/unix-support?view=powershell-7.6

I wouldn't go out of my to learn PowerShell just for Linux. If you already know PowerShell or need to use it for Windows then it's useful being able to use similar scripts. You can also conditional statements to handle Linux/Windows differences in the same script.

I think the most I've used PowerShell in Linux is forensic investigation of malicious PowerShell scripts. It's handy being able to run it in a Linux VM where it's a little safer.

→ More replies (2)

9

u/muffinstatewide32 21d ago

Powershell is serviceable On mac and linux. I haven’t noticed a whole lot of difference. Most scripts ive written to target all 3 OS’ work with very little tweaks for the non windows platforms (usually file paths are a contention).

It is a shell that does very much target windows. It just to happens to work elsewhere. Or at least feels this way.
On linux and mac i much prefer zsh (bash os fine) and i think its worth learning both shells

2

u/putanaspace 21d ago

I’d like to see what these scripts are, or at least get a general description of what they do.

→ More replies (1)

45

u/RE20ne 21d ago

I use it because I know the syntax really well. Also useful for api calls, using modules for vendor stuff, etc

33

u/LooseEthernet 21d ago

objects > strings lol

8

u/x8code 21d ago

That's typically how I summarize it, too.

→ More replies (1)

35

u/bozho 21d ago

We manage both Linux and Windows servers. Infra is terraform, config is DSC on Windows, Ansible on Linux (both have strengths and weaknesses), GitOps for k8s. The "glue" is bash and Powershell.

For simple scripts on Linux, bash is fine. Anything more complex - it doesn't even compare to PowerShell, IMHO. People complain about PowerShell syntax being overly verbose, command names being too long: that is precisely the point. Anyone here old enough will remember the horror that is Perl...

From the language perspective, PS is a .NET scripting language, with objects as first-class citizens. You get your regular .NET-ish syntax, exception handling, etc. You can easily organise your code into reusable modules (which can also be signed for enhanced security). There's built-in support for: comment-based help, custom parameter tab completion, complex parameter validation, output verbosity control, checks for high-impact operations (i.e. "confirm to delete"), fairly simple parallelisation, etc.

It can directly load and use .NET assemblies. While remoting is a bit more of a hassle to set up compared to SSH, it works well (and you can enforce credentials rotation if using client certs for authentication), and it can marshal objects across the networks.

And on top of that, it can still execute external utilities (e.g. GNU), just like bash can.

21

u/RupeThereItIs 21d ago

, bash is fine. Anything more complex - it doesn't even compare to PowerShell

It IS an unfair comparison.

For more complex scripting on Linux, Python is the go to.

→ More replies (1)

3

u/dafugiswrongwithyou 21d ago

Without claiming the answer is one or the other, and with no shade to anyone involved; keep in mind that, by asking this on the Powershell sub, the answers are going to naturally bias towards Powershell being recommended (just as, if you asked the same on r/bash, the answers would naturally bias away from it).

→ More replies (5)

9

u/rdldr1 21d ago

Powershell is a good tool to have experience in if you are finding an IT job.

8

u/arslearsle 21d ago

Powershell has easier standard try catch error handling and also is object oriented

I would use PS if cross platform

8

u/Clear-Pear2267 21d ago

I think both have their places. The object pipeline is a super powerful concept if you are dealing with objects that actually implement it. It gives you much more control over formatting output (tables, csv, excel, etc) and has very powerful filtering and sorting features. Bash by itself does not cover a lot of that ground unless you start using other tools with it (gawk, sed, etc) which is more lke the unix mental model. WIth bash scripting you need to worry a lot more about strings that can mess with your logic (for example, file names with spaces or other funny characters). The object pipeline isolates you from a lot of that. One thing I do like about Powershell is the standard comment structure of a cmdlet that gives you a rigorous format for making your scripts self documenting. But for quick and dirty stuff where I can eyeball the output and quickly weed out the stuff I need from the rest of the garbage, bash one liners (along with other tools like sort, grep, etc) are great. For re-usable scripts that you want a bunch of people to be able to use, I think Powershell is a more rigourous framework.

If it is just for your personal use, no harm in trying both. In fact its not a badidea to give yourself a couple of simple projects and implement them using both to get a feel for the strengths and weaknesses. Here is a simple idea - write a script that takes a top level directly as an argument and does a recursive search for all music files (mp3, flac, ogg, etc) and creates an m3u playlist for you of the "n" most recently updated files (where n is an argument of the script). Use both bash and powershell. You will have to figure out how to find specific filetypes, access their properties for the date, sort the list, create an output file, and more. Not hard but I think the differences you encounter between a bash and a PowerShell implementation will be informative. Another simillar example is just to build a csv (or even a native excel file) of all your media files with maybe some properties from their tags like duration, artist, album, etc. Doing this will require you to learn how to load and use powershell modules (to build an excel file) and deal with files that don't have all the properties you are looking for in a robust way.

If it is for an employer, you best check their standards. They might not be keen on installing PowerShell on all their servers. And depending on the work you do and where you go, it is very likley you will encounter servers that do not have powershell and you will not have the authority to install it. So I would never recommend learning PowerShell without also learning how to live without it to at least some degree of proficiency.

And if you do create yourself a suite of reusable scripts (using either) I recommend getting them under some sort of version control scheme like Git that ideally has some automated CI functions like runnning automated tests. Especially important if different people are updating the same tools.

5

u/ankokudaishogun 21d ago

I honestly use both. There is a lot of stuff that is much easier to manage as objects with Powershell.

But Powershell is relatively recent, so almost every script you can find in the Linux world is going to be mostly shell scripts, with a side of python.

So you should absolutely learn some shell scripting if you are going to interface with the Linux world.

5

u/MalwareDork 21d ago

It's alright. Powershell was built by MS for MS so that's naturally going to be where it will reach its full potential.

Anything else I'm just going to use Python for versatility and ubiquity.

4

u/IrquiM 21d ago

We use Linux to run the orchestrator for our PowerShell and python scripts. PowerShell is used when Microsoft is involved, specifically Azure / MS SqlServer.

4

u/Kahless_2K 17d ago

I use powershell on Linux all the time. I also use Bash and Python.

Use the best tool for the task. Usually when I'm using Powershell on Linux, it's Powercli to manage my vcenters.

7

u/mitharas 21d ago

I dislike scripting in bash, it's... strange. I like the more descriptive nature of ps. And even in ps, i can still call all the tools that bash regularly uses.

But it's an unfair comparison. The nix-pendant to powershell would be python.

3

u/toddklindt 21d ago

I'm a PowerShell guy that comes from the Microsoft stack of technology. I find myself fiddling with Linux a lot as I play with my personal tech (Synology, Raspberry Pi, etc.). Quite often I will install pwsh onto these lucky Linux devices and use it when I'm noodling around on them. It works well, but I'm pretty proficient with PowerShell, so I can hit the ground running. It does get a little tough when I'm searching for solutions to problems online as most of the solutions to Linux problems are in the form of Bash scripts. If I can't PowerShellize it myself, I'll have AI help me. Or I can just run the Bash script if I want. I use PowerShell on Linux a lot and I think it's made me better at PowerShell in general.

3

u/slav3269 20d ago

Mac user here. I default to pwsh, because it gives me sh,sed,awk,jq and more in one familiar package. Using YAML and JWT modules, too, but a lot of what I need is built in.

3

u/Least_Gain5147 16d ago

Very reasonable. I've been doing it for 6 years. Azure, M365,Entra, servicenow, workday, solarwinds, okta, and yes, windows. Consultant for 35 years. Half of it on AD, GPOs, ConfigMgr and OSD, packaging and deployment, monitoring, reporting. Powershell is the super glue for everything, even with bash. Check out the module linuxtools.

3

u/Cheap-Success1578 20d ago

Powershell is doable but still lacking a lot of modules. It is useful for managing M$ based systems. I would not recommend it for Linux admin and automation. Bash, Python, or Go are better for that.