Parse and return multiple strings from log files and export to .CSV file

Hi All, I'm trying to parse the following log file and output to a .CSV file.  The log file is created by a utility called ROIScan which is created by MS for Office reporting.

I need to search for "microsoft Visio" and exclude "Microsoft Visio viewer".  I was thinking something like this.

Get-ChildItem *.log | Select-String -Pattern "Microsoft Visio" | Select-String -Pattern -ne "Microsoft Visio Viewer".  Am i on the right track w/ this one?

If Visio is found, i need it then Parse the line from the log file, <License IsActive="TRUE", and list some of the data from this line as separate headers in a .CSV, such as "True", "Name", "Status Description".  I'm completely lost on this part.

Log File

Any examples or pointers would be helpful.  Thanks in advance.

June 29th, 2013 3:47am

Hi,

Do these log files always contain information on a single product? If not, can you please post another log file that has at least one other SKU node that isn't Visio?

Also, are the log files always XML?

Free Windows Admin Tool Kit Click here and download it now
June 29th, 2013 4:02am

That was fun, give this a try:

$xmlInput = Get-Content .\SDVMXP1-NP_ROIScan.xml
$xml = [xml]$xmlInput

$xml.OFFICEINVENTORY.SKU | ForEach {
    If ( $_.ProductName -like "Microsoft Visio*" -and $_.ProductName -ne "Microsoft Visio Viewer" ) {
        $_.LicenseData.License
    }
} | Export-Csv .\$($xmlInput.PSChildName[0])-Report.csv -NoTypeInformation

Bit of explanation:

The script reads in your XML log file and stores it in $xmlInput. An XML object, $xml, is then created from that input. The SKU nodes are then checked to see if the ProductName key meets your requirements. If so, the information from the License nodes are selected and then written to a CSV file that is based on the input log filename.


June 29th, 2013 4:40am

Hi Mike, thanks for the reply and sorry for the delay, i was out of the office.  I will def take a crack at this tomorrow and let you know how it goes.  I really appreciate the script, and the explanation.
Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2013 1:39am

Hi Mike, i was able to give his a shot, however i get the following error.  Any thoughts.

Cannot index into a null array.
At C:\Temp\ROIScan\Test.ps1:8 char:23
+ $xmlInput.PSChildName[ <<<< 0]
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray
 

July 2nd, 2013 6:57pm

It doesn't seem to like the way I'm naming the output file. Easiest way to get around this is to replace $($xmlInput.PSChildName[0])-Report.csv with Output.csv. The file will be overwritten each time you run the script though.
$xmlInput = Get-Content .\SDVMXP1-NP_ROIScan.xml
$xml = [xml]$xmlInput

$xml.OFFICEINVENTORY.SKU | ForEach {
    If ( $_.ProductName -like "Microsoft Visio*" -and $_.ProductName -ne "Microsoft Visio Viewer" ) {
        $_.LicenseData.License
    }
} | Export-Csv .\Output.csv -NoTypeInformation


Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2013 11:35pm

Hey Mike, that worked to pull the info from the log file that i specified.  So i changed the get-content path to \\servername\path\*.xml because i have a lot of .xml files to parse.

I was received the following error message below.  Thoughts?

Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space char

acters are allowed to appear before it. Line 101, position 3."

At C:\Temp\ROIScan\Test.ps1:2 char:22

+ $xml = [xml]$xmlInput <<<<

+ CategoryInfo : NotSpecified: (:) [], RuntimeException

+ FullyQualifiedErrorId : RuntimeException

July 3rd, 2013 3:30pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics