Hi Guys, today we are going to disuses about how to add the binding to IIS using Powershell. In most case, during the deployments, the one of the painful activity is adding binding for new sites. So this below posts will help those members to one step towards of Automation.
Theย New-WebBindingย cmdlet adds a new binding to an existing website.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#Assigining the URL which need to bind $_WebsiteUrl = "www.dotnet-helpers.com" #Name of the WEB SITE name created under Sites Folder(IIS) $_TargetIISWebsite ="Default Web site" #It has a method IsNullOrEmpty() which returns true if the passed string is null or empty. if([string]::IsNullOrWhiteSpace($_TargetIISWebsite)) { write-host "website not created." } else { #TRIM: Removes all leading and trailing white-space characters from the current String object $WebsiteUrl = $_WebsiteUrl.Trim(' ') } foreach ($Website in $_WebsiteUrl) { #We are adding the SSL binding to the Default Web Site using New-WebBinding cmdlets New-WebBinding -Name $web -IPAddress "*" -Port 80 -protocol http -HostHeader $Website -sslflags New-WebBinding -Name $web -IPAddress "*" -Port 443 -protocol https -HostHeader $Website -sslflags write-host $Website "Binding created successfully on" $_TargetIISWebsite } } |
Explanation:
Theย New-WebBindingย cmdlet adds a new binding to an existing website.
New-WebBinding -Name $web -IPAddress “*” -Port 80 -protocol http -HostHeader $Website -sslflags 0
-Name | The name of the Web site on which the new binding is created. |
-IPAddress | The IP address of the new binding. |
-Port | The port used for the binding. |
-Protocol | The protocol to be used for the Web binding (usually HTTP, HTTPS, or FTP). |
-HostHeader | The host header of the new binding. |
-SslFlags | Indicates what type of certificate OR certificate storage the new website supports. Only the below values are valid:
0 (Regular certificate in Windows certificate storage), |
What do you think?
I hope you have idea of how to add the binding to IIS using Powershell Script. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.
Hi Imran,
Thanks for your Prompt question. It can be achievable in single line of command in Command prompt. Please refer the link https://dotnet-helpers.com/iis/exporting-and-importing-website-in-iis
I have to move one site to another server which has around 500 site bindings. How can I achieve this. I am totally zero about the power shell script but knows c#.net. Any help is deeply appreciated.