How to specify application pool identity user and password from PowerShell

前端 未结 4 1397
独厮守ぢ
独厮守ぢ 2021-02-02 07:44

I have been having lots of difficulty automating the setup of a Web application and configuring IIS appropriately with the Application Pool Identity. I am doing this in a Web a

相关标签:
4条回答
  • 2021-02-02 08:06

    After few experiments

    Here is my Answer, I hope this will helps , I've worked on IIS 8.5

    $credentials = (Get-Credential -Message "Please enter the Login credentials including Domain Name").GetNetworkCredential()
    
    $userName = $credentials.Domain + '\' + $credentials.UserName
    
    Set-ItemProperty IIS:\AppPools\$app_pool_name -name processModel.identityType -Value SpecificUser 
    
    Set-ItemProperty IIS:\AppPools\$app_pool_name -name processModel.userName -Value $username
    
    Set-ItemProperty IIS:\AppPools\$app_pool_name -name processModel.password -Value $credentials.Password
    
    0 讨论(0)
  • 2021-02-02 08:09

    I'm on powershell v4 which doesn't have 'ConvertFrom-SecureString', in the end I got the following to work for me:

    Import-Module WebAdministration
    
    $cred = Get-Credential -Message "Please enter username and new password to reset IIS app pool password (for app pools running as username)"
    
    $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($cred.Password)
    $plaintext = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
    
    $applicationPools = Get-ChildItem IIS:\AppPools | where { $_.processModel.userName -eq 
    $cred.UserName }
    
    foreach($pool in $applicationPools)
    {
        $apppool = "IIS:\AppPools\" + $pool.Name
    
        Set-ItemProperty $apppool -name processModel.password -Value $plaintext
    }
    
    Write-Host "Application pool passwords updated..." -ForegroundColor Magenta 
    Write-Host "" 
    Read-Host -Prompt "Press Enter to exit"
    
    0 讨论(0)
  • 2021-02-02 08:15

    You would do this as follows:

    Import-Module WebAdministration
    Set-ItemProperty IIS:\AppPools\app-pool-name -name processModel -value @{userName="user_name";password="password";identitytype=3}
    

    See this document here for an explanation, and a reference of the indentity type numeric for the user type you will run the app pool under: http://www.iis.net/configreference/system.applicationhost/applicationpools/add/processmodel

    0 讨论(0)
  • 2021-02-02 08:19

    seems you can do this a little more directly now

    appcmd set apppool junkapp /processmodel.password:junkpassword
    
    0 讨论(0)
提交回复
热议问题