forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e8d41f
commit aca4768
Showing
3 changed files
with
45 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAutoAddProxy.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function Invoke-CIPPStandardAutoAddProxy { | ||
param( | ||
$Tenant, | ||
$Settings, | ||
$QueueItem | ||
) | ||
|
||
if ($Settings.remediate -eq $true) { | ||
$Domains = New-ExoRequest -TenantId $Tenant -Cmdlet 'Get-AcceptedDomain' | Select-Object -ExpandProperty DomainName | ||
|
||
$AllMailboxes = New-ExoRequest -TenantId $Tenant -Cmdlet 'Get-Mailbox' | ||
foreach ($Domain in $Domains) { | ||
$ProcessMailboxes = $AllMailboxes | Where-Object { | ||
$addresses = @($_.EmailAddresses) -replace '^[^:]+:' # remove SPO:, SMTP:, etc. | ||
$hasDomain = $addresses | Where-Object { $_ -like "*@$Domain" } | ||
if ($hasDomain) { return $false } else { return $true } | ||
} | ||
|
||
$bulkRequest = foreach ($Mailbox in $ProcessMailboxes) { | ||
$LocalPart = $Mailbox.UserPrincipalName -split '@' | Select-Object -First 1 | ||
$NewAlias = "$LocalPart@$Domain" | ||
@{ | ||
CmdletInput = @{ | ||
CmdletName = 'Set-Mailbox' | ||
Parameters = @{Identity = $Mailbox.Identity ; EmailAddresses = @{ | ||
'@odata.type' = '#Exchange.GenericHashTable' | ||
Add = "smtp:$NewAlias" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
$BatchResults = New-ExoBulkRequest -tenantid $Tenant -cmdletArray @($bulkRequest) | ||
$BatchResults | ForEach-Object { | ||
if ($_.error) { | ||
$ErrorMessage = Get-CippException -Exception $_.error | ||
Write-Host "Failed to apply new email policy to $($_.target) Error: $($ErrorMessage.NormalizedError)" | ||
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to apply Delegate Sent Items Style to $($_.error.target) Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage | ||
} | ||
} | ||
} | ||
} | ||
} |