下面的简化代码可行,但最终使用的是应用程序池身份而不是我在数组中指定的特定身份。
声明:
声明:
#App pool array positions
$Name = 0
$User = 1
$Pwdx = 2
#Application array positions
$SiteNm = 0
$PhyPath = 1
$PoolNm = 2
#App Pool Settings
$Port="80"
$HostName="*"
$Environment="local"
$Runtime="v4.0"
$Pipeline="0" #Integrated
$Identity="3" #SpecificUser
#Define the App Pools
$Pools = @(3)*2
$Pools[0] = "SomeAppPool","FooBar\SomeUser","S0meUs3rP4ssw0RD"
$Pools[1] = "AnotherAppPool","FooBar\AnotherUser","An0th3rUs3rP4ssw0RD"
执行代码:
Import-Module WebAdministration
#navigate to the app pools root
cd IIS:\AppPools\
foreach($p in $Pools)
{
$AppPoolName = $p[$Name]
$AppPoolUser = $p[$User]
$AppPoolPwd = $p[$Pwdx]
$appPool = New-Item $AppPoolName
$appPool | Set-ItemProperty -Name managedRuntimeVersion -Value $Runtime
$appPool | Set-ItemProperty -Name managedPipelineMode -Value $Pipeline
$appPool | Set-ItemProperty -Name processModel.identityType -Value $Identity
$appPool | Set-ItemProperty -Name processModel.username -Value $AppPoolUser
$appPool | Set-ItemProperty -Name processModel.password -Value $AppPoolPwd
Write-Host "$AppPoolName Application Pool Created..."
}