This commit is contained in:
Zack Meier
2026-04-15 15:42:41 -05:00
parent 74edcc4d9a
commit 03dba08135
146 changed files with 9119 additions and 1 deletions
+43
View File
@@ -0,0 +1,43 @@
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $M365Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
## Get All Devices and Mailboxes metadata, store in memory/variable
## Torey should verify I'm pulling ActiveSync devices correctly:
#$AllDevices = Get-MobileDevice # All Devices
$AllDevices = Get-MobileDevice -ActiveSync # Only ActiveSync I hope
$AllMailboxes = Get-Mailbox -ResultSize Unlimited
# Loop through each device, get a part of its identity, and match that identity part with a mailbox, 2400 devices took about 20 minutes to run
$result = @()
$count = 0
ForEach ($Device in $AllDevices) {
$count++
write-warning ($count.tostring() + '/' + $AllDevices.Count)
#clear loop variables
$Mailbox = $null
$DeviceDisplayName = $null
$ADUser = $null
$DeviceDisplayName = $Device.Identity.split('\')[0]
$Mailbox = $AllMailboxes | Where-Object DisplayName -eq $DeviceDisplayName
If($Mailbox){
$ADUser = Get-ADUser -Identity $Mailbox.PrimarySmtpAddress.split('@')[0] -Properties CanonicalName
}
# create custom object to show only information we want
$obj = [PSCustomObject]@{
DeviceDisplayName = $DeviceDisplayName;
DeviceAccessState = $Device.DeviceAccessState;
MailboxName = If($Mailbox){$Mailbox.Name};
PrimarySmtpAddress = If($Mailbox){$Mailbox.PrimarySmtpAddress};
Agency = If($Mailbox){$ADuser.CanonicalName.split('/')[1]};
DeviceFriendlyName = $Device.FriendlyName;
DeviceUserAgent = $Device.DeviceUserAgent;
}
# store new object in array
$result += $obj
}
Write-Output $result