列表重定向目标(URL)IIS站点
问题描述:
我有几个在IIS 8.5中配置的重定向站点,我想列出它们全部。我试过了:列表重定向目标(URL)IIS站点
.\appcmd.exe list site * -section:system.webServer/httpRedirect
但通配符不能正常工作,与appcmd
。我还从WebAdministration
模块尝试:
Get-WebConfiguration system.webServer/httpRedirect * | Get-Member destination
但是这也没有提供我所需要的...这是与2列的列表网站&目的地
答
这个片段会给你的网站名称和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
答
你可以参考下面的函数来解决这个问题。感谢 -
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
真棒下载! –
你好 - 虽然我很满意这个答案,我一直在使用它很久。在针对具有1000多个重定向的服务器运行这一小段代码时,我开始发生OOM错误。任何想法如何改善它,以便不会得到OOM错误? @阿济斯-PK –