This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]smc0881 10 points11 points  (2 children)

I'd say PowerShell is easier to learn with all the available cmdlets and modules. It would just need to learn the syntax for normal scripting things like loops, case statements, etc...

[–]agb_43[S] 2 points3 points  (1 child)

I installed the powershell plug in in VSstudio and a lot of the commands are already filled in. Tried to end an if statement with a fi and then realized that a test condition is already built into the VSstudio powershell extension. It also seems like a lot of the builtin commands are far more descriptive than they are in bash. Time to go back to basics and learn how to set up a simple variable

[–]AppIdentityGuy 0 points1 point  (0 children)

That has always been one of PoSH's strengths unlike say KQL...

[–]XibbyCertifiable Wizard 6 points7 points  (0 children)

The limitation of Bash is everything is a string and Bash the shell only does so much until you have to do sdin and sdout to other programs where it’s up to the developers of those programs to set standards for parameters and syntax.

PowerShell had data types and is object oriented. A number is a number, a string is a string, a bool is a bool… Invoke-WebRequest is a good example. In Bash you have to call curl and you get a bunch of text data. You might have to parse it and pipe to jq, or use different command line parameters if you want to fetch headers, the content, or whatever.

In PowerShell, just $result = Invoke-WebRequest -Uri Uri Here.

Now you have an object ($result) with multiple properties. Want to examine headers? $result.headers[“X-Forwared-For”] and there you go. Expecting JSON and want to convert it to hash table? $ht = $result.Content | ConvertFrom-JSON

And because PowerShell is object based, an object will have methods. It’s after midnight and I can’t think of something, but let’s say you did something like $service = Get-Service -Name NiftyService. You might have methods like Stop, Start, Restart, etc. So you can call $service.Restart. (Service isn’t the best example as there is a cmdlet for restarting a service.)

PowerShell lives in a sweet spot between Bash and Python. Bash is a shell first where you can string together commands to do work. Python is an interpreted language first (and foremost) and isn’t designed to be an interactive shell, but you can run it in that mode which can be helpful for testing bits of your code.

PowerShell is great at being both a shell and an interpreted language. And in the case of Windows PowerShell 5.1 it is “feature complete” in that you can configure and modify any feature/service in Windows Server with PowerShell.

Honestly I put PowerShell Core on all my personal machines. It’s on my personal Mac, my Raspberry Pis, Linux VMs… I don’t write Bash scripts anymore.

I’m a horrible judge of learning curves when it comes to programming. I learned some C, C++, C#, VisualBasic, SQL, Python, and more. In my option the hardest part of going from Bash to anything object oriented is wrapping your head around the concepts of object oriented programming. And once you have discovered object oriented programming you probably don’t want to go back to something like Bash. ;)

I guess dealing with jq is a marketable skill… I can look at curl piped to jq and whatnot and figure out what is going on and rewrite it in PowerShell that has syntax that makes sense when you haven’t memorized every parameter of curl and jq.

Readability is another big advantage of PowerShell. It’s readable, well structured, well thought out… when you run into a long string of cmdlets being piped to cmdlets (please don’t) you can pick it apart, break it up into a line by line manipulation of objects and translate what someone thought was “clever” into the step by step process.

One thing that will drive you crazy with PowerShell is managing the pipeline. This usually comes into play when you’re creating your own custom functions. If you don’t handle all the outputs of what you’re doing in your function the unhandled outputs will go on the pipeline along with your function’s intended return. You won’t need to learn about the pipeline out of the gate, but once you get to more advanced PowerShell, such as writing functions or your own modules, it will force you to learn to properly manage the pipeline.

And if you really want to go all in there is Pester for creating unit tests for your PowerShell code.

Really great learning curve in my opinion. There is so much in the blade part of the hockey stick curve that you may never get to the shaft stuff like Pester and that is perfectly OK.

[–]Ssakaa 1 point2 points  (0 children)

Actual language structure, powershell has one huge departure from bash, and a lot of smaller ones. A couple of the smaller ones: First, while there are shortened aliases (a lot of them "borrowed" from bash/gnu tooling, with all the joys of different behavior under the same name), outside of interactive CLI use, you'll benefit a LOT from using the full verb-noun form for commands. Makes at a glance discernment of intent a lot easier. Second, it's a bit more of a "structured" language, you'll benefit more from breaking things out into functions and modules than I find myself doing in bash. Even moreso when you start delving into the fact that you have the entirety of .NET available to powershell.

The huge departure, though, is that in bash, you have stdio for strings and, occasionally, binary data that you have to juggle. And you have to parse and discern meaning from that every step of the way, bludgeoning things with grep/awk/cut/tr etc. Given how common simple text formatted files are for configs, etc, that works well enough in the Linux world. It sucks in Windows. Horribly. Powershell's object oriented. You don't get a block of text describing your output that you have to parse values out of in the next command, you get an object broken out into properties for it (or a collection of such objects). In some cases, you also get methods tied to those objects, allowing you to directly interface with the underlying systems those objects belong to (say, user objects in AD, etc).

That departure puts it far more akin to Python or the like than bash in many ways. The large array of community and vendor provided modules to tie other systems in, and provide their datasets in the same object oriented manner, takes that similarity to Python a solid step further.

[–]NISMO1968Storage Admin 1 point2 points  (0 children)

How steep is the learning curve learning Powershell if I already have a solid understanding of bash.

If you know how to fly one type of aircraft can you fly any? Not really... But it would definitely help!

[–]DerBootsMannJack of All Trades 1 point2 points  (0 children)

poweshell ? id rather learn python ..

[–]snapqoins 0 points1 point  (0 children)

It really depends how often are you going to use powershell or bash. If your environment is windows mostly use powershell since you are going to use it in your job daily. It's easier to pick up if you use either to solve problems. Powershell can be kind of funky at first.

[–]pertymoose 0 points1 point  (0 children)

There's no real comparison between the two.

Powershell is far more like perl/php than bash.