How can I disable a URL Rewrite Rule using a Powershell Command? [Answered]RSS

1 reply

Last post Jul 11, 2013 12:38 PM by Rick Barber

  • How can I disable a URL Rewrite Rule using a Powershell Command?

    Jul 10, 2013 11:47 AM|AndiD|LINK

    Hello,

    I am aware that there is a solved forum entry. But since the solution does not work for me I have to open a new thread. I am afraid the other one isn't looked at anymore since it is published as solved.
    This is the thread:
    http://forums.iis.net/t/1173635.aspx/1?Scripting+Url+Rewrite+Rules+with+WebAdministration

    It says there:    You can also disable your rules by the command like:

    Set-WebconfigurationProperty '/system.webserver/rewrite/rules/rule[@name="YourRuleName"]' -Name enabled -Value false

    I tried to de-activate a rewrite rule on my server on the Default Web Site with the name "Redirect from blog" using your command above - no luck:

    Set-WebconfigurationProperty '/system.webserver/rewrite/rules/rule[@name="Redirect from blog"]' -Name enabled -Value false

    Instead, I get the following error message:

    WARNING: Target configuration object '/system.webserver/rewrite/rules/rule[@name="Redirect from blog"] is not found at path 'MACHINE/WEBROOT/APPHOST'.

    Do you have an idea of what went wrong?
    Obviously the rewrite rule is not where the system expects it. Where would I have to search for it or what in the command would I have to adapt?

    There are only a few sites on my machine and the rule that I want to disable is on the "Default Web Site".

    Thank you and regards

    Andi

     

  • Re: How can I disable a URL Rewrite Rule using a Powershell Command?

    Jul 11, 2013 12:38 PM|Rick Barber|LINK

    Hi Andi,

    That error indicates that PowerShell is looking at the wrong location for the rule.

    I'm still learning PowerShell myself but I found that this worked for me in testing.  I ran various tests with rules at the server level and site leven and was able to generate similar errors to what you provided depending on paths that I chose.  Try something like this:

    Import-module webadministration
    cd "iis:\sites\Default Web Site"
    set-webconfigurationproperty '/system.webserver/rewrite/rules/rule[@name="Redirect from blog"]' -Name enabled -Value false

    If you would like to do this from a single line, the following also works:

    set-webconfigurationproperty '/system.webserver/rewrite/rules/rule[@name="Redirect from blog"]' -Name enabled -Value false -PSPath "IIS:\sites\Default Web Site"

    The cool thing with PowerShell, like most scripting languages, is that there are usually more than one way to accomplish the same thing.

    Rick Barber

    OrcsWeb: Managed Windows Hosting Solutions
    "Remarkable Service. Remarkable Support."
    IIS Community Newsletter