【问题标题】:list redirect destinations (URL) IIS sites列出重定向目标 (URL) IIS 站点
【发布时间】:2017-06-20 11:13:53
【问题描述】:

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

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

但通配符不适用于appcmd。我还尝试了WebAdministration 模块:

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

但这也不能满足我的需求...这是一个包含 2 列站点和目的地的列表

【问题讨论】:

    标签: powershell iis appcmd web-administration


    【解决方案1】:

    这个 sn-p 将为您提供站点名称和 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
    

    【讨论】:

    • 你好 - 虽然我很感谢这个答案并且我已经使用了很长时间。在针对具有 1000 多个重定向的服务器运行这段小代码时,我开始出现 OOM 错误。有什么想法可以改进它以避免出现 OOM 错误吗? @abhijith-pk
    【解决方案2】:

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

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

    完整的示例存档,请从How to list redirect destination URLs of IIS sites by PowerShell下载

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-30
      • 2018-07-15
      • 1970-01-01
      • 2023-01-20
      • 2021-04-17
      • 2017-07-29
      • 2020-04-09
      • 2012-01-15
      相关资源
      最近更新 更多