?
Solved

scrip an aditional binding for IIS site to include www.

Posted on 2011-09-27
9
Medium Priority
?
573 Views
Last Modified: 2012-05-12
Hi all, I have 300 sites in IIS they all have a binding set up as a sub-domain  i.e.

benssite.mydomain.com

this works great for each of the 300 sites

I want to resolve these sites using www.benssite.mydomain.com too

So I want to copy the existing binding and add www. to the beginning and then add this as an additional binding.

so each site has 2 binings:

benssite.mydomain.com
www.benssite.mydomain.com

Is this possible using a script in IIS
0
Comment
Question by:bcoussens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 10

Expert Comment

by:gaurav05
ID: 36715496
Hi,

Command Line
To add a binding to a site, use the following syntax:

appcmd set site /site.name: string /+bindings.[protocol=' string ',bindingInformation=' string ']

The variable site.name string is name of the site to which you want to add a binding. The variable protocol string is the protocol that you want to use, and the variable bindingInformation string is the combination of IP address, port, and host header.

For example, to configure a site named contoso to have an HTTPS binding for all IP addresses, on port 443, without a host header, type the following at the command prompt, and then press ENTER:

appcmd set site /site.name: contoso /+bindings.[protocol='https',bindingInformation='*:443:']

For more information about Appcmd.exe, see Appcmd.exe (IIS 7).

Configuration
The procedure in this topic affects the following configuration elements:

<bindings> under <site> element
0
 
LVL 10

Expert Comment

by:gaurav05
ID: 36715500
Hi,

To add a host header to a Web site's binding, use the following syntax:

appcmd set site /site.name: string /bindings.[protocol=' string ',bindingInformation=' string '].bindingInformation: string

The variable site.name string is name of the site to which you want to add a host header. The variable [protocol='string',bindingInformation='string'] is the existing binding to which you want to add a host header, and bindingInformation string is the new binding with host header.

For example, to configure a site named contoso with an existing HTTPS binding for all IP addresses, on port 443, without a host header to have a host header named marketing, type the following at the command prompt, and then press ENTER:

appcmd set site /site.name: contoso /bindings.[protocol='https',bindingInformation='*:443:'].bindingInformation:*:443: marketing

For more information about Appcmd.exe, see Appcmd.exe (IIS 7).

Configuration
The procedure in this topic affects the following configuration elements:

<bindings> under <site> element
0
 

Author Comment

by:bcoussens
ID: 36716053
Yes I found this online too but this does not copy the existing binding and create an additional one using the current one adding www to the beginning.

Any other ideas?
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 30

Expert Comment

by:Brad Howe
ID: 36716730
So each site ONLY has 1 binding at the moment?

if so, you could create a simple Binding.CMD script that essentially grabs the sites current bindings, pipes to a TXT and then reads the TXT and pipes it back into the site settings.

1. Get ALL Sites Bindings and SITE text:NAME into a tmp TXT file.
    eg :  Ben Site        bensite.domain.com
2. Take the first site name and assign to a string.
3. Take the first binding and assign to a string.
4. Concat the binding_string with www.
5. Execute appcmd set site /+bindings with the sitename_string and binding_string.
6. Loop until TXT is complete.

Just a thought. sounds like a fun script IF all your sites are only with 1 binding currently. Have more will cause more work.

-Hades666
0
 
LVL 30

Accepted Solution

by:
Brad Howe earned 2000 total points
ID: 36717331
Hi,

Created a simple CMD script to automate this for you.

Requirements:
1. TXT File (Site_and_binding.txt) In the following format (SITE,NEWBINDING)
         SITE1,www.site1.com
         SITE2,www.site2.com
         SITE3,www.site3.com
         SITE4,www.site4.com

You can use
   %windir%\system32\inetsrv\AppCmd list sites /text:name > sitenames.txt
to get ALL the SITENAMES

BINDINGS....A little harder if you have multiple.

Create the script binding.CMD

@echo off
FOR /F "tokens=1,2 delims=," %%G IN (Site_and_binding.txt) DO echo ^%windir%\system32\inetsrv\AppCmd set SITE /site.name: %%G /+bindings.[protocol='http',bindingInformation='*:80:%%H']

Then Execute the script    
   CMD> binding.CMD > appcmds.txt

APPCMD.txt OUTPUT SAMPLE
C:\Windows\system32\inetsrv\AppCmd set SITE /site.name: SITE1 /+bindings.[protocol='http',bindingInformation='*:80:www.site1.com']
C:\Windows\system32\inetsrv\AppCmd set SITE /site.name: SITE2 /+bindings.[protocol='http',bindingInformation='*:80:www.site2.com']
C:\Windows\system32\inetsrv\AppCmd set SITE /site.name: SITE3 /+bindings.[protocol='http',bindingInformation='*:80:www.site3.com']
C:\Windows\system32\inetsrv\AppCmd set SITE /site.name: SITE4 /+bindings.[protocol='http',bindingInformation='*:80:www.site4.com']

Then simple cut and past those into command line and wait.

hope it helps give you some ideas.
Cheers,
Hades666
0
 

Author Comment

by:bcoussens
ID: 36764954
ok I think i follow, so first I use    

%windir%\system32\inetsrv\AppCmd list sites /text:name > sitenames.txt from the command line to get an output text file with all site names

this outputs a text file with all the sitenames, I then edit this and add next to each sitename the new www.sitename.domain.com binding (with a comma between site name and new binding)

I save this edited file as Site_and_binding.txt

then i create a script called binding.CMD  inserting:
@echo off
FOR /F "tokens=1,2 delims=," %%G IN (Site_and_binding.txt) DO echo ^%windir%\system32\inetsrv\AppCmd set SITE /site.name: %%G /+bindings.[protocol='http',bindingInformation='*:80:%%H']

Then Execute the script    
   CMD> binding.CMD > appcmds.txt

(i'm not sure about this bit,  where does appcmds.txt com from??  is the outputted from running the script?  or do i need to create this first?  )

Many thanks for your help.

Ben
0
 
LVL 30

Expert Comment

by:Brad Howe
ID: 36782454
Yes,

When you execute binding.cmd > appcmd.txt

The FOR LOOP essentially reads the TXT and generates the proper appcmd syntax to submit via CMD. So after you execute the CMD script, open the file appcmd.txt (which is in the folder you execute the binding.cmd from) and then simple select ALL and paste in commandline.

IIS will then add the bindings.

Cheers,
Hades666
0
 

Author Comment

by:bcoussens
ID: 36889975
Many thanks, this works a treat I now have 300 sites with updated host headers!!

Ben
0
 

Author Closing Comment

by:bcoussens
ID: 36889976
great solution and also attention to detail and communications
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lync server 2013 or Skype for business Backup Service Error ID 4049 – After File Share Migration
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question