Skip to content

Commit

Permalink
Disbale email forward function
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Jul 17, 2023
1 parent 314ffcb commit 637842d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 1 addition & 5 deletions ExecDisableEmailForward/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ try {
$Username = $request.body.user
$Tenantfilter = $request.body.tenantfilter
$Results = try {
$OoO = New-ExoRequest -tenantid $TenantFilter -cmdlet "Set-Mailbox" -cmdParams @{Identity = $request.body.user; ForwardingAddress = $null; ForwardingSMTPAddress = $null; DeliverToMailboxAndForward = $false }
"Disabled Email forwarding $username"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Disabled Email forwarding $($username)" -Sev "Info" -tenant $TenantFilter

Set-CIPPForwarding -userid $Request.body.user -tenantFilter $TenantFilter -APIName $APINAME -ExecutingUser $request.headers.'x-ms-client-principal' -Forward $null -keepCopy $false -ForwardingSMTPAddress $null -Disable $true
}
catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Could not disable Email forwarding for $($username)" -Sev "Error" -tenant $TenantFilter
"Could not disable forwarding message for $($username). Error: $($_.Exception.Message)"
}

Expand Down
10 changes: 7 additions & 3 deletions Modules/CIPPCore/Public/Set-CIPPForwarding.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ function Set-CIPPForwarding {
[CmdletBinding()]
param(
$userid,
$forwardingSMTPAddress,
$tenantFilter,
$username,
$ExecutingUser,
$APIName = "Forwarding",
$Forward,
$KeepCopy
$KeepCopy,
$Disable
)

try {
$permissions = New-ExoRequest -tenantid $tenantFilter -cmdlet "Set-mailbox" -cmdParams @{Identity = $userid; ForwardingAddress = $Forward ; DeliverToMailboxAndForward = [bool]$KeepCopy } -Anchor $username
"Forwarding all email for $username to $Forward"
if (!$username) { $username = $userid }
$permissions = New-ExoRequest -tenantid $tenantFilter -cmdlet "Set-mailbox" -cmdParams @{Identity = $userid; ForwardingSMTPAddress = $forwardingSMTPAddress; ForwardingAddress = $Forward ; DeliverToMailboxAndForward = [bool]$KeepCopy } -Anchor $username
if (!$Disable) { "Forwarding all email for $username to $Forward" } else { "Disabled forwarding for $username" }

Write-LogMessage -user $ExecutingUser -API $APIName -message "Set Forwarding for $($username) to $Forward" -Sev "Info" -tenant $TenantFilter
}
catch {
Expand Down

0 comments on commit 637842d

Please sign in to comment.