Live data from Hacker News

In defense of PowerShell

benwilson.me

41–50 of 82 posts

Re: In defense of PowerShell

#41
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…

So you're saying that if you expend zero effort to find the answers to these questions then those questions will remain unanswered?

If you want to become a systems administrator of Windows servers then I'd suggest reading at least one book on the subject, you're not going to get there by copying and pasting one command you found on the internet.

Just as it is with linux/unix. Just as it is with anything.

Pretending otherwise is disingenuous and intellectually dishonest.

Re: In defense of PowerShell

#42
Powershell is a nice language.

Here's map/filter/reduce. Golf welcome.

  @(1, 2, 3) `
     | % { $_ + 1 } `
     | ? { $_ -gt 2 } `
     | Measure-Object -Sum
     | Select Sum
You can write a generic reduce like this:

  $reduce = {
    param   ([scriptblock]$reducer)
    begin   { $initialised = $false }
    process { 
      if (-not $initialised) {
        $agg = $_
        $initialised = $true
      } else {
        $agg = &$reducer $agg $_
      }
    }
    end     { $agg }
  }
And then use it like this:

  @(1, 2, 3) | &$reduce { param($agg, $i) $agg + $i }

Re: In defense of PowerShell

#43
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

That's...comforting.

By the way, please stop. I'm having SMIT flashbacks.

Oh, god, the running man. Don't trip, donttripdonttripdontripdontrip...

Re: In defense of PowerShell

#44
I agree with most of the comment: it's weird.

I also agree with the author, you don't try enough or don't bother trying.

i LOVE nix environnements, but i HAVE to work on Windows. And yeah, at first, it's a pain. Nothing works as expected and you get bunch of errors ... but you have to remember that you're not on a nix terminal !

You don't expect to master a environnement on a first try, do you ? Remember this is not the term you know and love. And if you take some time to get used to, here is your reward:

you will be able to rocks the term on Windows too, and that's pretty badass.

Re: In defense of PowerShell

#45
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…

PowerShell has "providers" that let you interact with things as if they were a file system, which is what is going on in your example. I agree that it's not a great way to expose IIS settings.

The other place you see providers in use is when you use PS to edit the registry, but it's HKLM:\ (or whatever other hive) instead of IIS:\, and it makes a lot more sense there since people naturally think of the registry in a filesystem sort of way.

More info if you're curious about providers:

https://technet.microsoft.com/en-us/%5Clibrary/Ee126186(v=VS...

Re: In defense of PowerShell

#46

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.

I don't think PowerShell v. bash is the right comparison here. PowerShell v. Perl or Python or Ruby or Tcl or somesuch would be more spot-on.

Re: In defense of PowerShell

#47
post #15
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.

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…

Restart-Service:Windows :: service:RHEL ?

Re: In defense of PowerShell

#48
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.

A cmdlet is a PowerShell native command. It reads and writes objects, where as Unix commands read and write plain text. Try this in PowerShell:

get-command

get-command | where CommandType -eq "alias"

Notice the lack of parsing. In Unix you'd typically do this kind of thing with grep, but then you'd have to watch out that you don't accidently include the wrong rows because some other column happened to contain the string "alias"

Try this:

Get-Command | Out-GridView

There's this thing called PowerGUI. It has a text editor for writing PS and a computer management GUI tool. It's written in PS itself. At first I wasn't too impressed, but then I noticed in the computer management thing there's an option to "view code". And then I saw how simple it is, how these nice interfaces were implemented with a trivial amount of PowerShell. Now I think PowerShell is great.

Re: In defense of PowerShell

#49
post #43
post #31

Earlier quoted context omitted.

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

That's...comforting. By the way, please stop. I'm having SMIT flashbacks. Oh, god, the running man. Don't trip, donttripdonttripdontripdontrip...

Did you have to mention SMIT?

Re: In defense of PowerShell

#50
post #33
post #31

Earlier quoted context omitted.

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.

Yes it would be as the OP's question was about changing the binding. My bad.
Post reply on HN