Reputation: 1438
I have several redirect sites configured in IIS 8.5, and I want to list them all. I've tried:
.\appcmd.exe list site * -section:system.webServer/httpRedirect
but wildcards are not working fine with appcmd
. I also tried from the WebAdministration
module:
Get-WebConfiguration system.webServer/httpRedirect * | Get-Member destination
but this is also not delivering what I need... which is a list with 2 columns for site & destination
Upvotes: 3
Views: 2371
Reputation: 1009
You can refer to below function to address this issue.
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 the complete sample archive, please download from How to list redirect destination URLs of IIS sites by PowerShell
Upvotes: 1
Reputation: 4069
This snippet will give you the sitenames and httpredirect destinations :
Get-Website | select name,@{name='destination';e={(Get-WebConfigurationProperty -filter /system.webServer/httpRedirect -name "destination" -PSPath "IIS:\Sites\$($_.name)").value}}
For fetching just the destinations:
(Get-WebConfigurationProperty -filter /system.webServer/httpRedirect -name "destination" -PSPath 'IIS:\Sites\*').value
Upvotes: 4