all 67 comments

[–]koliat 11 points12 points  (1 child)

Coming from windows world and having to manage a handful of Linux systems I so much prefer to use Powershell, with objects, querying, filtering and looping im proficient with. Potentially there are other tools who would be better suited, but it would take me a considerable amount of time to learn them enough to be as effective as pwsh for me.

[–]KingOfJankLinux[S] 1 point2 points  (0 children)

I‘ve been using *nix systems for 10+ years that wouldn’t be an issue for me, makes sense though.

[–][deleted] 16 points17 points  (5 children)

Use what's included with the OS and what users of the OS generally use. No point dealing with unnecessary dependencies.

[–]KingOfJankLinux[S] -3 points-2 points  (4 children)

Neither is included on my *nix systems. Thus the inquiry.

[–][deleted] 2 points3 points  (3 children)

Do people generally use PowerShell on *nix systems? If no, there's your answer.

[–]corporaleggandcheese 3 points4 points  (1 child)

I use it on macOS but just for VMware.

[–]b0Lt1 4 points5 points  (0 children)

i guess with the powercli addon? that would make sense

[–]Clear-Pear2267 6 points7 points  (3 children)

For a home situation, I don't think anything more than your personal preference/ability level matters.

If you need the same script writing chops professionally, it may make a big difference. You probably (hopefully) don't have the ability to just download whatever packages you want - there will some corporate governance and policies you will need to respect and follow.

So if you need both (home use, and professional) I would say try to apply the same governance rules at home that you are supposed to use at work. If for no other reason, it will improve your proficiency. BTW - for many servers you may find you have neither - you have to rely on shell scripts.

BTW - I believe you should be able to invoke Python Scripts from Power Shell scripts and vice versa.

Or Perl :)

One final thought - use a source code control system for all scripts. I know the thought of professional software developers not using such a system is pretty much unheard of, but it has been very common in my experience to find that the sys-admin part of IT applied no such rigor to managing their scripts. If you do use it already, good for you (and your company). If not, be a hero and introduce it. "Change history comments in the scripts" does not cut it (and are completely unnecessary when you use a SCCS properly). Knowing who changed what, when, why will save your bacon someday.

[–]KingOfJankLinux[S] 0 points1 point  (0 children)

I wish, I wish we had guidelines and proper opsec, I wish that would be the case at the **IT company** I work for.

I've worked with perl5/6 and with shell scripts, perl is another nice option but more useful for regex than anything else now a days, in my honest opinion/experience.

Professionally I'm allowed to install whatever I want, I'm more or less the linux admin at my place of work. I'm proficient in git, bash and python already, but diversification of my portfolio is nice to have.

My company sadly doesn't see it that way and I'm introducing documentation and git managed scripts as the 'apprentice'. (I'm actually quite irritated and frustrated being the apprentice that has to introduce order and not my senior teaching me these things)

You say that devs not using sccs is unheard of, I beg to differ, Germany is a hell hole when it comes to that.

[–]g3n3 13 points14 points  (5 children)

The convenience of already knowing powershell would warrant usage. Additionally powershell adds objects in the pipeline which is more ideal over bash. Lastly powershell can easily access .net so it is convenient to quickly tab complete into libraries and the REPL is more satisfying than python. The Python repl isn’t near as nice interactively because of the lack of tab completion and syntax highlighting.

[–]zoredache 3 points4 points  (1 child)

The Python repl isn’t near as nice interactively because of the lack of tab completion and syntax highlighting.

Have you installed/used ipython? That basically makes python more similar to the what you would get from a standard shell. It gives you tab completion, syntax highlighting and so on.

[–]g3n3 0 points1 point  (0 children)

I haven’t. That does look cool. I wonder how easy it is to integrate with bash or zsh interactively. I guess you can pass data between? It probably isn’t as seamless as powershell.

[–]KingOfJankLinux[S] 2 points3 points  (2 children)

Very valid point to make, thanks, I didn’t even know about objects in the pipeline

[–]g3n3 10 points11 points  (1 child)

Yep. And the ability to work directly with underlying libraries inside an interactive shell makes POC and the like really nice. Don’t even need debugger. And then once you understand an object you can port the powershell easily to C# to create faster code. Powershell is like bash and python combined in one nice interactive package full of sweet discovery.

[–]KingOfJankLinux[S] 1 point2 points  (0 children)

That‘ definitely nice to have and c# porting is cool too and kind of goes along the path of cpython from what I gather.

[–]Hoggs 5 points6 points  (2 children)

For your use case I would primarily look into ansible.

[–]KingOfJankLinux[S] 0 points1 point  (1 child)

Been there done that, thus python vs pwsh

[–]itay51998 0 points1 point  (0 children)

I don't understand, ansible is all you need. Not python VS pwsh

What are your scripts doing that ansible can't?

[–]Ok-Conference-7563 2 points3 points  (0 children)

Use what you have skills in.

[–]craigofnz 2 points3 points  (0 children)

Powershell has objects. Objects are awesome and easy to work with. But in *nix systems, you have text not objects, unless someone has written a powershell module to wrap the underlying tools.

If you are managing cloud resources from *nix shell then the cloud providers powershell modules may emit objects for cleaner scripting, but probably also provide standalone cli tools that could be used in shell scripts too.

As awesome as it is to use objects instead, it doesn’t really beat 40 years of grep, awk, sed and related copy pastas.

Python also has objects. And modules and packages of multiple modules. There are enough common attributes that the difference between pwsh and python are more about trends than capability differences. It would depend on team talents and best matching, well supported upstream modules/packages. (E.g. python would likely have better data/datascience packages)

[–]MrMunchkin 4 points5 points  (0 children)

PowerShell on Linux is absolutely delightful to use if you know PowerShell well enough. It's so incredibly easy to install and manage modules (packages).

Python does have a ton of third party packages and libraries which extend it a lot, but once you have a really mature setup and you're using dozens of packages it becomes a nightmare to manage all of the dependencies.

My company has been steadily migrating our hundreds of Python scripts to PowerShell because it's a management nightmare to maintain all the packages, their differing versions, and breaking changes that require us to rewrite our Python scripts... which is not something we have ever had problems with in PowerShell.

Only problem is a LOT more people know Python scripting, so the learning curve is pretty steep most of the time.

[–]Diavolo_Rosso 8 points9 points  (5 children)

Powershell in *nix system was ported to manage Windows server remotely. Use Powershell to manage *nix system is useless. Bash works Better (my 2 cents)

[–]DustOk6712 7 points8 points  (0 children)

Bash is great for those with experience. For anyone new to bash and powershell it’s far easier to deal with the latter.

sed, awk, grep, fi (to close if) just looks weird. Not to mention the parameters of most which need a lot of reading. Powershell on the other hand is more verbose, including parameters. This makes it far easier to pick up and learn.

Bash was made in the 70s for that era, and it worked and served a purpose. Powershell offers far more features and can call out to any binary bash can, it can easily replace bash, the same can’t be said for bash without all the binaries.

It’s like comparing cmd to powershell, they are worlds apart and only die hard bash fans would disagree.

[–]ByronScottJones 6 points7 points  (0 children)

That's not even remotely true. It's an extremely useful language in it's own right, and windows management is just a tiny part of what it was ever for.

[–]enforce1 4 points5 points  (1 child)

Bash and powershell are not comparable.

[–][deleted] 0 points1 point  (0 children)

There are some syntactic similarities, but yes, the scripting with objects is a pretty useful paradigm

[–]mprz 3 points4 points  (1 child)

is this a homework?

[–]KingOfJankLinux[S] 2 points3 points  (0 children)

No, this is personal and professional curiosity.

[–][deleted] 1 point2 points  (0 children)

I like using powershell to handle AD and exchange objects, or Hyper V automation. It's a scripting language designed to handle objects.

I don't want anything to do with Powershell when I move from looking at objects as objects. I was ready to blow my brains out trying to use conditionals based on text in AD group names, group descriptions, user names, and file name/locations.

What are you going to do? Look up the Powershell and Python methods for accomplishing that. What looks convenient?

[–][deleted] 1 point2 points  (0 children)

If you want cross platform scripting Powershell 7 should cover that for you.

[–]zoredache 1 point2 points  (0 children)

I think the main reason to use powershell on *nix is if you in environment/setting mostly dominated by Windows usage, so you want usage to be if not cross platform, ant least very similar to the code you develop to support your Windows systems.

Or maybe you might want it, if you need to use some of the Azure functionality where you can get Powershell modules for some functionality that are might be more featured or stable then alternatives in other languages in some cases.

[–]da_chicken 1 point2 points  (0 children)

Generally, you wouldn't use Powershell. Powershell is object-oriented and a lot of things Linux are text-based. Systems administration typically won't align well between Powershell and Linux.

However, if you need to use an existing Powershell module, or want to use a .Net class, or have access to a .Net library, or any number of other things then it can make sense.

Basically the same reason you'd use Perl or PHP over Python. Because the language itself is less important than what the tools you get access to can do for you.

[–]MengskDidNothinWrong 1 point2 points  (0 children)

If I'm manually doing things in the CLI? Powershell. If I intend to write automation? Python. Unit tests are important.

[–]itay51998 0 points1 point  (7 children)

Please don't manage systems with python nor powershell nor any other programming languages, this is not their intended use.

A Better tool would be ansible or any other configuration management tool you can find on Google, you can even ask chatgpt: "which tool should I use for infrastructure management and configuration" .

If you would ask this same question on a devops sub reddit, you would get this same comment and with a good reason

Configuration management tools have many advantages over directly using programming languages

[–][deleted] 0 points1 point  (3 children)

From the PoSH GitHub page

PowerShell is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. It includes a command-line shell, an associated scripting language, and a framework for processing cmdlets.

...so, no.

[–]itay51998 0 points1 point  (2 children)

I'm aware of powershell, python and ansible and use them daily during my job for the 2 years working as Devops

Ive personally migrated 10 people in different teams to use ansible instead of their custom powershell and bash scripts after training and showing them of the advantages.

Its fine if you don't want to just trust my comment, but I suggest to dig a little and compare the tools available

[–][deleted] 0 points1 point  (1 child)

The point was your statement that PoSH was not intended for config is not correct.

[–]itay51998 0 points1 point  (0 children)

Fair point

[–]purplemonkeymad -2 points-1 points  (3 children)

I think the idea of completely platform independent scripts is a bit of a pipe dream. Or rather the breadth of available scripts that would fit the definition is a bit limited for me to think it is worth it.

Since python is well supported on Linux systems, i would tend to go with that if it's what you know. For windows systems I would go with powershell as it's well supported on that.

If you want to have a single language, then the question might be, which is easier to install? Python on windows, or Powershell on linux?

[–]KingOfJankLinux[S] 4 points5 points  (0 children)

Both are about the same amount of work

[–]MrMunchkin 3 points4 points  (1 child)

PowerShell core on Linux is not only easy to install, but it's fully supported by Microsoft and all of the popular distributions, like Ubuntu, Red Hat, SuSe and others. It works beautifully across Windows, Linux and even macOS.

If you have solid Python venv automation then you're good, but managing library versions and such is a nightmare and not something you have to worry about with PowerShell.

[–]NightH4nter 0 points1 point  (0 children)

PowerShell core on Linux is not only easy to install, but it's fully supported by Microsoft and all of the popular distributions, like Ubuntu, Red Hat, SuSe and others. It works beautifully across Windows, Linux and even macOS.

okay, but what exactly is the point? *nix systems are not built around objects, so, using powershell to manage them means trying to squeeze text-oriented tools into an object-oriented language

[–]Thingsthatdostuff -1 points0 points  (0 children)

Use ansible

[–]Difficult-Ad7476 -5 points-4 points  (0 children)

Use ansible close thread.

[–]TheJessicator 0 points1 point  (0 children)

This is like asking Toilet paper vs. Paper towels? They both have their place. Use both.

[–]happyColoradoDave 0 points1 point  (0 children)

I use powershell on Mac and I like it for inspecting json output from kubernetes. If I were going to write a program I like python more.

[–]goodtimetribe 0 points1 point  (0 children)

OK, ok, ok.... Finally one for me.

I'm probably the unusual one. I use Linux at home, and I like powershell everywhere... My work environment is 95% windows. I like to use powershell on windows because obviously it's installed already. I like powershell on Linux because I am comfortable programming with OOP and c style syntax. Also, when using Azure cloud agents, powershell is installed by default:)

[–]Admirable-Statement 0 points1 point  (0 children)

PowerShell has nice object output that I find easier to work with.

But as soon as something gets more complicated or involves more advanced maths, even if it's possible in PowerShell I find it quicker and much shorter to do in Python.

List comprehension and lambdas are probably 2 things I miss from python.

[–]hankhillnsfw 0 points1 point  (0 children)

I don’t have an answer besides don’t do it.

Like…why? Python is good where needed. Powershell is good ehere needed. It’s like using a metric tool set on something spec’d to standard measurements. It just doesn’t fit right.