Using PowerShell to parse Pidgin conversations

Your mileage will vary on the usefulness of this script, however I wanted to use PowerShell to let me know when a resource we track in Jabber was open. I set the MUC to persistent, and began by finding the latest conversation log file.

$path = Get-ChildItem $env:appData'\.purple\logs\jabber\'$env:userName'\[email protected]\' | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1

Next, we get the content and remove the HTML tags with it:

``Your mileage will vary on the usefulness of this script, however I wanted to use PowerShell to let me know when a resource we track in Jabber was open. I set the MUC to persistent, and began by finding the latest conversation log file.

$path = Get-ChildItem $env:appData'\.purple\logs\jabber\'$env:userName'\[email protected]\' | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1

Next, we get the content and remove the HTML tags with it:

``

Finally, we use some logic to determine if the resource is “open”, “on”, “closed”, or “off”. We then use the LastWriteTime and a New-TimeSpan to determine how long since the availability of the resource changed.

If ($content[-1] -match "on"){<br /> $timeelapsed = New-TimeSpan -Start $path.LastWriteTime -End (Get-Date)<br /> Write-Host -foregroundcolor Red "Game has been on for" $timeelapsed.Minutes"min"$timeelapsed.Seconds"sec."<br /> }<br /> ElseIf (($content[-1] -match "off") -or ($content[-1] -match "open")){<br /> $timeelapsed = New-TimeSpan -Start $path.LastWriteTime -End (Get-Date)<br /> Write-Host -foregroundcolor Green "Resource has been open for" $timeelapsed.Minutes"min"$timeelapsed.Seconds"sec."<br /> }<br /> Else{$content[-3,-2,-1]}<br /> If ($args[0] -eq "full"){$content[-3,-2,-1]}

The next logical steps might be to have it continuously monitor the file and perform some actions. Maybe send an email with an alert when the resource opens or closes.