Live data from Hacker News

In defense of PowerShell

benwilson.me

31–40 of 82 posts

Re: In defense of PowerShell

#31
post #11

I dislike windows (and by extension, powershell) because a solution such as changing the port the webserver runs on looks something like: New-ItemProperty IIS:\sites\DemoSite -name bindings -value @{protocol="http";bindingInformation=":8081:"} http://www.iis.net/learn/manage/powershell/powershell-snap-i... What did I just modify? Is it persisted to the hard disk? How do i back that up? How do I revert the change? How…

That example you gave is from 2008. You would use the current PowerShell Cmdlets provided for managing IIS.

  IIS:\>New-WebBinding -Name "Default Web Site" -IPAddress "*" -Port 80 -HostHeader TestSite
https://technet.microsoft.com/en-us/library/ee790599.aspx

Re: In defense of PowerShell

#32
post #24
post #9

Earlier quoted context omitted.

I find Powershell extremely weird . We have a fair number of Powershell scripts for admin tasks and frankly I think they'd all be easier to understand if they were just written in C#.

[deleted]

Well, to be fair, in 2002 it was far from clear that there were going to be millions of C# programmers.

Re: In defense of PowerShell

#33
post #31
post #11

I dislike windows (and by extension, powershell) because a solution such as changing the port the webserver runs on looks something like: New-ItemProperty IIS:\sites\DemoSite -name bindings -value @{protocol="http";bindingInformation=":8081:"} http://www.iis.net/learn/manage/powershell/powershell-snap-i... What did I just modify? Is it persisted to the hard disk? How do i back that up? How do I revert the change? How…

That example you gave is from 2008. You would use the current PowerShell Cmdlets provided for managing IIS. IIS:\>New-WebBinding -Name "Default Web Site" -IPAddress "*" -Port 80 -HostHeader TestSite https://technet.microsoft.com/en-us/library/ee790599.aspx

Edit: updated per research.

Wouldn't it be, for his example of changing the port:

    Set-WebBinding -Name 'RadWebServer' -IPAddress "*" -Port 443 -PropertyName Port -Value 4430
I don't have a huge amount of PowerShell experience so maybe that's incorrect or has extra bits.

Re: In defense of PowerShell

#34

Noone gets Powershell.

Some of us do, but we've given up trying to expose HN to the shell. The anti-Microsoft culture that built up in the late 1990s and early 2000s has too much inertia on HN to overcome by occasional articles.

The anti-Microsoft culture that was earned in the late 1990s and early 2000s has too much inertia on HN to overcome by occasional articles.

FTFY

Re: In defense of PowerShell

#35
post #7

I work primarily in a Microsoft environment, although I have Linux shell experience as well, and I totally don't get Powershell. What is a cmdlet? Why does it need a stupid made-up name like that? Why are all the commands incredibly verbose and hard to remember? I avoid using it at every opportunity.

Powershell cmdlets are different(ly named) than executables/commands because they don't preferentially emit text: they emit .NET object streams. I suspect this is for compatibility/interrop reasons.

(They are implemented as .NET classes loaded from within libraries, as I recall. Eg, `import-module activedirectory` will load the entire library of AD cmdlets.)

Here's what you can do with object streams:

Get-ADUser | select FirstName,LastName,EmailAddress,Department | where {$_.FirstName -contains "Jeffery"} | format-table

In a traditional Unix pipeline, you'd have to make sure that none of the other fields contained "Jeffery", or you could get false positive results. For example, you might have to use multiple named pipes or temporary files for each of the table columns, and reinterpolate them into a table/CSV/whatever after doing the grep. You could always use Python/Perl/Ruby/Tcl instead of course, but those aren't really shells.

You can also do math, method calls, etc. The example above was just a trivial one.

Re: In defense of PowerShell

#36
As someone who used to use PowerShell rather extensively (back when my dayjob regrettably involved thousands of Windows machines that needed managing and support), I feel like trying to compare PowerShell to, say, bash is folly. To me, PowerShell has more in common with a proper scripting language - somewhere between Perl and Ruby, but with a nice-ish REPL - than a traditional shell like bash. Both the Unix-style text-centric paradigm and the PowerShell-style object-centric paradigm have their place.

That all said, the most recent PowerShell I've significantly touched was version 2; I've since moved on to greener pastures.

Re: In defense of PowerShell

#37
post #21

It worse than that, the misunderstanding that is. I live and breathe Linux. But Powershell is so far ahead of bash for text and object manipulation, it's not really even a close call.

That's an interesting claim, care to back it? P.S. *nix shell != bash, there's zsh and fish that are light years ahead re: tab completion and other general niceties.

zsh and fish are mostly interactive shells, are they not? How does your claim of them being ahead in "tab completion and other general niceties" contradict ossreality's claim of PowerShell being superior in "text and object manipulation"?

Re: In defense of PowerShell

#38
post #11

I dislike windows (and by extension, powershell) because a solution such as changing the port the webserver runs on looks something like: New-ItemProperty IIS:\sites\DemoSite -name bindings -value @{protocol="http";bindingInformation=":8081:"} http://www.iis.net/learn/manage/powershell/powershell-snap-i... What did I just modify? Is it persisted to the hard disk? How do i back that up? How do I revert the change? How…

>I dislike windows (and by extension, powershell) because a solution such as changing the port the webserver runs on looks something like:

Doesn't look that much different or arcane to how you'd do it in Linux.

Except more structured (which is good).

>What did I just modify? Is it persisted to the hard disk? How do i back that up? How do I revert the change? How do I move this change (and 20 others) from one server to another?

Oh, the humanity of learning a different way of doing things.

Re: In defense of PowerShell

#39
I have not used powershell so I can't vouch for it. It is mainly because I couldn't find simple tutorials regarding them. Unix shell on the other hand is dead simple to use. However I get all icky if I have to use them on scripts. The outputs are always raw and never structured so it feels like a hackjob everytime. It also leads way to a different kind of vulnerabilities from incorrect parsing of outputs. I think this is the part where powershell from what I heard comes off as superior. The output is structured and you can work straight with the results.

As far as verbosity, its a mixed bag for me. It makes it easy to read at a glance with minimal mental parsing but at the same time seems such an incorrect fit for a shell where it is optimal to have it under a screen line. You can equate it to trying to write a rant on twitter.

Re: In defense of PowerShell

#40
post #15

Earlier quoted context omitted.

As a Unix person, 'Restart-Service' seems a lot easier to remember than 'systemctl'. Edit: Restart-Service is also easier to remember than /etc/init.d was. Edit 2 (rate limit): `service` on RHEL is great, but it's a Red Hat-ism. Which is fine, I used to work at Red Hat, but still. It's also pretty limited: you use service to start/stop/restart, but you still use systemctl to list services, or list /etc/init.d (techni…

What about service apache2 restart

Or /etc/rc.d/apache2 restart, as one would find in the BSD world (and Slackware, with a bit of modification).

This isn't to mention that it should be relatively trivial to map "restart-service $foo" to "/etc/rc.d/$foo restart" or "systemctl $foo.service restart" or whatever if one so chooses.

Post reply on HN