#Created by P. Sukus #Modified by D. Dill #Name: mobile 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$\inetpub\logs\LogFiles\W3SVC1 | where {$_.LastWriteTime -gt $date} } Foreach ($l in $logfiles) { Write-host "Processing "$l.fullname Copy-item $l.fullname -Destination $pwd.path $palmusers += gc $l.name | where {$_ -match "DeviceType=Palm"} $iphoneusers += gc $l.name | where {$_ -match "DeviceType=iPhone"} Remove-Item $l.name } $iuser = @() $puser = @() foreach ($l in $iphoneusers | where {$_ -ne $null}) { $u = $l.split(" ")[7] if ($iuser -notcontains $u) { $iuser += "$u" } $u = $null } foreach ($l in $palmusers | where {$_ -ne $null}) { $u = $l.split(" ")[7] if ($puser -notcontains $u) { $puser += "$u" } $u = $null } $body = "" $body += "" $body += "" $body += "iPhone Users" $body += "" $body += "" $body += "" $body += "" $body += "" $body += "" foreach ($y in $iuser) { $body += "" } $body += "" $body += "
" $body += "" foreach ($y in $puser) { $body += "" } $body += "
iPhone Users
$y
Palm Users
$y
" $body += "
Audited servers: $servers
" $body += "Audited for: DeviceType=Palm and DeviceType=iPhone" $body += "" $smtpServer = "yourmailserver" $mailer = new-object Net.Mail.SMTPclient($smtpserver) $From = "dontreplyiamascript@domain.com" $To = "youremail@yourdomain.com" $subject = "Mobile 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) clear-variable logfiles clear-variable servers clear-variable daysold