Skip to content

Instantly share code, notes, and snippets.

@stanislavhordiyenko
Created August 24, 2017 23:58
Show Gist options
  • Save stanislavhordiyenko/abf85cb74dcd2f764c9314cd22d77f70 to your computer and use it in GitHub Desktop.
Save stanislavhordiyenko/abf85cb74dcd2f764c9314cd22d77f70 to your computer and use it in GitHub Desktop.
Test-VirtualDirectory function will help you to find out whether virtual directory exists in IIS from powershell script
Import-Module WebAdministration
function Test-VirtualDirectory
{
param(
[string]$WebsiteName,
[string]$VirtualDirectoryPath
)
if (-not (Test-Path "IIS:\Sites\$WebsiteName")) {
throw "$WebsiteName website could not be found in IIS"
}
return (Get-ChildItem "IIS:\Sites\$WebsiteName" | Where { $_.Schema.Name -eq 'VirtualDirectory' -and $_.Name -eq $VirtualDirectoryPath } | Measure).Count -eq 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment