back to article PowerShell comes to MacOS and Linux. Oh and Windows too

Microsoft has given the world new versions of PowerShell that bring the popular automation and scripting tool to MacOS and Linux. PowerShell Core 6.0’s both an upgrade and a replacement for its predecessors. It’s a replacement because Microsoft is no longer actively developing its predecessor, “Windows PowerShell”. That tool …

Silver badge
Windows

PowerShell?

If God had meant us to use PowerShell, He'd never have given us bash (Apologies to Flanders and Swann) - Having used both, I think I will continue to use a *NIX shell, thank you.

82
14
JLV
Silver badge

Re: PowerShell?

upvoted, but it's a bit more nuanced than that.

PS is extremely good at piping precise object streams from one process to another. For example, I know bash has stuff like pgrep or pkill, but you can see people recommending jumping hoops to pipe ps into grep and then parse out all the fields you don't want to get at the pid.

PS needs none of that. Each step can feed exactly what's needed to the next and you have tons of filters/qualifiers to get exactly what you want.

If you're in the biz of programmatically configuring systems, I think PS has the edge. You don't have to faff as much with cut/awk/grep on a text stream, you have an object stream instead. I think it's a bit like the power use you see with 'find' doing things through xargs - any pretense that it's simple goes right out the window at that point in bash. PS is like that from the start, seems like.

Unfortunately, the number of options and qualifiers is massive and makes casual use of PS shell from the command line really unobvious for casual users, like me.

ls -t => get-childitem | sort -property LastWriteTime

ls | grep foo => get-childitem | Out-String -Stream | select-string -Pattern foo

(the above is not a good way to look for *foo* files, but it shows how hard simple grep use can be. aliasing it to 'gci' or 'ls' doesn't fundamentally improve things...)

Bash seems good to power users and admins alike. PS seems to really reward admins or ultra-power users because the learning curve is massive. Give me 3 weeks on it and I kinda get its basic usage. 3 weeks off, forgotten most of it again. Still better than cmd.exe though!

That's my take, but I'd be happy to hear from people who've used both bash and PS in anger.

A system that would support both paradigms would be awesome, but failing that I'll take bash over PS for my use cases. Even better would a system that mixed both. Still, hats off to MS here, they've been opening up quite a bit at the system level these last few years, much as I rag on Windows itself.

49
9

Re: PowerShell?

> ls | grep foo => get-childitem | Out-String -Stream | select-string -Pattern foo

Command line, so use aliases, and it is much simpler than that:

dir | ? name -match foo

12
2
JLV
Silver badge

Re: PowerShell?

? is an alias for select-string here? sorry, I'd rather stick to the whole enchilada, these aliases are confusing me, if reference docs talk about select-string, sls or ? just add another layer of confusion, IMHO.

the point I was trying to make is that you can't just "wing it" with a grep, you need to know your upstream object. if my ls wasn't just a plain ls, but an ls -l and if I wanted to find foo anywhere in its output, I'd have to cast the whole thing to a string because select-string wants strings and it's not getting them.

8
2
LDS
Silver badge
Devil

Sorry, both are products of the Devil itself.

Only a very evil being could inspire the syntax used in those shells and their scripts.

22
1

Re: PowerShell?

I believe "ls | grep foo" could be accomplished using "ls | findstr foo" in Powershell :-)

7
0
Silver badge
Mushroom

Re: PowerShell?

Powershell is far superior to Bash and I call BULLSHIT on your suggestion that Bash is superior. The only problem with Powershell is a GNU/Linux environment is that GNU/Linux is not an Object Orientated environment whereas from top to bottom Windows is. Therefore Powershell can use it's far more advanced capabilities whereas on GNU/Linux it's stuck using the same kludgy approaches as Bash.

You claim to have used both. Well I have to. Here's a short list of some of the things I can do in Powershell that I can't do in Bash. Oh - and syntactically it's more consistent and intelligent, too.

1) Object oriented pipes so that I don't have to format and reparse and be concerned about language settings.

2) Command metadata. PowerShell commands, functions and even *script files* expose metadata about the names, positions, types and validation rules for parameters, allowing the *shell* to perform type coercion, allowing the *shell* to explain the parameters/syntax, allowing the *shell* to support both tab completion and auto-suggestions with no need for external and cumbersome completion definitions.

3) Robust risk management. Look up common parameters -WhatIf, -Confirm, -Force and consider how they are supported by ambient values in scripts you author yourself.

4) Multiple location types and -providers. Even a SQL Server appears as a navigable file system. Want to work with a certain database? Just switch to the sqlserver: drive and navigate to the server/database and start selecting, creating tables etc.

5) Fan-out remoting. Execute the same script transparently and *robustly* on multiple servers and consolidate the results back on the controlling console. Try icm host1,host2,host3 {ps} and watch how you get consolidated, object-oriented process descriptions from multiple servers.

6) Workflow scripting. PowerShell scripts can (since v3) be defined as workflows which are suspendable, resumable and which can pick up and continue even across system restarts.

7) Parallel scripting. No, not just starting multiple processes, but having the actual *script* branch out and run massively parallel.

8) True remote sessions where you don't step into and out of remote sessions but actually controls any number of remote sessions from the outside.

9) PowerShell web access. You can now set up a IIS with PWA as a gateway. This gives you a firewall-friendly remote command line in any standards compliant browser.

10) Superior security features, e.g. script signing, memory encryption, proper multi-mode credentials allowing script to be agnostic about authentication schemes which may go way beyond stupid username+password and use smart cards, tokens, OTPs etc.

11) Transaction support right in the shell. Script actions can join any resource manager such as SQL server, registry, message queues in a single atomic transaction. Do that in bash?

12) Strongly typed stripting, extensive data types, e.g first class xml support and regex support right in the shell. Optional static/explicit typing. Real lambdas (script blocks) instead of stupidly relying on dangerous and error prone "eval" functions.

13) Real *structured* exception handling as an alternative to outdated traps (which PowerShell also has). try-catch-finally blocks.

14) Instrumentation, extensive tracing, transcript and *source level* debugging of scripts.

15) Consistent naming conventions covering verb-noun command names, common verbs, common parameter names.

28
44
Anonymous Coward

" from top to bottom Windows is"

No. Windows is still mostly a C API, which is not object oriented. It also has some C++ and COM APIs, which are object oriented, but which are not .NET objects. Powershell requires its wrappers over all of them.

And frankly, I'd prefer to call a COM API than a .NET one. It doesn't require a specific VM, a JIT, and a framework just to call a function - and you can call it from many more languages and scripts.

28
7
Anonymous Coward

Re: PowerShell?

>> If God had meant us to use PowerShell, He'd never have given us bash

You realise that Powershell is way more powerful, capable and secure than Bash? There was a long long list of advantages previously posted here.

15
35
Silver badge

Re: PowerShell?

"Powershell is far superior to Bash"

Quite. I seem to recognise that list from somewhere...

10
4

Re: PowerShell?

Wow, impressive capabilities, I wish I knew how to use it while being very glad that I don't.

Having done some extensive <command> | <awk|sed|grep> ..., I wished all the time for something that *knew* what was coming.

Not surprisingly, xargs is my favourite bash mechanism.

17
1
Silver badge

Re: " from top to bottom Windows is"

"No. Windows is still mostly a C API"

Some of it, yes, but not mostly.

"which is not object oriented"

You are not understanding how this works. Windows from top to bottom can pass data as objects via it's management interfaces - what the underlying APIs use doesn't matter.

"Powershell requires its wrappers over all of them."

No, it doesn't. You might need a Powershell wrapper to say access a specific database as an object but the Windows OS access is baked in.

"And frankly, I'd prefer to call a COM API than a .NET one."

You don't need to care what it calls if your system supports .Net core.

12
16

Re: PowerShell?

Yes, that's more or less how I see it.

Those of us raised with tools like grep find it awkward to work the way we are used to when we move to Powershell but once there are people brought up in that environment they'll find it equally clumsy should they be asked to move in the other direction ('What do you mean it just returns a single property from each object combined into a text stream? I want my objects!')

I don't know how useful it will be on my non-Windows systems but I'm certainly not going to rule it out just because it's Microsoft.

18
1
Anonymous Coward

Re: " from top to bottom Windows is"

Really, most of Windows is C API. And most of .NET (and Windows Runtime / COM) is a wrapper around the C API.

Start reverse engineering things, and you notice that very quickly.

Also, Powershell isn't a wrapper around .NET. It is .NET.

14
3
Anonymous Coward

Re: PowerShell?

Why do people compare Powershell to bash?

It's a very capable scripting language, but an appalling shell. Bash is the reverse.

You're better off comparing it to node or python.

29
1
Silver badge

Re: PowerShell?

This is a stupid argument.

If you're used to Bash, use Bash. If you're used to Powershell, use Powershell. Bash is better for Linux administration but pretty hamstring for Windows, while Powershell integrates with Windows perfectly but isn't likely to be doing anything exciting on Linux.

I see this rather more as giving you the option to use the right tool for Linux-to-Windows administration (since 90% of your client machines are likely to be on Windows even if your engineers are using Linux), rather than an attempt to supplant Bash on Linux-to-Linux admin tasks.

16
2
Anonymous Coward

"You are not understanding how this works"

You are not really understanding what Windows is, and how PowerShell works.

Like it or not, PowerShell commands ends calling or a Windows API (through its wrappers, it has to turn API calls into its .NET objects methods and properties, how do you think it happens, magically?), or an application API - which may be already a .NET one, or not, depending on what the application is coded with.

WMI itself is a COM based interface, and it's obviously available with .NET since .NET - like many other languages - can call COM objects.

Still "Windows from top to bottom" CAN'T "pass data as objects", because that's not how Windows is implemented. There is no, for example, file object in Windows. There are file handles, and file functions. Whatever you use to manipulate a file has to be a wrapper over these APIs.

"You don't need to care what it calls if your system supports .Net core"

Exactly - you need the whole .NET stuff to use PowerShell, and that's something I'd happily avoid. It's just another damned layer to keep updated (I'm really tired to apply .NET updates too), broadens the attack surface, and limits the number of languages you can use to manage Windows.

Each and every management tool using PowerShell scripts is far slower and less user friendly than the previous tools using COM - and especially their error handling is awful. That's because the .NET overhead and piping of text data instead of native code calls and proper in-memory data structures and exceptions passed around (albeit marshaled when needed).

20
5
Silver badge

Re: PowerShell?

> 1) Object oriented pipes so that I don't have to format and reparse and be concerned about language settings.

This is easily the best feature of powershell, but the rest of it is just so bad it fails to redeem it.

Also some of your other points do exist in other shells.

The surprising thing is that bash can compete at all, given the 40 odd years between them, and yet it does.

19
5
Silver badge

Re: PowerShell?

> "9) PowerShell web access. You can now set up a IIS with PWA as a gateway.

> This gives you a firewall-friendly remote command line in any standards compliant browser."

Is that entirely wise?

24
1
FAIL

Re: PowerShell?

Powershell is far superior to Bash and I call BULLSHIT on your suggestion that Bash is superior.

Well, you sound like a blithering idiot saying that. Apart from #2, none of those are geared towards a shell. You might as well have described be benefits C#, or compared VBA to batch files.

The trouble with bash is people think it's a scripting language, when it's not. It's the equivalent to batch files - more than a screen-full, then you need a good reason to not use something else.

26
2
Silver badge

Re: " from top to bottom Windows is"

>>"No. Windows is still mostly a C API, which is not object oriented. It also has some C++ and COM APIs, which are object oriented, but which are not .NET objects. Powershell requires its wrappers over all of them."

No. Windows HAS a C API (and others). But pretty much every setting and configurable option in the OS is exposed as an object for use by Powershell.

>>And frankly, I'd prefer to call a COM API than a .NET one. It doesn't require a specific VM, a JIT, and a framework just to call a function - and you can call it from many more languages and scripts.

It's the 21st Century. It's okay to use languages that don't require an explicit compilation step. We're discussing Powershell vs. Bash. None of the above is relevant in a comparison of the two.

5
16
Silver badge

Re: PowerShell?

Giving a long list of features in PowerShell does not imply that it is superior. A casual glance, in fact, reveals that almost everything in the list is either essentially meaningless (e.g. "True remote sessions") or has no place in a shell (e.g. "web access").

18
4
Silver badge
Pint

Re: PowerShell?

Yes. I'm very sorry. Full attribution to The Vogon for that list. I had it floating around from a previous discussion. Sorry about that - I did credit you last time I posted it but I seem to have lost it this time. Mea Culpa.

It's a good list. Pint as apology!

6
3
Silver badge

Re: PowerShell?

>>Why do people compare Powershell to bash?

Seems to be mostly GNU/Linux users who need to assert that their OS is better than another. Command Line has historically been a notable differentiator between GNU/Linux and Windows. And so its arcane spells and incantations became a badge of superiority over dialogue boxes and configuration wizards - because if you need to be smarter to use it, that shows it's the tool for smart people. *ahem*

When Microsoft looked at Bash and said: "You know, if we can make this a bit less idiosyncratic and do it in a modern way, it would be pretty useful to us, too" it was like Steve Balmer had personally mugged Brian Fox at gunpoint to these people. (Even though as you point out, Powershell and Bash have basic, conceptual differences). It became vital to prove that Powershell, despite being newer and benefiting from building on everything that came before it, was inferior to Bash. Because otherwise GNU/Linux gurus couldn't point at a pile of (unsigned, downloaded from the web) scripts and say: "See! Better!"

>>It's a very capable scripting language, but an appalling shell

Well it's not really a shell. I fire up ISE (Integrated Scripting Environment) which comes as standard on Windows rather than the basic Powershell interface and it works great as a shell for me. (Only time I use the other interface is if I'm CLI'ing in Python or something and I need stdin style interaction).

>>You're better off comparing it to node or python.

By language design, yes. But it's so handy for sysadmins managing Windows systems that it occupies the same user space as Bash.

5
16
Silver badge
Trollface

Re: PowerShell?

@JLV - So PS is a bit like Perl?

4
1
Silver badge
Thumb Up

Re: PowerShell?

"[Powershell is] a very capable scripting language, but an appalling shell. Bash is the reverse."

Ahh, thankyou AC, this is what I've been thinking for years, but never managed to put into words.

4
1
Silver badge

Re: PowerShell?

Powershell is far superior to Bash

At the point you are demonstrating the syntax is abominable so while you can wing all 15 use cases after quad espresso and an amphetamine chaser, doing so in a business environment should be a sackable offense.

If you want to use it for something THAT level of complexity neither bash, nor powershell do the job. You need to use a proper language, have test cases, unit testing and possibly integration testing. Sure, you can cook it in bash or ps instead of let's say python, but that means that you need to find someone capable of consuming the same speed flavored quad espressos to maintain it.

Both PS and Bash have lost the plot - they now allow what is effectively software development while having a readability compared to which badly written Perl reads like Shakespeare sonnets. No thanks, if someone starts building production code using either, sacking is the right thing to do.

4
2
Silver badge

Re: PowerShell?

But grep is so much more natural to use. I mean you grep things, you don't "findstr" things.

7
1
Silver badge

Re: PowerShell?

> Command Line has historically been a notable differentiator between GNU/Linux and Windows.

Mainly because Microsoft spent decades denigrating 'command line' and deliberately crippling their own. For example 20 years ago in Windows 95 they included a command line editor, doskey, but it wasn't available by default and wasn't documented. The initial development version of Windows 98 did not even include a DOS box or a command line (that had to be fixed).

9
1
Happy

Re: PowerShell?

Powershell is far superior to Bash and I call BULLSHIT on your suggestion that Bash is superior.

And yet, only today, there was an article in El Reg bemoaning the fact that there are no more religious wars in IT.

8
0
Anonymous Coward

Re: PowerShell?

"Is that entirely wise?"

Why wouldn't it be? It's just like accessing say Bash via SSH, but far more practical, flexible and firewall friendly with far more security options.

0
4
Anonymous Coward

Re: PowerShell?

> Having used both, I think I will continue to use a *NIX shell, thank you.

Linux type of 23 years here, and Unix before that, but what is wrong with having choice? It is not exactly a binary decision, is it?

Never used PowerShell, but good to know I can if I ever need to.

2
1
Anonymous Coward

Re: PowerShell?

> Quite. I seem to recognise that list from somewhere...

Sounds like the sort of stuff you use Node.js or Python scripts for. :-)

1
1
Silver badge

Re: PowerShell?

It's just like accessing say Bash via SSH, but far more practical, flexible and firewall friendly with far more security options.

This is where the Powershell advocates aren't understanding the UNIX advocates. UNIX has a philosophy:

Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface

and we try to stick to it. This is why Powershell has a long "feature list" that bash does not have. UNIX developers would not put remote access features in to a shell, because remote access features are not part of a shell.

Microsoft has a different approach, they tend to put every feature that they can think would be useful in to a product. To someone who embraces the UNIX philosophy, that is abhorrent, so depending upon your philosophy, you can consider bash superior to Powershell, or vice versa.

1
0
Anonymous Coward

Re: PowerShell?

"It's a very capable scripting language, but an appalling shell. Bash is the reverse."

No, Powershell is also a better shell too. Scripting is after all just creating a series of shell commands.

0
0
Anonymous Coward

Re: "You are not understanding how this works"

"Still "Windows from top to bottom" CAN'T "pass data as objects", because that's not how Windows is implemented. There is no, for example, file object in Windows. There are file handles, and file functions. Whatever you use to manipulate a file has to be a wrapper over these APIs."

Which as the OP stated above is done via the Windows management APIs. There is no "Powershell wrapper" as you claimed - it's part of the OS already.

"Each and every management tool using PowerShell scripts is far slower and less user friendly than the previous tools using COM"

Not true - Exchange and AD tools for instance are WAY faster - especially on multiple objects.

"and especially their error handling is awful"

No it isn't - Powershell tools write to the event logs just like the COM tools did - except with a much more granular level of detail.

"That's because the .NET overhead and piping of text data instead of native code calls and proper in-memory data structures and exceptions passed around (albeit marshaled when needed)."

.Net is very fast versus any other commonly used interpreted CLR model. Performance has never been an issue in any environment I have been in and I work in places with tens of thousands of boxes.

If you look at benchmarks of .Net versus say C++ there usually isn't much in it ands .Net is sometimes significantly faster! See for instance https://www.codeproject.com/Articles/212856/Head-to-head-benchmark-Csharp-vs-NET

0
0
Anonymous Coward

Re: PowerShell?

"is either essentially meaningless (e.g. "True remote sessions")"

Just because you don't understand the advantages doesn't make it meaningless. You can run Powershell directly against remote machines without having to pipe connections via SSH, etc.

" or has no place in a shell (e.g. "web access")."

So say SSH has no place connecting to a Shell?

0
0

Re: PowerShell?

"6) Workflow scripting. PowerShell scripts can (since v3) be defined as workflows which are suspendable, resumable and which can pick up and continue even across system restarts."

I would like to know more. Really need this is some of my scripts.

0
0
Silver badge

Re: PowerShell?

Just because you don't understand the advantages doesn't make it meaningless. You can run Powershell directly against remote machines without having to pipe connections via SSH, etc.

Yes, really, I get it! I just think it is an awful idea. The two things are not related.

So say SSH has no place connecting to a Shell?

No, of course it does not. "The shell" and "how you get remote access to a shell" are orthogonal concepts, implemented in separate programs. The shell doesn't care how it is connected to its user, and the transport doesn't care what it is transporting.

Like I said, whether you agree with this or not will depend on whether your viewpoint is "small programs that do one thing that you can combine with many other programs that also do one thing" is good, or whether you think "one program that can do everything we need in all possible scenarios" is a good thing.

Not to cast too many aspersions, but the best designed, most complex and maintainable a system is, the more likely it is composed of many small programs that do one thing.

0
0
Anonymous Coward

Re: PowerShell?

Heretic

0
0

Restartable (across system restart) powershell scripts

> I would like to know more. Really need this is some of my scripts.

See this article:

https://blogs.technet.microsoft.com/heyscriptingguy/2013/01/23/powershell-workflows-restarting-the-computer/

When using Powershell to script "workflows" a subset of powershell cmdlets are supported. IIRC you can create a "script step" if you want to use non-workflow cmdlets.

0
0

PowerShell on Linux. That's rich. "Here, Yoda, let me show you how to use that there force."

35
8
Silver badge
Mushroom

Powershell == Invasion of the body snatchers

There is no way that I'll ever, ever, ever let it near and Linux or MacOS system of mine.

If it appears then I'll press that big red button myself.

After spending a week battling with MS over why the MSCS bits had dissappeared from a server after the application of a patch and rolling it back made it appear again, I would have liked to do real harm to the people responsible.

They eventually issued the patch again and fixed it but being in S. Asia at the time and with the customer threatening to cancel our $4M contract over the non deliver of clustering, it still gives me the heebies and that was in 2015.

29
13
Anonymous Coward

Re: Powershell == Invasion of the body snatchers

There is no way that I'll ever, ever, ever let it near and Linux or MacOS system of mine.

Ditto. I like tools that are native to the environment. In addition, we have become allergic to Microsoft offering *anything* for free because we know there is a price to pay later (based on a 30+ year track record), we rather continue to actively avoid any Microsoft entanglement. At most, they get to run a desktop environment where we haven't replaced it yet with something that costs less and is easier to maintain, but we no longer allow anything MS made deeper into operations.

If we need anything automated we'll use Unix tools, but for anything complex there will be use cases, analysis and proper coding in a language rather than shell scripts - in a Unix environment.

7
0
Silver badge
Meh

Next up-

Tits on a fish.

24
7
Silver badge

Poor old MS

Still trying to remain relevant, no phone OS, an unloved client OS, a declining user base, a disliked speech app and a far smaller set of tech evangelists as they stopped listening and providing TechNet.

There’s no way I’ll be using this on any non-Windows system as the built in tools have been doing nicely for years.

33
11
Silver badge

Re: Poor old MS

"Still trying to remain relevant, no phone OS"

Microsoft are still developing Windows 10 mobile. To run on what is more the question! And we know that Andromeda is coming which will merge Windows Mobile and Windows capabilities so they haven't given up yet.

"a declining user base,"

Nope - Microsoft's user base is still growing.

" and a far smaller set of tech evangelists as they stopped listening and providing TechNet."

That did suck. But people were flogging the license keys on eBay.

4
16
Silver badge

Re: Poor old MS

"an unloved client OS"

Yeah, not like Windows is the world's most used operating system on desktop or anything....

6
13
Silver badge

Re: Poor old MS

Don't confuse those who are stuck on Windows vs those who like the product.

You might want to research market trends on desktop PC sales, Those who are not stuck on Windows have moved away to products such as Mac, Linux, Tablet devices, mobile phones, etc.

Now go and re-consider if its "the most used OS on desktop or anything" - you will find that its not.

For starters, they only have desktop and tablet offerings, with tablet being a poor second cousin to other competing tablet offerings

If you take a blinkered look of "Microsofts historical market segment", which has two products - Windows and Linux, then yes, its in the lead a the moment, but that lead continues to decline as people look to other more viable products.

This shows that its an unloved OS, otherwise market segment would be increasing and they wouldn't have to have needed to try and give it away.

18
4
Silver badge

Re: Poor old MS

Your reply is self contradictory, in one breath you say

"Now go and re-consider if its "the most used OS on desktop or anything" - you will find that its not."

and then follow it up with

"If you take a blinkered look of "Microsofts historical market segment", which has two products - Windows and Linux, then yes, its in the lead a the moment"

Microsoft's historical market segment, i.e. desktop PCs and laptops, hasn't really changed. Regardless of any marketing hype that has always been and continues to be their largest market (other than Office which is really part of that same segment anyway, although now includes mobile apps on various platforms).

Sure there are tablets to consider, but a Windows tablet is just a laptop in another form factor, and an Android tablet or iPad is a mobile phone in another form factor, they aren't part of the same market segment.

http://gs.statcounter.com/os-market-share/desktop/worldwide/#monthly-201712-201712-bar

This isn't a totally accurate source, since it depends on web browser usage, so devices that are not used to access the Internet are not included, but even if you cut the Windows lead in half it's still well ahead as far as desktop goes.

Mobile of course is another story entirely

http://gs.statcounter.com/os-market-share/mobile/worldwide#monthly-201712-201712-bar

Regardless of whether it has declined/is declining (which I would argue it isn't but that's by the by), it is a simple fact that some form of Windows from XP-10 is currently the most common OS on desktop PCs and laptops for both home and commercial use by quite a significant margin.

If you think otherwise I would love to know what you think the most commonly used desktop OS is.

3
4

Page:

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Forums

Biting the hand that feeds IT © 1998–2018