Skip to content

Instantly share code, notes, and snippets.

@bradymholt
Created March 6, 2015 01:54
Show Gist options
  • Save bradymholt/3944ee0ffb2b42ccd41c to your computer and use it in GitHub Desktop.
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
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