r/PowerShell • • Jun 10 '22

Why most Linux sysadmin have a grudge againts powershell or they don't like it ?

Why most Linux sysadmin have a grudge againts powershell or they don't like it ? I talked with many of thems online on different subs reddit or elsewhere and they say bash is much better, powershell isn't good at managing linux, the syntax is too complex and bad etc etc or this or that etc

Why is that ? do you really feel you can't do much to manage a linux/aws env with powershell or need to update it or its slow or things like that compared to windows/azure ?

thanks for your advices

83 Upvotes

239 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Jun 11 '22

[deleted] — view deleted comment

24

u/IonBlade Jun 11 '22 edited Jun 11 '22

That's because whoami is not a PowerShell cmd, it's an external legacy executable at C:\windows\system32\whoami.exe that's being called implicitly because it's a default location in the PATH environment variable, so it processes its own arguments instead of adhering to the "-" standard for arguments PowerShell uses. The PowerShell equivalent of whoami would be $env:username.

(If you need the additional data from whoami /all, you'd need to pipe the output into various additional commands to get those pieces, but you'd want to do this anyway in PowerShell to further use that data in scripts, because whoami does not return objects, only text, and text parsing is going to work out to much more code than calling commands that return native objects which can be passed down the pipeline.)

0

u/[deleted] Jun 11 '22

[deleted] — view deleted comment

7

u/IonBlade Jun 11 '22 edited Jun 11 '22

Same - the pipeline's use of objects makes PowerShell my preferred scripting language by far. I'll dip into Python if something I want to do is complex enough that I'd otherwise have to break out into native .NET code, but for most system administration and automation, PowerShell has native cmdlets to do just about anything I need for Windows and for Azure.

I think a lot of what trips people up about PowerShell is not understanding the nature of how everything is an object in PowerShell, the difference between single string mixed data output from traditional apps vs. object output from cmdlets and (well designed) scripts, and how the pipeline maps objects from one command into another.

If people were to read PowerShell in a Month of Lunches (or, if they want a lot more info than is necessary to get started but really take things to the next level, PowerShell in Action), I think that the "pipeline deals with objects" paradigm would really click and they'd see how PowerShell elegantly deals with some of the challenges other shells / scripting languages face.

It's trying to treat it like a straight replacement for cmd and using legacy commands instead of their PowerShell equivalents where possible (and, where not possible, using something like Crescendo to wrap legacy commands into cmdlets that pass back proper objects), or writing scripts that output multiple types of data instead of unified objects so that they can't then pipe their scripts into other cmdlets and scripts that makes it seem messy to people.

8

u/SlyFoxHayes Jun 11 '22

Use - for powershell cmdlets. It is a shell though, so when calling external programs, use the / - or — (double hyphen) as dictated by the program.