简体   繁体   中英

IIS Application Pool recycling Identity when using PowerShell script

I'm trying my hand at PowerShell today with a dev install of a WCF web service. I'm using a PowerShell script being executed on Windows Server 2012 and IIS 8.5.96.

At first I manually set up the service, just to make sure everything worked and I new what settings I would need to include in the script. I then deleted the application pool, the web site, and the folder directory.

I've run the script, and it works, however everytime it runs it sets the application pool up with the Identity I used when I manually created the service.

Below is the script as I have it so far. You can see that I don't specify the application pool Identity anywhere, so I'm thinking it must be stored somewhere on the computer.. however I haven't had any luck finding it (I've done a search on both C and D drives, the only two partitions on this server).

Any thoughts/ideas? #load the IIS module Import-Module WebAdministration Add-WindowsFeature Web-Scripting-Tools

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

I am not really sure what is causing the AppPool to be created with the previous identity, but perhaps you could try immediately setting some of the properties on the ConfigurationElement object returned by New-WebAppPool:

# 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM