Posted in
Hosting & IIS7,
Windows Powershell |
No Comment | 6,407 views | 16/12/2010 22:21
Powershell function to modify http errors in IIS7.
Function Modify-HttpErrors
{
Param ($Description, $StatusCode, $Path, $ResponseMode, $Action)
If ($Action -eq "Add")
{
Set-WebConfiguration -Filter /System.WebServer/HttpErrors/Error[@StatusCode=$StatusCode] -Value @{PrefixLanguageFilePath="$Null"; Path="$Path"; ResponseMode="$ResponseMode"} -PSPath IIS:\ -Location $Description
}
If ($Action -eq "Remove")
{
Set-WebConfiguration -Filter /System.WebServer/HttpErrors/Error[@StatusCode=$StatusCode] -Value @{PrefixLanguageFilePath="%SystemDrive%\inetpub\custerr"; Path="$StatusCode.html"; ResponseMode="File"} -PSPath IIS:\ -Location $Description
}
If ($Action -eq "Restore")
{
Clear-WebConfiguration -Filter /System.WebServer/HttpErrors/Error -PSPath IIS:\ -Location $Description
}
} |
Function Modify-HttpErrors
{
Param ($Description, $StatusCode, $Path, $ResponseMode, $Action)
If ($Action -eq "Add")
{
Set-WebConfiguration -Filter /System.WebServer/HttpErrors/Error[@StatusCode=$StatusCode] -Value @{PrefixLanguageFilePath="$Null"; Path="$Path"; ResponseMode="$ResponseMode"} -PSPath IIS:\ -Location $Description
}
If ($Action -eq "Remove")
{
Set-WebConfiguration -Filter /System.WebServer/HttpErrors/Error[@StatusCode=$StatusCode] -Value @{PrefixLanguageFilePath="%SystemDrive%\inetpub\custerr"; Path="$StatusCode.html"; ResponseMode="File"} -PSPath IIS:\ -Location $Description
}
If ($Action -eq "Restore")
{
Clear-WebConfiguration -Filter /System.WebServer/HttpErrors/Error -PSPath IIS:\ -Location $Description
}
}
StatusCode is the code name of error page, like 404.