Get App Pool Identity for IIS in Power Shell Script

Not strictly what the OP wanted, but google led me here for querying all App Pool Identities. This is my version

Import-Module WebAdministration;Get-ChildItem -Path IIS:\AppPools\ | 
Select-Object name, state, managedRuntimeVersion, managedPipelineMode, @{e={$_.processModel.username};l="username"}, <#@{e={$_.processModel.password};l="password"}, #> @{e={$_.processModel.identityType};l="identityType"} |
format-table -AutoSize

I know this is old, but this is what I ended up using, which I think suits everyone?

Assuming $Name contains the app pool's name:

$sid = New-Object System.Security.Principal.SecurityIdentifier (
    Get-Item IIS:\AppPools\$Name | select -ExpandProperty applicationPoolSid
)

$identity = $sid.Translate([System.Security.Principal.NTAccount])

$identity.Value 

IIS APPPOOL\MyAppPool


Just combine the path and retrieve the item. This will work:

$item = Get-Item (Join-Path 'IIS:\AppPools\' 'Test') | 
   select -ExpandProperty processModel | 
   select -expand identityType

Needed this but none of the answers had complete code so I put something together.

Try {
    Import-Module WebAdministration -ErrorAction Stop
} Catch {
    Write-Error -Message "Unable to load required module."
}

$webapps = Get-ChildItem –Path IIS:\AppPools
$list = [System.Collections.ArrayList]::new()
foreach ($webapp in $webapps) {
    $Pool = "IIS:\AppPools\" + $webapp.name
    $sid = New-Object System.Security.Principal.SecurityIdentifier (
        Get-Item $Pool | select -ExpandProperty applicationPoolSid
    )
    [void]$List.add([PSCustomObject]@{
        Name = $webapp.name
        Pool = $Pool
        ServiceAccount = $sid.Translate([System.Security.Principal.NTAccount])
    })
}
$list

Output

Name              Pool                            ServiceAccount               
----              ----                            --------------               
.NET v4.5         IIS:\AppPools\.NET v4.5         IIS APPPOOL\.NET v4.5        
.NET v4.5 Classic IIS:\AppPools\.NET v4.5 Classic IIS APPPOOL\.NET v4.5 Classic
DefaultAppPool    IIS:\AppPools\DefaultAppPool    IIS APPPOOL\DefaultAppPool   
WsusPool          IIS:\AppPools\WsusPool          IIS APPPOOL\WsusPool         

Tags:

Iis

Powershell