Joseph Joseph - 3 months ago 21
PowerShell Question

Get App Pool Identity for IIS in Power Shell Script

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

Answer

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
Comments