3

我在 IIS 8.5 中配置了几个重定向站点,我想将它们全部列出。我试过了:

.\appcmd.exe list site * -section:system.webServer/httpRedirect

但通配符不适用于appcmd. 我也从WebAdministration模块中尝试过:

Get-WebConfiguration system.webServer/httpRedirect * | Get-Member destination

但这也没有提供我需要的东西......这是一个包含 2 列站点和目的地的列表

4

2 回答 2

4

此代码段将为您提供站点名称和 httpredirect 目的地:

Get-Website | select name,@{name='destination';e={(Get-WebConfigurationProperty -filter /system.webServer/httpRedirect -name "destination" -PSPath "IIS:\Sites\$($_.name)").value}}

仅获取目的地:

(Get-WebConfigurationProperty -filter /system.webServer/httpRedirect -name "destination" -PSPath 'IIS:\Sites\*').value
于 2017-06-20T12:29:35.620 回答
1

你可以参考下面的函数来解决这个问题。

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)" 
    } 
} 

有关完整的示例存档,请从如何通过 PowerShell 列出 IIS 站点的重定向目标 URL下载

于 2017-06-26T03:08:03.537 回答