Created
March 6, 2015 01:54
-
-
Save bradymholt/3944ee0ffb2b42ccd41c to your computer and use it in GitHub Desktop.
Toggles IIS Rewrite rule on/off by setting 'enabled' attribute of a web.config rewrite rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ($computerName, $username, $password, $targetFile, $ruleName, $enabled) | |
trap | |
{ | |
write-output $_ | |
exit 1 | |
} | |
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force | |
$credentials = New-Object System.Management.Automation.PsCredential($username, $securePassword) | |
$ruleNode = "//rewrite/rules/rule[@name=""$ruleName""]" | |
Invoke-Command -ComputerName $computerName -Credential $credentials -ScriptBlock { | |
[xml] $xml = [xml](Get-Content $args[0] | Out-String) | |
$xml.SelectSingleNode($args[1]).enabled = $args[2] | |
$xml.Save($args[0]) | |
} -ArgumentList $targetFile, $ruleNode, $enabled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment