Script IIS7 & 7.5


I have the following code:

@echo off 
setlocal EnableDelayedExpansion 

REM Get parameters from user if they're not specified 
if [%1]==[] set /P directory="Enter name of directory/site: " 
if [%2]==[] set /P sitenum="Enter site number: " 

mkdir C:\websites\%directory%

REM Create site in IIS 
%systemroot%\system32\inetsrv\appcmd add site /name:"%directory%" /id:%sitenum% /physicalPath:"C:\websites\%directory%" /bindings:http/* 

REM Attempt to migrate config to IIS7 stylee 
%SystemRoot%\system32\inetsrv\appcmd migrate config "%directory%/" 

REM Start new site 
%SystemRoot%\system32\inetsrv\appcmd start site "%directory%" 

echo site "%directory%" now running at 

REM interactive mode 
if [%1]==[] (if [%2]==[] ( 

Open in new window

Problem I face:

It does not create the folder directory
I want the site ID to be added automatically rather than a user entering the ID
I also get an error:
Enter name of directory/site: test10
Enter site number: 23
SITE object "test10" added
APP object "test10/" added
VDIR object "test10/" added
Successfully migrated section "system.web/httpModules".
Successfully migrated section "system.web/httpHandlers".
ERROR ( message:The W3SVC service is not available - try starting the service first. )
site "ari10" now running at
Press any key to continue . . .

Any help will be appreciated. Trying to get this process automated.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

First, the site number is a unique identifier.  Your script lacks testing to make sure a site number a user might enter is not already in use.
Similarly for any input you request.

Is IIS running?
W3svc refers to the IIS not running when you are trying to start a site.
introluxAuthor Commented:
So there is no way to automate the site number apart from having a check that the ID number is in use?
If you do not specify the ID, the system will randomly assign one.
Any scripting should use testing and validation to avoid data corruption.

vbscript/powershell might be a more robust than the batch file using appcmd.

If I am not mistaken, vbscript and possible powershell, have methods/tie into such that you can configure/manage/ the IIS parameters.

Instead of prompting for information, you could use a CSV/excel spreadsheet/database from which your script will read data, and then add/activate, deactivate, delete sites.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

It seems you are in need of further assistance.
If you would provide detail.........
introluxAuthor Commented:
Basically looking to generate a script that we would possibly run  to create the following:

Create folder
Create sites and set correct binding
Create Application Pool
Set Application Pool .NET version (If possible)
Start web site

Let me know if possible.


It is possible, using vbscript, powershell or c# might be a better approach as they have hooks to interact and verify response as compared to using batch processing when you have to call different commands to do the different things.
introluxAuthor Commented:
Powershell script
There are many examples of scripts that perform these tasks.  You would need to combine the various available scripts into a single one that does what you need.
i.e script that creates folders and sets appropriate permissions
script that ..........

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
introluxAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.