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