-
-
Save uzbekdev1/6c552dfd9204a13c68121dfc85b5dc35 to your computer and use it in GitHub Desktop.
Check if the an application pool exists on a remote server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Tests if a web application exists (this can be a site or application). | |
This was only written to keep naming conventions consistent. This is the same as | |
Test-Path IIS:\Sites\$SiteName; | |
.PARAMETER Url | |
The url of the match on | |
.PARAMETER Environment | |
The environment to apply this to | |
.EXAMPLE | |
Test-WebAppExists -Environment Dev -Url "http://unittest.{env}.place.something.com/services" | |
#> | |
Function Test-WebAppExists { | |
Param ( | |
[string] $ServerName = $env:COMPUTERNAME, | |
[Parameter(Mandatory = $true)] | |
[string] $Url | |
) | |
# setup variables | |
$appPoolName = ConvertTo-UrlBasedAppPoolName -Url $Url | |
$scriptBlock = { | |
if($appPoolName -eq $null) { | |
$appPoolName = $args[0] | |
} | |
Import-Module WebAdministration | |
$pathToTest = "IIS:\AppPools\{0}" -f $appPoolName | |
if((Test-Path $pathToTest) -eq $false) { return $false } | |
$app = Get-Item $pathToTest | |
$exists = $true | |
if($app -eq $null) { $exists = $false } | |
if($app.GetType().Fullname -ne "Microsoft.IIs.PowerShell.Framework.ConfigurationElement") { $exists = $false } | |
return $exists; | |
} # end scriptblock | |
$parameters = @($appPoolName) | |
if(Test-IsLocalComputerName -ComputerName $ServerName) { | |
$exists = . $scriptBlock | |
} else { | |
$exists = Invoke-Command -ComputerName $ServerName -ScriptBlock $scriptBlock -ArgumentList $parameters | |
} | |
return $exists; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment