SOLUTION
Thanks to Peter putting me on the right track, I was able to get this working and to help in the future these are the steps.
Install the URL Rewrite module into IIS, I created a dummy rule to I could see where the XML elements needed to go.
Create a CSV with the following headers: Name, Source, Target
Name has to be unique, the Source is the HTML page name and the Target is where you want the page to redirect to.
Create a PS1 file by copying the following:
$docTemplate = @'
<contact $($contacts -join "`n") />
'@
$entryTemplate = @'
<rule name="$($redirect.Name)" stopProcessing="true">
<match url="$($redirect.Source)" />
<action type="Redirect" url="$($redirect.Target)" redirectType="Permanent" />
</rule>
'@
Import-Csv C:\temp\Sites.csv -Delimiter ',' | Group-Object Id -ov grp | ForEach-Object {
$contacts = foreach ($Redirect in $_.Group) {
$ExecutionContext.InvokeCommand.ExpandString($entryTemplate)
}
$ExecutionContext.InvokeCommand.ExpandString($docTemplate) } |
Set-Content -LiteralPath file.xml
I did steal this from another Stackoverflow post (link) and modify it to fit my requirements, you can ignore the "contact" element, it needs to remain but isn't used.
When you run the PS1 file you will end up with a file called "file.XML" that you can then copy all the rules and paste them into the web.config file.
Warning, if you are doing lots of re-writes you will hit an issue with the web.config file being over 250k in size - results in a 500 error. To fix this you need to edit the registry and add a couple of keys to allow for a bigger web.config file:
Key1:
HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB
This is a DWORD, set the value to decimal and change the value to a bit larger then your web.config.
Key2:
HKLM\SOFTWARE\Wow6432Node\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB
Same as above, DWORD and set to a bit bigger than web.config file.
Finally do a IISRESET to pickup the changes.
Cheers
Rob