Link to home
Start Free TrialLog in
Avatar of introlux
introluxFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Script IIS7 & 7.5

Hi,

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/*:80:www.%directory%.%computername%.net 

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 http://www.%directory%.%computername%.net:80 

REM interactive mode 
if [%1]==[] (if [%2]==[] ( 
	pause 
	exit 
))

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 http://www.test10.SERVER1.net:80
Press any key to continue . . .

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

Regards,

introlux
Avatar of arnold
arnold
Flag of United States of America image

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.
Avatar of introlux

ASKER

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.

http://technet.microsoft.com/en-us/library/ee790599.aspx

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.
It seems you are in need of further assistance.
If you would provide detail.........
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.

Regards,

introlux
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.
Powershell script
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks