Trying to get Application Pool Identity in IIS for a specific name, for example : Test
Succeded in getting it via below code but dont want to loop through all the webapps, is there any easy of getting it by specifying the name?
Import-Module WebAdministration
Get-WebApplication
$webapps = Get-WebApplication
$list = @()
foreach ($webapp in get-childitem IIS:\AppPools\)
{
$name = "IIS:\AppPools\" + $webapp.name
$item = @{}
if ($webapp.name -eq 'Test')
{
$item = $webapp.processModel.identityType
break
}
}
echo $webapp.processModel.identityType
To get the IIS application pool names using PowerShell, you need to use the IIS PSDrive but for that, we need the IIS PowerShell module WebAdministration or IISAdministration on the server we are running the command. If the WebAdministration module is already installed, use the below command to import the module.
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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With