Skip to content

Commit

Permalink
refactor: exchange connection logic caveats outside the actual connec…
Browse files Browse the repository at this point in the history
…tion code
  • Loading branch information
GruberMarkus authored Mar 25, 2024
1 parent 7e34154 commit 02eb362
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/Export-RecipientPermissions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ try {
}

if ($x) {
$x = @($x | Select-Object -Property $($RecipientPropertiesExtended -join ', '))
$x = @($x | Select-Object -Property $RecipientPropertiesExtended)
$AllRecipients.AddRange(@($x))
Write-Host " $($x.count) recipients"
} else {
Expand Down Expand Up @@ -1232,53 +1232,52 @@ try {
Write-Host ' Migration mailboxes'
# Get-EXOMailbox misses several options (such as -Migration), so Get-Mailbox is still used for Exchange Online sometimes
$x = . ([scriptblock]::Create($ConnectExchange)) -ScriptBlock { Get-Mailbox -Migration -resultsize unlimited -ErrorAction Stop -WarningAction silentlycontinue }

if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $($RecipientPropertiesExtended -join ', '))) }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $RecipientPropertiesExtended)) }

if ($ExportFromOnPrem) {
Write-Host ' Arbitration mailboxes'
$x = . ([scriptblock]::Create($ConnectExchange)) -ScriptBlock { Get-Mailbox -Arbitration -resultsize unlimited -ErrorAction Stop -WarningAction silentlycontinue }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $($RecipientPropertiesExtended -join ', '))) }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $RecipientPropertiesExtended)) }

Write-Host ' AuditLog mailboxes'
$x = . ([scriptblock]::Create($ConnectExchange)) -ScriptBlock { Get-Mailbox -AuditLog -resultsize unlimited -ErrorAction Stop -WarningAction silentlycontinue }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $($RecipientPropertiesExtended -join ', '))) }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $RecipientPropertiesExtended)) }

Write-Host ' AuxAuditLog mailboxes'
$x = . ([scriptblock]::Create($ConnectExchange)) -ScriptBlock { Get-Mailbox -AuxAuditLog -resultsize unlimited -ErrorAction Stop -WarningAction silentlycontinue }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $($RecipientPropertiesExtended -join ', '))) }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $RecipientPropertiesExtended)) }

Write-Host ' Monitoring mailboxes'
$x = . ([scriptblock]::Create($ConnectExchange)) -ScriptBlock { Get-Mailbox -Monitoring -resultsize unlimited -ErrorAction Stop -WarningAction silentlycontinue }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $($RecipientPropertiesExtended -join ', '))) }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $RecipientPropertiesExtended)) }

Write-Host ' RemoteArchive mailboxes'
$x = . ([scriptblock]::Create($ConnectExchange)) -ScriptBlock { Get-Mailbox -RemoteArchive -resultsize unlimited -ErrorAction Stop -WarningAction silentlycontinue }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $($RecipientPropertiesExtended -join ', '))) }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $RecipientPropertiesExtended)) }
} else {
Write-Host ' Inactive mailboxes'
$x = . ([scriptblock]::Create($ConnectExchange)) -ScriptBlock { Get-EXOMailbox -InactiveMailboxOnly -PropertySets All -ResultSize unlimited -ErrorAction Stop -WarningAction silentlycontinue }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $($RecipientPropertiesExtended -join ', '))) }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $RecipientPropertiesExtended)) }

Write-Host ' Softdeleted mailboxes'
$x = . ([scriptblock]::Create($ConnectExchange)) -ScriptBlock { Get-EXOMailbox -SoftDeletedMailbox -PropertySets All -ResultSize unlimited -ErrorAction Stop -WarningAction silentlycontinue }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $($RecipientPropertiesExtended -join ', '))) }
if ($x) { $AllRecipients.AddRange(@($x | Select-Object -Property $RecipientPropertiesExtended)) }
}

Write-Host (' {0:0000000} total recipients found' -f $($AllRecipients.count))

Write-Host " Sort list by PrimarySmtpAddress @$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK')@"
$AllRecipients.TrimToSize()

$x = @($AllRecipients | Where-Object { $_.PrimarySmtpAddress } | Sort-Object -Property PrimarySmtpAddress)
$x = @(@($AllRecipients) | Where-Object { $_.PrimarySmtpAddress } | Sort-Object -Property PrimarySmtpAddress)

$AllRecipients.clear()
$AllRecipients.AddRange(@($x))
$x = $null
$AllRecipients.TrimToSize()

Write-Host ' Create lookup hashtables'
Write-Host " first character (lowercase) of name attribute for future wildcard searches @$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK')@"
Write-Host " First character (lowercase) of name attribute for future wildcard searches @$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK')@"
$WildcardSearchStrings = @(@(for ($x = 0; $x -lt $AllRecipients.count; $x++) { (-join $AllRecipients[$x].Name[0]).ToLower() }) | Select-Object -Unique)

Write-Host " DistinguishedName to recipients array index @$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK')@"
Expand Down

0 comments on commit 02eb362

Please sign in to comment.