Solved

scrip an aditional binding for IIS site to include www.

Posted on 2011-09-27
9
565 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Accepted Solution

by:
Brad Howe earned 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
I'd like to talk about something that is near and dear to my heart: build systems. Without them, building software is all about compiling locally, with software versions everywhere. It can be a mess. Today we are going to discuss building a small di…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now