Update ** There is one problem with the script in this post in that its doesn't pick up the updates to the O/S as pointed out in http://www.hedonists.ca/2010/07/22/blocking-the-iphone-part-i. So the only 100% way would be to parse the IIS logs where you can grab the same information about the devices. I'll try to post a script that does parsing that should work on 2003 up. Thanks also to Dennis who sent another version of the script I've added to the download that give enhanced reporting** ** New scripted posted for IIS logs http://gsexdev.blogspot.com/2010/08/parsing-iis-log-activesync-traffic-for.html **
On January 9, 2007 Apple released their first iphone and unleashed on the world what is arguably one of the most successful user mobile devices on the planet (I'm not arguing technical merit here just end user experience). Kind of like a virus these phones have spread throughout corporations and into every nook and cranny some with the IT departments blessing others with their scorn. Whether you like or hate the devices if your in charge of managing an Exchange server it can be useful to see how many of these devices are out there and what version of the Apple IOS they are running. This can help you keep abreast of any issues or limitations these devices might impose on your users or server.
On Exchange 2007/2010 getting information about what devices have been registered via ActiveSync is exceeding easy thanks to the Get-ActiveSyncDeviceStatistics cmdlet. With this cmdlet there are two distinct properties that are of interest when trying to report on iPhones. The first is the DeviceType property which gets set to iPhone for any iPhone. The second is the DeviceUserAgent which holds information about what version of IOS is running on the phone and in the later versions of the IOS holds information about what type of iPhone it is (eg 3G,3GS,4 etc).
Now this is where we strike the first problem like all good software the version information that you can get out of the DeviceUserAgent doesn't relate directly to the version of IOS the phone is running so some parsing and translation is needed. This is where the good old Internet helps out firstly on Wikipedia all the IOS versions have been documented at http://en.wikipedia.org/wiki/Apple_iOS_version_history . So this page gives us a IOS version to SDK build version this still doesn't quite get us to what is being stored in the deviceUserAgent property this needs to be translated with a little more code which looks like
$inparray = $inputvar.Split(',')
$v1 = $inparray[1].Substring(0,1)
$v2 = $inparray[1].Substring(1,1)
$v3 = $inparray[1].Substring(2,($inparray[1].Length-2))
$useragent = "{0:D2}" -f (([int][char]$v2)-64)
essentially this reformats the alpha character to a numerical represntation from 0-26. This then allows the IOS version to be matched. The actually phone version seems to only work on later version of the IOS and I've based it on information from a few forum posts so this is a little imcomplete I also didn't really have any information on how the iPad appears so this script i dont think will detect one but Im intrested in any feedback anyone has about other devices or codes they notice.
So what the rest of the script does is basically using the Get-Mailbox and Get-ActiveSyncDeviceStatistics cmdlet is it enumerates all iPhones activesync registrations for all users and uses some custom objects to build a Html report and then send it to a nomintated email address configured in the following varibles via SMTP using the configured server.
$sendAlertTo = "user@domain.com"
$sendAlertFrom = "Senderfromaddress@domain.com"
$SMTPServer = "servername"
These three varibles need to be configured before you will get a result out of the script an alternate method to sending the report as an email is just to output the result to a HTML file using Out-file eg you would modify the script like
$appleCollection | ConvertTo-HTML -head $tableStyle –body $body | out-file c:\iphreport.htm
I've put a download of this script here the code itself looks like
$sendAlertTo = "user@domain.com"
$sendAlertFrom = "Senderfromaddress@domain.com"
$SMTPServer = "servername"
$appleCollection = @()
$appleverhash = @{ }
$hndSethash = @{ }
function addtoIOShash($inputvar){
$inparray = $inputvar.Split(',')
$v1 = $inparray[1].Substring(0,1)
$v2 = $inparray[1].Substring(1,1)
$v3 = $inparray[1].Substring(2,($inparray[1].Length-2))
$useragent = "{0:D2}" -f (([int][char]$v2)-64)
$apverobj = "" | select IOSVersion,IOSReleaseDate,ActiveSyncUserAgent,AppleBuildCode
$apverobj.IOSVersion = $inparray[0]
$apverobj.IOSReleaseDate = $inparray[2]
$apverobj.AppleBuildCode = $inparray[1]
$apverobj.ActiveSyncUserAgent = $v1 + $useragent + "." + $v3
$appleverhash.add($apverobj.ActiveSyncUserAgent,$apverobj)
}
#IOSVersion,Deviceid,ReleaseDate
addtoIOShash("1,1A543,Jun-07")
addtoIOShash("1.0.1,1C25,Jul-07")
addtoIOShash("1.0.2,1C28,Aug-07")
addtoIOShash("1.1,3A100,Sep-07")
addtoIOShash("1.1,3A101,Sep-07")
addtoIOShash("1.1.1,3A109,Sep-07")
addtoIOShash("1.1.1,3A110,Sep-07")
addtoIOShash("1.1.2 ,3B48,Nov-07")
addtoIOShash("1.1.3,4A93,Jan-08")
addtoIOShash("1.1.4,4A102,Feb-08")
addtoIOShash("1.1.5,4B1,Jul-08")
addtoIOShash("2,5A347,Jul-08")
addtoIOShash("2.0.1,5B108,Aug-08")
addtoIOShash("2.0.2,5C1,Aug-08")
addtoIOShash("2.1,5F136,Sep-08")
addtoIOShash("2.1,5F137,Sep-08")
addtoIOShash("2.1,5F138,Sep-08")
addtoIOShash("2.2,5G77,Nov-08")
addtoIOShash("2.2.1,5H11,Jan-09")
addtoIOShash("3,7A341,Jun-09")
addtoIOShash("3.0.1,7A400,Jul-09")
addtoIOShash("3.1,7C144,Sep-09")
addtoIOShash("3.1,7C145,Sep-09")
addtoIOShash("3.1,7C146,Sep-09")
addtoIOShash("3.1.2,7D11,Oct-09")
addtoIOShash("3.1.3,7E18,Feb-09")
addtoIOShash("3.2,7B367,Apr-10")
addtoIOShash("4.0,8A293,Jun-10")
$hndSethash.add("1C2","IPhone 3G")
$hndSethash.add("2C1","IPhone 3GS")
$hndSethash.add("3C1","IPhone 4")
Get-Mailbox -ResultSize Unlimited | ForEach-object {
$Mb = $_
Get-ActiveSyncDeviceStatistics -Mailbox:$_.Identity | foreach-object {
if($_.DeviceType -eq "iPhone"){
$userRepobj = "" | select UserName,emailAddress,IphoneType,IOSVersion,IOSReleaseDate,ActiveSyncUserAgent,ActiveSyncDeviceUserAgent,AppleBuildCode
if ($_.DeviceUserAgent -ne $null){
$apcode = $_.DeviceUserAgent
$userRepobj.ActiveSyncDeviceUserAgent = $_.DeviceUserAgent
$apcodearray = $apcode.split("/")
if ($apcodearray[0].length -gt 12){
$userRepobj.IphoneType = $hndSethash[$apcodearray[0].Substring(12,3)]
}
$userRepobj.IOSVersion = $appleverhash[$apcodearray[1]].IOSVersion
$userRepobj.IOSReleaseDate = $appleverhash[$apcodearray[1]].IOSReleaseDate
$userRepobj.ActiveSyncUserAgent = $appleverhash[$apcodearray[1]].ActiveSyncUserAgent
$userRepobj.AppleBuildCode = $appleverhash[$apcodearray[1]].AppleBuildCode
$userRepobj.UserName = $Mb.Name
$userRepobj.emailAddress = $Mb.WindowsEmailAddress
$appleCollection += $userRepobj
}
}
}
}
$tableStyle = @"
<style>
BODY{background-color:white;}
TABLE{border-width: 1px;
border-style: solid;
border-color: black;
border-collapse: collapse;
}
TH{border-width: 1px;
padding: 10px;
border-style: solid;
border-color: black;
background-color:#66CCCC
}
TD{border-width: 1px;
padding: 2px;
border-style: solid;
border-color: black;
background-color:white
}
</style>
"@
$body = @"
<p style="font-size:25px;family:calibri;color:#ff9100">
$TableHeader
</p>
"@
$SmtpClient = new-object system.net.mail.smtpClient
$SmtpClient.host = $SMTPServer
$MailMessage = new-object System.Net.Mail.MailMessage
$MailMessage.To.Add($sendAlertTo)
$MailMessage.From = $sendAlertFrom
$MailMessage.Subject = "iPhone Registrration Report"
$MailMessage.IsBodyHtml = $TRUE
$MailMessage.body = $appleCollection | ConvertTo-HTML -head $tableStyle –body $body
$SMTPClient.Send($MailMessage)
On January 9, 2007 Apple released their first iphone and unleashed on the world what is arguably one of the most successful user mobile devices on the planet (I'm not arguing technical merit here just end user experience). Kind of like a virus these phones have spread throughout corporations and into every nook and cranny some with the IT departments blessing others with their scorn. Whether you like or hate the devices if your in charge of managing an Exchange server it can be useful to see how many of these devices are out there and what version of the Apple IOS they are running. This can help you keep abreast of any issues or limitations these devices might impose on your users or server.
On Exchange 2007/2010 getting information about what devices have been registered via ActiveSync is exceeding easy thanks to the Get-ActiveSyncDeviceStatistics cmdlet. With this cmdlet there are two distinct properties that are of interest when trying to report on iPhones. The first is the DeviceType property which gets set to iPhone for any iPhone. The second is the DeviceUserAgent which holds information about what version of IOS is running on the phone and in the later versions of the IOS holds information about what type of iPhone it is (eg 3G,3GS,4 etc).
Now this is where we strike the first problem like all good software the version information that you can get out of the DeviceUserAgent doesn't relate directly to the version of IOS the phone is running so some parsing and translation is needed. This is where the good old Internet helps out firstly on Wikipedia all the IOS versions have been documented at http://en.wikipedia.org/wiki/Apple_iOS_version_history . So this page gives us a IOS version to SDK build version this still doesn't quite get us to what is being stored in the deviceUserAgent property this needs to be translated with a little more code which looks like
$inparray = $inputvar.Split(',')
$v1 = $inparray[1].Substring(0,1)
$v2 = $inparray[1].Substring(1,1)
$v3 = $inparray[1].Substring(2,($inparray[1].Length-2))
$useragent = "{0:D2}" -f (([int][char]$v2)-64)
essentially this reformats the alpha character to a numerical represntation from 0-26. This then allows the IOS version to be matched. The actually phone version seems to only work on later version of the IOS and I've based it on information from a few forum posts so this is a little imcomplete I also didn't really have any information on how the iPad appears so this script i dont think will detect one but Im intrested in any feedback anyone has about other devices or codes they notice.
So what the rest of the script does is basically using the Get-Mailbox and Get-ActiveSyncDeviceStatistics cmdlet is it enumerates all iPhones activesync registrations for all users and uses some custom objects to build a Html report and then send it to a nomintated email address configured in the following varibles via SMTP using the configured server.
$sendAlertTo = "user@domain.com"
$sendAlertFrom = "Senderfromaddress@domain.com"
$SMTPServer = "servername"
These three varibles need to be configured before you will get a result out of the script an alternate method to sending the report as an email is just to output the result to a HTML file using Out-file eg you would modify the script like
$appleCollection | ConvertTo-HTML -head $tableStyle –body $body | out-file c:\iphreport.htm
I've put a download of this script here the code itself looks like
$sendAlertTo = "user@domain.com"
$sendAlertFrom = "Senderfromaddress@domain.com"
$SMTPServer = "servername"
$appleCollection = @()
$appleverhash = @{ }
$hndSethash = @{ }
function addtoIOShash($inputvar){
$inparray = $inputvar.Split(',')
$v1 = $inparray[1].Substring(0,1)
$v2 = $inparray[1].Substring(1,1)
$v3 = $inparray[1].Substring(2,($inparray[1].Length-2))
$useragent = "{0:D2}" -f (([int][char]$v2)-64)
$apverobj = "" | select IOSVersion,IOSReleaseDate,ActiveSyncUserAgent,AppleBuildCode
$apverobj.IOSVersion = $inparray[0]
$apverobj.IOSReleaseDate = $inparray[2]
$apverobj.AppleBuildCode = $inparray[1]
$apverobj.ActiveSyncUserAgent = $v1 + $useragent + "." + $v3
$appleverhash.add($apverobj.ActiveSyncUserAgent,$apverobj)
}
#IOSVersion,Deviceid,ReleaseDate
addtoIOShash("1,1A543,Jun-07")
addtoIOShash("1.0.1,1C25,Jul-07")
addtoIOShash("1.0.2,1C28,Aug-07")
addtoIOShash("1.1,3A100,Sep-07")
addtoIOShash("1.1,3A101,Sep-07")
addtoIOShash("1.1.1,3A109,Sep-07")
addtoIOShash("1.1.1,3A110,Sep-07")
addtoIOShash("1.1.2 ,3B48,Nov-07")
addtoIOShash("1.1.3,4A93,Jan-08")
addtoIOShash("1.1.4,4A102,Feb-08")
addtoIOShash("1.1.5,4B1,Jul-08")
addtoIOShash("2,5A347,Jul-08")
addtoIOShash("2.0.1,5B108,Aug-08")
addtoIOShash("2.0.2,5C1,Aug-08")
addtoIOShash("2.1,5F136,Sep-08")
addtoIOShash("2.1,5F137,Sep-08")
addtoIOShash("2.1,5F138,Sep-08")
addtoIOShash("2.2,5G77,Nov-08")
addtoIOShash("2.2.1,5H11,Jan-09")
addtoIOShash("3,7A341,Jun-09")
addtoIOShash("3.0.1,7A400,Jul-09")
addtoIOShash("3.1,7C144,Sep-09")
addtoIOShash("3.1,7C145,Sep-09")
addtoIOShash("3.1,7C146,Sep-09")
addtoIOShash("3.1.2,7D11,Oct-09")
addtoIOShash("3.1.3,7E18,Feb-09")
addtoIOShash("3.2,7B367,Apr-10")
addtoIOShash("4.0,8A293,Jun-10")
$hndSethash.add("1C2","IPhone 3G")
$hndSethash.add("2C1","IPhone 3GS")
$hndSethash.add("3C1","IPhone 4")
Get-Mailbox -ResultSize Unlimited | ForEach-object {
$Mb = $_
Get-ActiveSyncDeviceStatistics -Mailbox:$_.Identity | foreach-object {
if($_.DeviceType -eq "iPhone"){
$userRepobj = "" | select UserName,emailAddress,IphoneType,IOSVersion,IOSReleaseDate,ActiveSyncUserAgent,ActiveSyncDeviceUserAgent,AppleBuildCode
if ($_.DeviceUserAgent -ne $null){
$apcode = $_.DeviceUserAgent
$userRepobj.ActiveSyncDeviceUserAgent = $_.DeviceUserAgent
$apcodearray = $apcode.split("/")
if ($apcodearray[0].length -gt 12){
$userRepobj.IphoneType = $hndSethash[$apcodearray[0].Substring(12,3)]
}
$userRepobj.IOSVersion = $appleverhash[$apcodearray[1]].IOSVersion
$userRepobj.IOSReleaseDate = $appleverhash[$apcodearray[1]].IOSReleaseDate
$userRepobj.ActiveSyncUserAgent = $appleverhash[$apcodearray[1]].ActiveSyncUserAgent
$userRepobj.AppleBuildCode = $appleverhash[$apcodearray[1]].AppleBuildCode
$userRepobj.UserName = $Mb.Name
$userRepobj.emailAddress = $Mb.WindowsEmailAddress
$appleCollection += $userRepobj
}
}
}
}
$tableStyle = @"
<style>
BODY{background-color:white;}
TABLE{border-width: 1px;
border-style: solid;
border-color: black;
border-collapse: collapse;
}
TH{border-width: 1px;
padding: 10px;
border-style: solid;
border-color: black;
background-color:#66CCCC
}
TD{border-width: 1px;
padding: 2px;
border-style: solid;
border-color: black;
background-color:white
}
</style>
"@
$body = @"
<p style="font-size:25px;family:calibri;color:#ff9100">
$TableHeader
</p>
"@
$SmtpClient = new-object system.net.mail.smtpClient
$SmtpClient.host = $SMTPServer
$MailMessage = new-object System.Net.Mail.MailMessage
$MailMessage.To.Add($sendAlertTo)
$MailMessage.From = $sendAlertFrom
$MailMessage.Subject = "iPhone Registrration Report"
$MailMessage.IsBodyHtml = $TRUE
$MailMessage.body = $appleCollection | ConvertTo-HTML -head $tableStyle –body $body
$SMTPClient.Send($MailMessage)