gpt4 book ai didi

powershell - 如何使用 PowerShell 在 IIS 8.5 中创建具有特定用户的应用程序池?

转载 作者:行者123 更新时间:2023-12-03 22:31:10 25 4
gpt4 key购买 nike

下面缩短的代码有效,但它最终使用的是 ApplicationPool 标识,而不是我在数组中指定的特定标识。

声明:

#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..."
}

最佳答案

不使用“Set-ItemProperty”,而是直接访问和设置 AppPool 属性:

$appPool = New-Item $AppPoolName
$appPool.managedRuntimeVersion = $Runtime
$appPool.managedPipelineMode = $Pipeline
$appPool.processModel.identityType = $Identity
$appPool.processModel.username = $AppPoolUser
$appPool.processModel.password = $AppPoolPwd
$appPool | Set-Item
$appPool.Stop()
$appPool.Start()

编辑:做了一些测试,看起来您的代码工作正常,只是它没有设置用户名。为什么?

实际参数是“processModel.userName”(注意大写的“N”)。所以,看起来像

$appPool | Set-ItemProperty -Name processModel.userName -Value $AppPoolUser

区分大小写,但是

$appPool.processModel.username = $AppPoolUser

不是。爱上了 PowerShell。

关于powershell - 如何使用 PowerShell 在 IIS 8.5 中创建具有特定用户的应用程序池?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29244067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com