简体   繁体   English

如何使用PowerShell在IIS 8.5中为特定用户创建应用程序池?

[英]How do I create an application pool with specific user in IIS 8.5 using PowerShell?

The shortened code below works, but it winds up using the ApplicationPool identity, not the specific ones that I specify in the array. 下面的缩短代码可行,但它最终使用ApplicationPool标识,而不是我在数组中指定的特定标识。

Declarations: 声明:

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

Execute Code: 执行代码:

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

Instead of using "Set-ItemProperty", access and set the AppPool property directly: 而不是使用“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()

EDIT: Did some testing and it appears that your code works just fine, except it does not set the user name. 编辑:做了一些测试,看起来你的代码工作得很好,除了它没有设置用户名。 Why? 为什么?

The actual parameter is "processModel.userName" (Notice the capital 'N'). 实际参数是“processModel.userName”(注意大写'N')。 So, it looks like 所以,它看起来像

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

is case sensitive, but 区分大小写,但是

$appPool.processModel.username = $AppPoolUser

is not. 不是。 Got to love PowerShell. 一定要喜欢PowerShell。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Powershell在IIS 5.0中创建应用程序? - How do I create an application in IIS 5.0 using powershell? 如何在 IIS 管理器中使用 PowerShell 或 appcmd 在 Compression 中设置应用程序池磁盘空间限制? - How do I set the application pool disk space limit in IIS Manager in Compression using PowerShell or appcmd? 如何使用powershell脚本启动和停止IIS中的应用程序池 - How to start and stop application pool in IIS using powershell script 使用Powershell创建IIS 6.0应用程序池 - Creating an IIS 6.0 Application Pool using Powershell 使用 Powershell 获取 IIS 应用程序池 ProcessID - Using Powershell to obtain an IIS Application Pool ProcessID 使用PowerShell配置IIS应用程序池设置 - Configuring IIS application pool settings using PowerShell 如何使用Powershell将IIS7应用程序池及其设置导出到多个服务器 - How do I export IIS7 app pool and its settings using Powershell to multiple servers 如何使用 Powershell 枚举 IIS 网站并找到每个网站的应用程序池? - How do I enumerate IIS websites using Powershell and find the app pool for each? 使用Powershell在IIS中设置网站的应用程序池 - Setting a website's application pool in IIS using Powershell 使用PowerShell回收IIS应用程序池:“异常调用回收” - Recycling IIS application pool using PowerShell: “Exception calling Recycle”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM