Created
September 27, 2018 20:46
-
-
Save Swimburger/c5ebdf7f9c5878d42ca24fb9efeaa0d4 to your computer and use it in GitHub Desktop.
PowerShell script to generate Rewrite Maps config files based on as CSV file
This file contains 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([string] $csvPath, [string] $configOutputPath, [string] $rewriteMapName) | |
$csv = Import-Csv -Delimiter ";" -Path $csvPath | |
$xml = New-Object -TypeName XML | |
$xml.Load($configOutputPath) | |
$rewriteMap = Select-XML -Xml $xml -XPath "//rewriteMap[@name='$rewriteMapName']" | |
$rewriteMap.Node.SelectNodes('//add') | ForEach { $_.ParentNode.RemoveChild($_) } | Out-Null | |
foreach($redirectLine in $csv){ | |
$newRedirect = $xml.CreateElement("add") | |
$newRedirect.SetAttribute("key", $redirectLine.from) | |
$newRedirect.SetAttribute("value", $redirectLine.to) | |
$rewriteMap.Node.AppendChild($newRedirect) | Out-Null | |
} | |
$xml.Save($configOutputPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment