Skip to content

Instantly share code, notes, and snippets.

@Swimburger
Created September 27, 2018 20:46
Show Gist options
  • Save Swimburger/c5ebdf7f9c5878d42ca24fb9efeaa0d4 to your computer and use it in GitHub Desktop.
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
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