IIS 7.5 Application Panels / IIS Manager: Applications

When you view the application pools in IIS 7.5> application pools, the last column lists "Applications." This column shows the number of application / site pools that this appPool is associated with.

I am trying to figure out how to query this column / information using Powershell. The ultimate goal here is to have a script that I could run that would tell me if any application pool is being used for more than one website or application.

I cannot find a way to request this information at startup:

get-itemproperty IIS:\AppPools\(AppPoolName) | format-list * 

I do not see this property. I'm not sure if this column is a property, if not, is there a better way to check if AppPools are being used for more than one website / app?

+4
source share
3 answers

I wish I saw your post earlier, this is what I came up with:

 $SiteApps = get-item IIS:\Sites* $arraySize = ($SiteApps.count -1) $i = 0 $t = 0 for ($i=0; $i -le $arraySize; $i ++) # start at the beg of the array { for ($t=($i+1); $t -le $arraySize; $t++) { if ($siteApps[$i].applicationpool -eq $siteApps[$t].applicationpool) { $web1 = $siteApps[$i].name $webappPool = $siteApps[$i].applicationpool $web2 = $siteApps[$t].name $answer = $answer + "The website "$web1" is sharing the AppPool "webAppPool" with website "$web2". " } } } 
0
source

The Applications property is defined in the format file, its code is in the iisprovider.format.ps1xml file (in the webadmin module folder).

  <TableColumnItem> <ScriptBlock> $pn = $_.Name $sites = get-webconfigurationproperty "/system.applicationHost/sites/site/application[@applicationPool=`'$pn`'and @path='/']/parent::*" machine/webroot/apphost -name name $apps = get-webconfigurationproperty "/system.applicationHost/sites/site/application[@applicationPool=`'$pn`'and @path!='/']" machine/webroot/apphost -name path $arr = @() if ($sites -ne $null) {$arr += $sites} if ($apps -ne $null) {$arr += $apps} if ($arr.Length -gt 0) { $out = "" foreach ($s in $arr) {$out += $s.Value + "`n"} $out.Substring(0, $out.Length - 1) } </ScriptBlock> </TableColumnItem> 

You can extract the code and use it outside the format file, just give $ pn the name of the application you want to request. Here is a simplified version of the code:

 $pn = 'pool1' $sites = get-webconfigurationproperty "/system.applicationHost/sites/site/application[@applicationPool='$pn' and @path='/']/parent::*" machine/webroot/apphost -name name $apps = get-webconfigurationproperty "/system.applicationHost/sites/site/application[@applicationPool='$pn' and @path!='/']" machine/webroot/apphost -name path $sites,$apps | foreach {$_.value} 
+4
source

I went with this:

 Import-Module WebAdministration function Get-WebAppPoolApplications($webAppPoolName) { $result = @() $webAppPool = Get-Item ( Join-Path 'IIS:\AppPools' $webAppPoolName ) if ( $webAppPool -ne $null ) { $webSites = Get-ChildItem 'IIS:\Sites' $webSites | % { $webApplications = Get-ChildItem ( Join-Path 'IIS:\Sites' $_.Name ) | where { $_.NodeType -eq 'application' } $result += $webApplications | where { $_.applicationPool -eq $webAppPoolName } } } $result } 
+1
source

Source: https://habr.com/ru/post/1411841/


All Articles