我有點晚了,但我認爲這個PowerShell腳本是有用的,請注意,我只將它用於我的本地開發盒,因此對神奇數字表示歉意。
AuthFlags = 4集成授權
這並不完全符合Marc的要求,但它是一個良好的開端。
如果您下載WMI Tools,則可以使用它們探索到IIS元數據庫的WMI接口。
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