List of redirect addresses (URLs) of IIS sites
I have several redirect sites configured in IIS 8.5 and I want to list them all. I tried:
.\appcmd.exe list site * -section:system.webServer/httpRedirect
but wildcards don't work fine with appcmd
. I also tried the module WebAdministration
:
Get-WebConfiguration system.webServer/httpRedirect * | Get-Member destination
but that also doesn't deliver what I need ... which is a 2 column list for site and destination
+3
source to share
2 answers
This snippet will give you the filenames and httpirectirect addresses:
Get-Website | select name,@{name='destination';e={(Get-WebConfigurationProperty -filter /system.webServer/httpRedirect -name "destination" -PSPath "IIS:\Sites\$($_.name)").value}}
To get only addressees:
(Get-WebConfigurationProperty -filter /system.webServer/httpRedirect -name "destination" -PSPath 'IIS:\Sites\*').value
+4
source to share
To solve this problem, you can refer to the function below.
Function Get-IISRedirectURLs {
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$false)][String]$SiteName
)
If ([String]::IsNullOrEmpty($SiteName)) {
Get-Website | ForEach-Object {
$SiteName = $_.Name
$prop = Get-WebConfigurationProperty -filter /system.webServer/httpRedirect -name 'destination' -PSPath "IIS:\Sites\$SiteName"
Write-Host "$SiteName`t$($prop.value)"
}
} Else {
$prop = Get-WebConfigurationProperty -filter /system.webServer/httpRedirect -name 'destination' -PSPath "IIS:\Sites\$SiteName"
Write-Host "$SiteName`t$($prop.value)"
}
}
For a complete archive of samples, please download from How to redirect target URLs of IIS sites using PowerShell
+1
source to share