Parsing CPUU EMWProf log files with PowerShell

I recently got asked if there was an easier way to gather the user, computer, and status information from the EMW Client Profile Updating Utility (EMWProf) log files. Sure you can go through each log file and parse it out.  Then I thought could this be easily done in PowerShell; it turns out very easily!

 


 

I’m planning to execute the script from the directory where the EMProf log files are created. The first thing we need to do is list all log files in the directory, and create an array.

# Get list of all log files in the current directory

$Files = Get-ChildItem -filter “*.log”

# Log array

$Log =@()

 


 

Next we need find the status information from each log file that was generated.

 

# Find username and status from each file
Foreach ($Item in $Files)

{
$user = $null
$status=$null
Write-Host”Working on”$Item

# Get file content
$FILE=GET-CONTENT$Item.Name

# Select second last line from the file (Status line)

$ProfileStatus=$FILE|Select-Object-Last2|Select-Object-First1
$LastLine=$FILE|Select-Object-Last1

# Select substring
If ($LastLine-notlike”*— END LOG —*”)

{
$Status=”FAILED – CHECK LOG FILE “+$LastLine.Substring($LastLine.IndexOf(“[“))

}

elseIf ($ProfileStatus-notlike”*[Info]*”)

{

$Status=”FAILED – CHECK LOG FILE “+$LastLine.Substring($LastLine.IndexOf(“[“))

$ProfileStatus=$lastline

}

elseIf ($ProfileStatus.LastIndexOf(“updated”) -eq’-1′)

{

$Status=”FAILED – CHECK LOG FILE    ”   +$ProfileStatus.Substring($ProfileStatus.IndexOf(“[“))

}

else

{

$Status=”COMPLETED             ”   +$ProfileStatus.Substring($ProfileStatus.IndexOf(“[Info]”))

}

# Remove period at the end of the line
$Status=$Status.Substring(0,$Status.LastIndexOf(“.”))

# Get date and time of log file
$TimeStamp=$ProfileStatus.Substring(0,$ProfileStatus.IndexOf(“M”)+6)

# Select 5th line from the log file (Username line)
$Username=$FILE|Select-Object-First5|Select-Object-Last1

#Select Substring

$User=$Username.Substring(($Username.IndexOf(“s”))+2)
$User=$User.Substring(0,$User.LastIndexOf(“.”))

# Select 4th line from the log file (Computer line)
$Computername=$FILE|Select-Object-First4|Select-Object-Last1

#Select Substring
$Computer=$Computername.Substring(($Computername.IndexOf(“: “))+2)
$Computer=$Computer.Substring(0,$Computer.LastIndexOf(“.”))

 


 

Finally we wanted to export this to a CSV and display it in GridView.

 

write-host $User – $Status – $TimeStamp – $Computer
# Add results to log
$LogObj = New-Object PSObject
$LogObj | add-member Noteproperty User       $User
$LogObj | add-member Noteproperty Workstation  $Computer
$LogObj | add-member Noteproperty Status     $Status
$LogObj | add-member Noteproperty TimeStamp  $TimeStamp
$LogObj | add-member Noteproperty LogFile    $Item.Name
$Log+=$LogObj
}

$Log | Out-GridView

$Log | Export-CSV Results.csv -notype
image-1_20131014-192954_1
This script will work with QMM 8.7 – 8.10 versions of Client Profile Updating Utility. However, future product releases may alter the EMWProf log file format.

Download ===> parsecpuulogs.zip