Audit iPhone Users by psukus 30 months ago
View followups from Dan Dill | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1280"></script>download | new post
This script is intended to use IIS logs to audit OWA logs for syncing of mail from an iPhone. In our environment this is an unauthorized device and needs to be audited. This script is not perfect, nor the prettiest thing in the world but it works. IIS logging must be on for this to work. email the results to yourself in $To varible. Have Fun!
- #Created by P. Sukus
- #Name: iPhone users syncing through OWA audit
- #set the timeframe to audit in days
- $Daysold = 1
- $Date = (get-date).adddays(-$daysold)
- $servers = "server1", "server2", "server3"
- foreach ($s in $servers)
- {
- Write-host -ForegroundColor Blue "Checking server $s for files from the last $daysold day(s)"
- $logfiles += gci -path \\$s\c$\windows\system32\logfiles\W3SVC1 | where {$_.LastWriteTime -gt $date}
- }
- Foreach ($l in $logfiles)
- {
- Write-host "Processing "$l.fullname
- Copy-item $l.fullname -Destination $pwd.path
- $listousers += gc $l.name | where {$_ -match "DeviceType="}
- Remove-Item $l.name
- }
- $user = @()
- foreach ($l in $listousers | where {$_ -ne $null})
- {
- $u = $l.split(" ")[8]
- if ($user -notcontains $u)
- {
- $user += "$u"
- }
- $u = $null
- }
- $body = "<!DOCTYPE html PUBLIC `"-//W3C//DTD XHTML 1.0 Strict//EN`" `"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd`">"
- $body += "<html xmlns=`"http://www.w3.org/1999/xhtml`">"
- $body += "<head>"
- $body += "<title>iPhone Users</title>"
- $body += "</head><body>"
- $body += "<table border=1>"
- $body += "<colgroup>"
- $body += "<col/>"
- $body += "</colgroup>"
- $body += "<tr><td><b>iPhone Users</b></td></tr>"
- foreach ($y in $user)
- {
- $body += "<tr><td>$y</td></tr>"
- }
- $body += "</table>"
- $body += "</body></html>"
- $smtpServer = "your.SMTPserver.here"
- $mailer = new-object Net.Mail.SMTPclient($smtpserver)
- $From = "iphoneusersync@company.internal"
- $To = "admin@company.internal"
- $subject = "iPhone users syncing through OWA in the last $daysold day(s)"
- $msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
- $msg.IsBodyHTML = $true
- $mailer.send($msg)
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository