Я пытаюсь создать сценарий, который будет проверять веб-сервер нашего клиента и определять, будут ли они использовать какое-либо перенаправление IIS, которое может вызывать проблемы. Это было проблемой для нас много раз, и количество виртуальных каталогов делает эту задачу чрезвычайно утомительной. Итак, я придумал этот скрипт, который, казалось, работал КРАСОТНО:
clear-host
#Import the WebAdministration Module
Import-Module WebAdministration
#Determine if Default Website is redirecting
write-host "Determining if redirects are enabled on the default website" -BackgroundColor DarkCyan
$root = "IIS:\Sites"
$all = get-childitem($root)
$all |
foreach{
$fold_name = $_.name
$cur_path = "$root" + "\" + "$fold_name"
$enable = (get-webconfigurationproperty -filter /system.webserver/httpRedirect -PSPath "$cur_path"-name enabled).value
If ($enable -eq $true)
{
$dest = (get-webconfigurationproperty -filter /system.webserver/httpRedirect -PSPath "$cur_path"-name destination).value
write-host $fold_name is redirected to $dest
}
else{
write-host "There is no redirect enabled on $fold_name"}
}
#Determine if redirect enabled on Virtual Directories
write-host "Determining if redirects are enabled on any virtual directories" -BackgroundColor DarkCyan
$Subroot = "IIS:\Sites\Default Web Site"
$Suball = get-childitem($Subroot)
$Suball |
foreach{
$Subfold_name = $_.name
$Subcur_path = "$Subroot" + "\" + "$Subfold_name"
$Subenable = (get-webconfigurationproperty -filter /system.webserver/httpRedirect -PSPath "$Subcur_path"-name enabled).value
If ($Subenable -eq $true)
{
$Subdest = (get-webconfigurationproperty -filter /system.webserver/httpRedirect -PSPath "$Subcur_path"-name destination).value
If ($Subdest -ne $dest)
{
write-host "$Subfold_name is redirected to $Subdest"}
}}
#End the script
write-host "Query complete. If any redirects exists they are listed above" -BackgroundColor DarkCyan
Pause
Я попробовал его на нескольких серверах, и он работал отлично ... Потом я сел на один и начал заливаться красным ...
get-webconfigurationproperty : Filename: \\?\E:\Folder\Subfolder\web.config
Line number: 13
Error: There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined
At E:\Scripts\IISRedirectCheck.ps1:49 char:18
+ $Subdest = (get-webconfigurationproperty -filter /system.webserver/httpRedi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WebConfigurationProperty], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.GetConfigurationPropertyCommand
Он указывает на строку 49, которая:
$Subdest = (get-webconfigurationproperty -filter /system.webserver/httpRedirect -PSPath "$Subcur_path"-name destination).value
Когда я тестирую $ Subdest, он возвращает значение без ошибки, поэтому я не уверен, что не так с этой строкой ... У кого-нибудь есть идеи?