I have an XML file (lets call it test.xml) where part of it looks like this
<export-error cs-guid="{11111C00-11A2-E411-80BB-002226874D89}" dn="CN=Doe\, John,OU=Billing,OU=Chicago,OU=IL,OU=US,DC=XYZ,DC=local">
There are a bunch of lines similar to this and the rest of the xml is stuff I don't care about.
How can I get the output to be just this:
"CN=Doe\, John,OU=Billing,OU=Chicago,OU=IL,OU=US,DC=XYZ,DC=local"
There are actually several Distinguished names I want out of that file. Basically grab the stuff betwee dn= and > symbol
I tried this select-string ./test.xml -pattern "dn" but it splits the output after the space into another line, and I only want the DN. I tried regular expressions, but I can't make regular expressions to save my butt.
This i what I have so far.
$input_path = './test.xml'
$output_file = './out.txt'
$regex = '[\dn=]{1}([A-Za-z.]*)[\>"]{1}'
select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
Can someone help me with the proper $regex line?