Netflex Blog

powershell

Vraag ActiveSync Devices met een Exchange partnership op

Als u benieuwt bent welke devices uw medewerkers gebruiken om hun mail te synchroniseren kunt u onderstaand script gebruiken. Dit script exporteert de ActiveSync device gegevens naar een CSV file met o.a. het type device, het model, welk OS er op het desbetreffende device draait, de gebruiker van het device en of het device geblokkeerd is of niet.

Op deze manier heeft u inzicht in de verschillende ActiveSync devices.


# Show-ActiveSyncDevices.ps1
#
# Collects ActiveSync device information and saves it to a CSV-file.
#
# Created: 08-05-2014
# Created by: Michiel Elderson (Netflex)
#
# version: 1.0
#
# THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE
# RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.

#Set report path, add some headers and check for Exchange version
$Outfile="c:ScriptsReportsActiveSyncDevices.csv"
$PSSession= (Get-PSSession|select-objectcomputername|select-object-first1).computername
$exchangeserver= (get-exchangeserver$PSSession)
$ExchangeMajorVersion=$ExchangeServer.AdminDisplayVersion.Major
$ExchangeSPLevel=$ExchangeServer.AdminDisplayVersion.Minor

If (Test-Path$Outfile){
del$Outfile
}

$Header="DeviceType,FriendlyName,DeviceOS,DeviceModel,UserDisplayname,DeviceAccessState,DeviceActiveSyncVersion"
add-content-value$Header-path$Outfile

If ($ExchangeMajorVersion-eq14){
write-host"..Exchange 2010 detected"-foregroundcolorgreen
Write-Host"..Getting device list"-foregroundcolorgreen
$ASdevices=Get-ActiveSyncDevice | where {$_.UserDisplayName}
}

If ($ExchangeMajorVersion-eq15){
write-host"..Exchange 2013 detected"-foregroundcolorgreen
Write-Host"..Getting device list"-foregroundcolorgreen
$ASdevices=Get-MobileDevice | where {$_.UserDisplayName}
}

#Count total devices
$ASdevicecount=$ASdevices.count
$i=0

Foreach ($ASdevicein$ASdevices){
#Add Progress bar
$i=$i+1
$pct=$i/$ASdevicecount*100
Write-Progress-Activity"Collecting ActiveSync details"-Status"Processing device $i of $ASdevicecount - $ASdevice"-PercentComplete$pct

#Get device information
$DeviceType=$ASdevice.devicetype
$FriendlyName=$ASdevice.friendlyname
$DeviceOS=$ASdevice.deviceos
$DeviceModel=$ASdevice.devicemodel
$UserDisplayname=$ASdevice.userdisplayname
$DeviceAccessState=$ASdevice.deviceaccessstate
$DeviceActiveSyncVersion=$ASdevice.DeviceActiveSyncVersion

#Add information to report
$Outinfo=$DeviceType+","+$FriendlyName+","+$DeviceOS+","+$DeviceModel+","+$UserDisplayname+","+$DeviceAccessState+","+$DeviceActiveSyncVersion
add-content-value$Outinfo-path$Outfile

#Display current device/user on screen
$Username=$UserDisplayname.split('/')[$($UserDisplayname.split('/').count-1)]
Write-host"Processing device $username"-foregroundcolorwhite
}

 

Write-host"Report written to $Outfile"-foregroundcolorgreen

 

Gebruik:

Sla bovenstaand script op in Show-ActiveSyncDevices.ps1
Wijzig het path van de CSV file ($outfile = “D:ScriptsExchangeReportsActiveSyncDevices.csv”)
Draai het script in de Exchange Management Shell (EMS)

Het script is getest met Exchange 2010 en Exchange 2013.

Scroll to Top