-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-DeviceIDs_ForTenant.ps1
30 lines (24 loc) · 1.36 KB
/
Get-DeviceIDs_ForTenant.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<#
.Synopsis
This script will loop through all users in the tenant and RETRIEVE the status of each user's device ID (allowed to sync / blocked from syncing).
.DESCRIPTION
This script will loop through all users in the tenant, RETRIEVE the device ID's allowed/blocked to sync from each individual, and create a report
that will be located on the desktop. The script will also REMOVE ANY DUPLICATES with regards to the PrimarySmtpAddress property.
.EXAMPLE
.\Get-DeviceIDs_ForTenant.ps1
#>
#Connect to O365
$cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Write-Host "Connected to Exchange Online." -f Gray
Write-Host "Now processing... Be patient." -f Yellow
#Declare Variable
$Users = Get-CASMailbox
$OutputFile = "C:\users\$env:USERNAME\Desktop\Report_DeviceIDsForTenant.csv"
$Results = @()
foreach($user in $Users){
$Results += Get-CASMailbox -Identity $user.UserPrincipalName | select PrimarySmtpAddress, @{n='AllowedDeviceIDs';e={$_.ActiveSyncAllowedDeviceIDs -join ";"}},@{n='BlockedDeviceIDs';e={$_.ActiveSyncBlockedDeviceIDs -join ";"}}
}
$Results | Sort-Object -Unique -Property PrimarySmtpAddress | Export-Csv -Path $OutputFile -NoTypeInformation
Remove-PSSession $Session