Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Removing Leading Zeros from IP Address in XML file w/ PowerShell

$
0
0

Hello all,

I am attempting to use PowerShell to get content from several XML files and remove any leading zeros that may exist in an IP address within the XML file.  For example an IP address may appear in the XML as (notice bolded octet):

<ServerLocation>\\192.0.01.101\config</serverLocation>

And I want the script to replace the 01 by dropping the leading 0 thus making the IP address:

<ServerLocation>\\192.0.1.101\config</ServerLocation>

I appear to be in some sort of wildcard/regular expression hell due to all the periods.  The following replace finds the correct text to replace, but I cannot get it to replace with the values I desire.

-replace "\.0.\.", ".\.\."

The left half of the replace statement finds exactly what I need to replace.  The right half replaces the text litterally so I end up with 192.0...101

Obviously I can just write 10 different replace statements that will account for every possibly situation, but I would rather have one super line of code that accounts for all.  Anyone think they can make this happen?  Open to other ideas as well.


















Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>