IIS 应用程序池在使用 PowerShell 脚本时回收身份

IIS Application Pool recycling Identity when using PowerShell script

我今天正在尝试使用 PowerShell 开发安装 WCF Web 服务。我正在使用在 Windows Server 2012 和 IIS 8.5.96 上执行的 PowerShell 脚本。

起初我手动设置服务,只是为了确保一切正常,然后我更新了我需要在脚本中包含的设置。然后我删除了应用程序池、网站和文件夹目录。

我有 运行 脚本,它可以工作,但是每次 运行 它都会使用我在手动创建服务时使用的 Identity 设置应用程序池.

以下是我目前的脚本。你可以看到我没有在任何地方指定应用程序池身份,所以我认为它必须存储在计算机上的某个地方..但是我没有找到它(我已经搜索了两个CD 驱动器,此服务器上仅有的两个分区)。

有thoughts/ideas吗? #加载IIS模块 导入模块 WebAdministration 添加-Windows功能网络脚本工具

#variables
$okeeffename = "OKeeffe"
$domain = "InsideServices.dev.com"
$okeeffeapppoolname = "OKeeffeApplicationPool"
$okeeffeiis = "IIS:\AppPools$okeeffeapppoolname"
$logpath = "D:\SystemLogFiles\LogFiles"
$domainpath = "d:\webcontent$domain"
$okeeffedirectory = "d:\webcontent$domain$okeeffename"
$okeeffestagingpath = "\prdhilfs02\install\Monet\ServerUpgrade\DEVHILWB119\OKeeffe"

#create webcontent and application folders
Write-Host "Creating directories" -ForegroundColor Yellow
New-Item -Path $domainpath -type directory -ErrorAction Stop
New-Item -Path $okeeffedirectory -type directory -ErrorAction Stop

#create log folder, if it doesn't exist
if(-not (Test-Path -path $logpath))
{   
    New-Item -Path $logpath -type directory 
}

#create app pool
if(-not (Test-Path -path $okeeffeiis))
{
    #Write-Host "Creating app pool: $okeeffeapppoolname" -ForegroundColor Yellow
    New-WebAppPool $okeeffeapppoolname -force -ErrorAction Stop
    set runtime version
    Set-ItemProperty "IIS:\AppPools$okeeffeapppoolname" managedRuntimeVersion v4.0
}

我不太确定是什么原因导致使用以前的标识创建 AppPool,但也许您可以尝试立即设置 New-WebAppPool 返回的 ConfigurationElement 对象的一些属性:

# Get reference to ConfigurationElement for AppPool...
$pool = New-WebAppPool $okeeffeapppoolname -force -ErrorAction Stop

$pool.processModel.identityType = "SpecificUser"
$pool.processModel.username = 'domain\username'
$pool.processModel.password = 'password'

$pool | Set-Item

参考:http://forums.iis.net/t/1171615.aspx?How+to+configure+application+pool+identity+from+powershell+