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 .
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.
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.