Author Posts

December 21, 2017 at 4:50 pm

Hi

I need to transfer static routes from server to server .
If I get the old server routes by
Get-NetRoute |where {$_.RouteMetric -eq '1'} | FT DestinationPrefix,NextHop,RouteMetric | out-file c:\newroutes.txt

is this possible to add them to the new server by using New-NetRoute from the text file ?

or course any other way to make this migration is welcome .

Thanks

December 21, 2017 at 4:53 pm

First, if you're looking to transfer data, text is a terrible format. Don't use Format-Table – it discards there structure of the data. Just Export-CliXML. That maintains the structure of the data – the properties of the objects. You can Import-CliXML them to recreate the objects.

Text is lovely on Linux. Well, not really, but try to avoid text files as a means of data storage.

https://technet.microsoft.com/en-us/library/hh826148(v=wps.630).aspx describes which parameters New-NetRoute can accept from the pipeline (e.g., "Import-CliXML mydata.xml | New-NetRoute"). If you need it to use properties which don't accept pipeline input, then you'll have to ForEach it.

Import-CliXML whatever.xml |
ForEach-Object {
New-NetRoute -Parameter $_.Property -OtherParam $_.OtherProp
}

Within ForEach, $_ lets you access one object at a time from your CliXML file, so you can refer to the individual properties like RouteMetric and such.

December 24, 2017 at 8:15 am

Thanks Don

On source server :
Get-NetRoute |where {$_.RouteMetric -eq '1'} | export-CliXML c:\newroutes.xml

On Destination server :
Import-CliXML c:\newroutes.xml |
ForEach-Object {
New-NetRoute -DestinationPrefix $_.DestinationPrefix -NextHop $_.NextHop -RouteMetric $_.RouteMetric -InterfaceAlias $_.InterfaceAlias
}

Did the job