Hacker News new | ask | show | jobs
by parfe 3948 days ago
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 do I move this change (and 20 others) from one server to another? It's three months later, and I want to do something similar, where can I find the current state of DemoSite and mimic it for DevSite?

I like plain text. Clearly companies succeed on microsoft products and people make money administering them. Doesn't mean I have to like it.

7 comments

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

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.
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?
And THAT is the other thing. bash 7 years ago is the same as bash today, no changes based on some corporate overlords marketing idea of the month. Powershell is still in flux, and with MS as the owner, when will it ever be stable?
You're comparing the IIS management command lets to bash. PowerShell the language is largely the same, the same as bash. A more apt comparison would be to apachectl and the apache config files, which have changed.
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.

You modified applicationHost.config which is an XML in %windir%\system32\inetsrv.

IIS has its' own set of commands that you may be more comfortable with, appcmd is sorta like apachectl (just more verbose). http://www.iis.net/learn/get-started/getting-started-with-ii....

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

So how would you accomplish the same task on Linux using bash? What script would you write to set the web server's port to 1234?
With conventional Linux distributions it is tricky to do this in a clean and idempotent way while preserving the entirety of the existing server configuration. The best solution of which I am aware is Augeas, which supports multiple file formats, and tools of similar type that specialize in a single file format (e.g., jq).

What these generally do is parse the entire configuration file into an abstract syntax tree, apply the modifications you have asked for to the tree, then serialize the result back into the configuration file format. This ensures that the input and the output are both at least syntactically valid; as a result it is less error-prone than sed/awk. Unlike with configuration file templates (e.g., Ansible's Jinja2 templates) the changes can be applied on top of the distribution's default configuration if desirable and reapplied when that default configuration is updated.

You could just use sed and do a regex substitution that's what I use in similar instances.
Why the colons surrounding the port !?
Basically you're modifying a string that consists of:

   IP Address:Port:Virtual Host
For example:

   172.16.1.1:80:www.example.com
The raw values reside in an XML config file called "applicationHost.config" which replaces the old school and rather opaque IIS6 metabase.

Admittedly that example is a bit old school, there's better commandlets available now that wrap having to manipulate these string values directly. e.g. the New-WebBinding and Set-WebBinding examples shown in sibling comments in this sub-thread.

A site config looks like:

  <site name="MyWebSite" id="3" serverAutoStart="true">
    <application path="/" applicationPool="MyWebSite">
       <virtualDirectory path="/" physicalPath="D:\websites\mywebsite\www" />
    </application>
    <bindings>
      <binding protocol="http" bindingInformation="172.16.1.1:80:example.com" />
      <binding protocol="http" bindingInformation="172.16.1.1:80:www.example.com" />
      <binding protocol="https" bindingInformation="172.16.1.:443:" />
    </bindings>
   </site>
None of this is particularly mysterious, and the documentation is pretty good.