tags:

views:

554

answers:

6

edit: IIS6; I'm not sure IIS7 is an option in the immediate future...

From a developer angle, I am constantly changing my IIS settings, or need to merge settings from other teams into different VMs. The "Save Configuration to Disk" has never really worked well for me.

Because we are making lots of small changes, web installation projects have never really worked either... Tools aimed for the web-admin aren't necessarily a good fit for the developer - we have different aims and needs.

Does anyone have a script / tool / utility that would allow us to quickly configure IIS? In particular:

  • remove everything (start clean)
  • add a load of virtual directories, each mapped to application base paths
  • set as an application
  • set the app-pool (we'll assume the app pool already exists)
  • set the ASP.NET version to 2.x if needed

from some find of flat input list (any format would do).

+3  A: 

PowerShell with the IIS administration snapin?

Richard
+1  A: 

Powershell would work. If you wanted to avoid dependencies, you could also generate a script to run against AdsUtil.vbs.

Probably easier would be standardizing on IIS7 where all this stuff lives in web.config files making life alot easier.

Wyatt Barnett
+1  A: 

You may want to look into the Metabase XML config files for IIS and allowing direct edit.

CodeRot
+6  A: 

I can think of three options off the top of my head...

  1. Powershell snap-in.
  2. the AdsUtil.vbs (located in C:\Inetpub\AdminScripts by default) will enable you to script those tasks into a batch file, or you could even call it from powershell if you don't have the time to invest learning the WMI interface for IIS.
  3. MSBuild script. Probably harder to configure but the MSBuild Extension Pack provides some tasks for managing both IIS6 and IIS7 from a MSBuild script.

I think if it was me needing to do this, I would use Powershell, or remove the need all together and create a base VM install that had all the basics already configured in. When I'm done with teasting I'd just rollback the harddrive and be free to go again.

David McEwing
+3  A: 

I'm a bit late to the show but I thought this PowerShell script my be useful, be aware I only use this for my local development box so apologies for the magic numbers.

AuthFlags = 4 is integrated authorisation

It doesn't exactly fulfil Marc's requirements but it's a good start.

If you download WMI Tools you can use them to explore the WMI interface to the IIS metabase.

function CreateAppPool($poolName,$userName,$password)
{
    [wmiclass] $appPoolSettings = "root\MicrosoftIISv2:IISApplicationPoolSetting";
    $newPool = $appPoolSettings.CreateInstance();
    $newPool.Name = "W3SVC/AppPools/" + $poolName;
    $newPool.WAMUsername = $userName;
    $newPool.WAMUserPass = $password;
    $newPool.AppPoolIdentityType = 3;
    $newPool.Put();
    # Do it again if it fails as there is a bug with Powershell/WMI
    if (!$?)
    {
        $newPool.Put(); 
    }
}


function CreateWebsite($webSiteName, $path, $port, $appPoolName)
{
    [wmiclass] $bindingClass = 'root\MicrosoftIISv2:ServerBinding';
    $bindings = $bindingClass.CreateInstance();
    $bindings.Port = $port;
    $webService = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsWebService";
    $webSite = $webService.CreateNewSite($webSiteName, $bindings, $path);
    [int] $index = $webSite.ReturnValue.IndexOf("'") + 1;
    [int] $length = $webSite.ReturnValue.Length - $index - 1;
    [string] $websiteID = $webSite.ReturnValue.SubString($index, $length)  + "/root";
    $webVirtualDirSetting = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsWebVirtualDirSetting" | Where-Object {$_.Name -eq $websiteID};
    $webVirtualDirSetting.AppFriendlyName = $webSiteName;
    $webVirtualDirSetting.AppPoolId = $appPoolName;
    $webVirtualDirSetting.AccessFlags = 517;
    $webVirtualDirSetting.AuthFlags = 4;
    $webVirtualDirSetting.Put();

    #Switch the Website to .NET 2.0
    C:\windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -sn W3SVC/
}

$webSiteName = "MyWebsiteName";
$webSitePath = "C:\MyWebsitePath";
$webSitePort = "9001";
$appPoolName = "MyWebsitePool";
$appPoolIdentity = "MYDESKTOP\MyWebsiteIdentity";
$appPoolPassword = "MyWebsitePassword"; 

CreateAppPool $appPoolName $appPoolIdentity $appPoolPassword
CreateWebsite $webSiteName $webSitePath $webSitePort $appPoolName
Nigel Holland
+1  A: 

may or may not help but check out http://rprieto.github.com/psDeploy/iis-6-cmdlets.html

RhysC