我正在尝试使用 PowerShell 在 IIS 中创建应用程序池。在网上搜索后,我创建了以下测试脚本:
Import-Module WebAdministration
$siteName = "TestAppPool"
$userAccountName = "Domain\UserName"
$userAccountPassword = "MyPassword"
if(!(Test-Path ("IIS:\AppPools\" + $siteName)))
{
$appPool = New-Item ("IIS:\AppPools\" + $siteName)
#Display Default AppPool Settings
"AppPool = " + $appPool
"UserName = " + $appPool.processModel.userName
"Password = " + $appPool.processModel.password
"Runtime = " + $appPool.managedRuntimeVersion
$appPool.processModel.userName = $userAccountName
$appPool.processModel.password = $userAccountPassword
$appPool.managedRuntimeVersion = "v4.0"
$appPool | Set-Item
#Display Updated AppPool Settings
"AppPool = " +$appPool
"UserName = " + $appPool.processModel.userName
"Password = " + $appPool.processModel.password
"Runtime = " + $appPool.managedRuntimeVersion
}
当我运行脚本时,用户名和密码不会更新为我设置的值。
这是两个打印块的结果
#Display Default AppPool Settings
AppPool = Microsoft.IIs.PowerShell.Framework.ConfigurationElement
UserName =
Password =
Runtime = v2.0
#Display Updated AppPool Settings
AppPool = Microsoft.IIs.PowerShell.Framework.ConfigurationElement
UserName =
Password =
Runtime = v2.0
在 IIS 中查看,应用程序池显示 .Net 框架已更新,但身份仍设置为 ApplicationPoolIdentity。它应该是域\用户名。
我是机器上的管理员,我在管理员模式下运行 PowerShell。关于我可能缺少什么以使其正常工作的任何想法?