Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

regex, replace and where....

$
0
0

Hello All,

I'm struggling with parsing an xml file of our DFSn environment. The issue (so far) is that PoSH falls over when parsing '&'. And the problem is that my original xml will contain strings that need to be corrected along with strings that don't....

An example of the xml I'm manipulating is:

<?xml version="1.0"?>

<Root xmlns = "http://schemas.microsoft.com/dfs/2007/03/dfsutil" majorVersion = "2" minorVersion = "0"
 Name="\\MyDFSn.my.domain.com\City" State="OK" Timeout="300" >
 <Target State="ONLINE" >\\MyDFSn.my.domain.com\City</Target>

<Link Name="data\obreggav" Comment="DFS link to homeshare for   Gavin    O&apos;Bren  " State="OK" Timeout="300" >
  <Target State="ONLINE" >\\MyServer.my.domain.com\data_MyServer_vol102\obregav</Target>
 </Link>
 <Link Name="DataShared\datagroup\stpf&amp;s" State="OK" Timeout="300" >
  <Target State="ONLINE" >\\OtherServer.my.otherdomain.com\shared4_OtherServer_vol304\stpf&s</Target>
 </Link>

</Root>

As you can see I need to only change the '&' in the last Link where it says 'stpf&s' BUT I need to leave all other instances of '&' as they are ('stpf&amp;s' and 'O&apos;Bren ')

How is the best / simplest way to do this?  I feel that I want to do a -replace or use the replace method of get-content (or something) AND where-object to separate '&amp;' -AND '&apos;' but I can't figure that out!

Any help would be very welcome :)

Many thanks

Tomsk

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles