Thursday, December 12, 2013

Powershell to insert at start of line and end of line

When I was creating the post Facebook Domain Name Sets for ISA I needed to insert data at the start and end of a line.  I used powershell to do this, and this is what I came up with:
Get-Content DNSList.txt | ForEach-Object {“%PREPEND%”+$_+”%APPEND%”}
DNSList.txt contains a list of text;
%PREPEND% is the data to add at the start of the line;
%APPEND% is the data to add to the end of the line.
In the Facebook ISA example, the actual code was (one line):
Get-Content | list.txt | ForEach-Obect {“<fpc4:Str dt:dt=`”string`”>*.”+$_”</fpc4:Str> “}
Notice the backticks infront of the “string” component.  This is to escape the quote marks to allow them to be included.
The output can be pasted into the relevant XML file and imported into ISA.

No comments:

Post a Comment