function Test-IISAppPoolByName { <# .SYNOPSIS Tests IIS to see if a specific app pool is running Will throw if there is no app pool #> [CmdletBinding()] [OutputType([System.Boolean])] Param( [Parameter(Mandatory=$false)] [Alias("AppPoolName")] [string]$Name = "" ) process { $logLead = (Get-LogLeadName) Write-Verbose "$logLead : Finding app pool by name" if (!$Name) { Write-Host "The following are the valid names for application pools:" Write-Host (((IISAdministration\Get-IISAppPool).Name) -Join "`r`n") # This should halt, returning false could be construed as the app pool exists throw "$logLead : $Name was empty or not supplied" } else { try { $appPool = IISAdministration\Get-IISAppPool -Name $name -ErrorAction Ignore if ($null -eq $appPool) { # This should halt, returning false could be construed as the app pool exists # Setting to return false tho because of some sites being configured not-as-expected Write-Warning "$logLead : $Name is not a valid AppPool name" return $false; } else { return $appPool.State -eq "Started" } } catch { # This should halt, returning false could be construed as the app pool exists # Setting to return false tho because of some sites being configured not-as-expected Write-Warning "$logLead : $Name is not a valid AppPool name" return $false; } } return $false } }