使用PowerShell创建AppPool不会设置AppPool标识

Dar*_*ode 17 windows iis powershell application-pool

我试图使用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
}
Run Code Online (Sandbox Code Playgroud)

当我运行脚本时,用户名和密码不会更新为我设置的值.

以下是两个打印块的结果

#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
Run Code Online (Sandbox Code Playgroud)

在IIS中,应用程序池显示.Net Framework已更新,但Identity仍设置为ApplicationPoolIdentity.它应该是Domain\UserName.

在此输入图像描述

我是机器上的管理员,我在管理员模式下运行PowerShell.关于我可能缺少什么想法才能让它发挥作用?

Mus*_*idi 25

您需要更改Process Model标识类型以接受用户帐户而不是默认的ApplicationPoolIdentity,这可以按如下方式完成:

Set-ItemProperty -Path IIS:\AppPools\TestAppPool -Name processmodel.identityType -Value 3
Set-ItemProperty -Path IIS:\AppPools\TestAppPool -Name processmodel.username -Value Domain\UserName
Set-ItemProperty -Path IIS:\AppPools\TestAppPool -Name processmodel.password -Value MyPassword
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助.


Fle*_*lea 6

在我需要将appPool设置为NetworkService和其他需要执行此操作的人之后,我遇到了这个问题,这里是IIS 7.5将appPool设置为的语法NetworkService

$pool = get-item("IIS:\AppPools\YOURAPPPOOLNAME");
$pool | Set-ItemProperty -Name "ProcessModel.IdentityType" -Value 2
Run Code Online (Sandbox Code Playgroud)

注意:在IIS 7.5中,NetworkService已从值3切换到值2.

有关更多信息,请Process Model访问:http://www.iis.net/configreference/system.applicationhost/applicationpools/add/processmodel