question

kannagatlaswamy-9730 avatar image
0 Votes"
kannagatlaswamy-9730 asked RichMatheisen-8856 edited

Power shell Script to add IP address to it's IIS bindings

Hello All,

I want to create a script in SCCM console where in it will deploy to a collection with below script conditions.

Can someone please help me with a power shell script where I want to add the machines IP address to it's IIS bindings.

Regards,
Swamy.

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered kannagatlaswamy-9730 commented

Does no one do web searches anymore???

Set-WebBinding

set-webbinding


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello Rich,

I have went through that link, but am looking for a script where it can write for bulk of machines, and more over the script should be like--- IP address of the machine should be added to IIS bindings on the same machine.

Kindly help me on this.

Regards,
Swamy.

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 edited

A machine usually has more than one IP address, maybe both IPv4 and IPv6, and possibly more than one NIC. You can use Get-NetIpAddress to get those addresses and you can be specific about which NICs you want to use. But how you name those interfaces and what their indexes are you'll have to determine. I imagine they'll differ from machine to machine unless all your machines are configured identically with the NICs in the same slots.

As for a script, what have you tried so far? Post it here if you need help with it or have a question about it.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have tried below the scripts but no luck:

  1. Set-WebBinding -PropertyName "Default Web Site" -Value http -IPAddress 192.168.0.1 -Port 80

  2. $oldIP = "All Unassigned"
    $newIP = "192.168.0.1"
    foreach ($website in Get-Website) {
    "Site: {0}" -f $website.name
    $bindings = Get-WebBinding -Name $website.name
    foreach ($binding in $website.bindings.Collection) {
    $bindingInfo = $binding.bindingInformation
    " Binding: {0}" -f $bindingInfo
    if ($bindingInfo -imatch $oldIP) {
    " Updating IP: {0} ---> {1}" -f $oldIP, $newIP
    Set-WebBinding -Name $website.name -BindingInformation $bindingInfo -PropertyName "IPAddress" -Value $newIP
    }
    }
    }

0 Votes 0 ·

The "bindingInformation" contains the IP, port, and hostname. And there are possibly multiple bindings. Your attempt to use the -imatch operator fails.

Have a look at this link for an example how to get just the IP address(es): get-an-iis-ip-address-in-string-format-from-get-webbinding-in-powershell


0 Votes 0 ·
MotoX80 avatar image
0 Votes"
MotoX80 answered

IP address of the machine should be added to IIS bindings on the same machine.

You don't need to do that unless you have multiple IP addresses. The default binding is "*" which equates to any IP on the machine.

If you have multiple IP's and multiple sites, then you would need a DSC type script to define a specific application/site/IP on a given machine.


125179-capture.jpg




capture.jpg (42.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.