Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved to Set-CIPPForwarding Function #923

Merged
merged 8 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ Function Invoke-ExecEmailForward {
$ForwardingSMTPAddress = $request.body.ForwardExternal
$DisableForwarding = $request.body.disableForwarding
$APIName = $TriggerMetadata.FunctionName
[bool]$KeepCopy = if ($request.body.keepCopy -eq "true") { $true } else { $false }

if ($ForwardingAddress) {
try {
New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-mailbox' -cmdParams @{Identity = $Username; ForwardingAddress = $ForwardingAddress ; DeliverToMailboxAndForward = [bool]$request.body.keepCopy } -Anchor $username
Set-CIPPForwarding -userid $username -tenantFilter $TenantFilter -APIName $APINAME -ExecutingUser $request.headers.'x-ms-client-principal' -Forward $ForwardingAddress -keepCopy $KeepCopy
if (-not $request.body.KeepCopy) {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Set Forwarding for $($username) to $($ForwardingAddress) and not keeping a copy" -Sev 'Info' -tenant $TenantFilter
$results = "Forwarding all email for $($username) to $($ForwardingAddress) and not keeping a copy"
} elseif ($request.body.KeepCopy) {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Set Forwarding for $($username) to $($ForwardingAddress) and keeping a copy" -Sev 'Info' -tenant $TenantFilter
$results = "Forwarding all email for $($username) to $($ForwardingAddress) and keeping a copy"
}
} catch {
Expand All @@ -36,12 +35,10 @@ Function Invoke-ExecEmailForward {

elseif ($ForwardingSMTPAddress) {
try {
New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-mailbox' -cmdParams @{Identity = $Username; ForwardingSMTPAddress = $ForwardingSMTPAddress ; DeliverToMailboxAndForward = [bool]$request.body.keepCopy } -Anchor $username
Set-CIPPForwarding -userid $username -tenantFilter $TenantFilter -APIName $APINAME -ExecutingUser $request.headers.'x-ms-client-principal' -forwardingSMTPAddress $ForwardingSMTPAddress -keepCopy $KeepCopy
if (-not $request.body.KeepCopy) {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Set forwarding for $($username) to $($ForwardingSMTPAddress) and not keeping a copy" -Sev 'Info' -tenant $TenantFilter
$results = "Forwarding all email for $($username) to $($ForwardingSMTPAddress) and not keeping a copy"
} elseif ($request.body.KeepCopy) {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Set forwarding for $($username) to $($ForwardingSMTPAddress) and keeping a copy" -Sev 'Info' -tenant $TenantFilter
$results = "Forwarding all email for $($username) to $($ForwardingSMTPAddress) and keeping a copy"
}
} catch {
Expand All @@ -54,8 +51,7 @@ Function Invoke-ExecEmailForward {

elseif ($DisableForwarding -eq 'True') {
try {
New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-Mailbox' -cmdParams @{Identity = $Username; ForwardingAddress = $null; ForwardingSMTPAddress = $null; DeliverToMailboxAndForward = $false }
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Disabled Email forwarding for $($username)" -Sev 'Info' -tenant $TenantFilter
Set-CIPPForwarding -userid $username -username $username -tenantFilter $Tenantfilter -ExecutingUser $ExecutingUser -APIName $APIName -Disable $true
$results = "Disabled Email Forwarding for $($username)"
} catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Could not disable Email forwarding for $($username)" -Sev 'Error' -tenant $TenantFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Invoke-ExecMailboxRestore {
$TenantFilter = $Request.Body.TenantFilter
$RequestName = $Request.Body.RequestName
$SourceMailbox = $Request.Body.SourceMailbox
$TargetMailbox = $Request.Body.TargetMailbox
$TargetMailbox = if (!$Request.Body.input) {$Request.Body.TargetMailbox} else {$Request.Body.input}

$ExoRequest = @{
tenantid = $TenantFilter
Expand Down
4 changes: 2 additions & 2 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-ListMailboxes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Function Invoke-ListMailboxes {
# Interact with query parameters or the body of the request.
$TenantFilter = $Request.Query.TenantFilter
try {
$Select = 'id,ExchangeGuid,ArchiveGuid,UserPrincipalName,DisplayName,PrimarySMTPAddress,RecipientType,RecipientTypeDetails,EmailAddresses'
$Select = 'id,ExchangeGuid,ArchiveGuid,UserPrincipalName,DisplayName,PrimarySMTPAddress,RecipientType,RecipientTypeDetails,EmailAddresses,WhenSoftDeleted'
$ExoRequest = @{
tenantid = $TenantFilter
cmdlet = 'Get-Mailbox'
Expand Down Expand Up @@ -57,7 +57,7 @@ Function Invoke-ListMailboxes {
}

Write-Host ($ExoRequest | ConvertTo-Json)
$GraphRequest = (New-ExoRequest @ExoRequest) | Select-Object id, ExchangeGuid, ArchiveGuid, @{ Name = 'UPN'; Expression = { $_.'UserPrincipalName' } },
$GraphRequest = (New-ExoRequest @ExoRequest) | Select-Object id, ExchangeGuid, ArchiveGuid, WhenSoftDeleted, @{ Name = 'UPN'; Expression = { $_.'UserPrincipalName' } },

@{ Name = 'displayName'; Expression = { $_.'DisplayName' } },
@{ Name = 'primarySmtpAddress'; Expression = { $_.'PrimarySMTPAddress' } },
Expand Down
6 changes: 5 additions & 1 deletion Modules/CIPPCore/Public/Invoke-CIPPOffboardingJob.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ function Invoke-CIPPOffboardingJob {
Set-CIPPOutOfOffice -tenantFilter $tenantFilter -userid $username -InternalMessage $Options.OOO -ExternalMessage $Options.OOO -ExecutingUser $ExecutingUser -APIName $APIName -state 'Enabled'
}
{ $_.'forward' -ne '' } {
Set-CIPPForwarding -userid $userid -username $username -tenantFilter $Tenantfilter -Forward $Options.forward -KeepCopy [bool]$Options.keepCopy -ExecutingUser $ExecutingUser -APIName $APIName
if (!$options.keepcopy) {
Set-CIPPForwarding -userid $userid -username $username -tenantFilter $Tenantfilter -Forward $Options.forward -ExecutingUser $ExecutingUser -APIName $APIName
} else {
Set-CIPPForwarding -userid $userid -username $username -tenantFilter $Tenantfilter -Forward $Options.forward -KeepCopy $Options.keepCopy -ExecutingUser $ExecutingUser -APIName $APIName
}
}
{ $_.'RemoveLicenses' -eq 'true' } {
Remove-CIPPLicense -userid $userid -username $Username -tenantFilter $Tenantfilter -ExecutingUser $ExecutingUser -APIName $APIName
Expand Down
18 changes: 12 additions & 6 deletions Modules/CIPPCore/Public/Set-CIPPForwarding.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ function Set-CIPPForwarding {
[bool]$Disable
)


try {
if (!$username) { $username = $userid }
if ($PSCmdlet.ShouldProcess($username, 'Set forwarding')) {
$null = New-ExoRequest -tenantid $tenantFilter -cmdlet 'Set-mailbox' -cmdParams @{Identity = $userid; ForwardingSMTPAddress = $forwardingSMTPAddress; ForwardingAddress = $Forward ; DeliverToMailboxAndForward = [bool]$KeepCopy } -Anchor $username
}
if (!$Disable) {
$Message = "Forwarding all email for $username to $Forward"
} else {
$Message = "Disabled forwarding for $username"
if ($Disable -eq $true) {
Write-Output "Disabling forwarding for $username"
$null = New-ExoRequest -tenantid $tenantFilter -cmdlet 'Set-mailbox' -cmdParams @{Identity = $userid; ForwardingSMTPAddress = $null; ForwardingAddress = $null ; DeliverToMailboxAndForward = $false } -Anchor $username
$Message = "Disabled forwarding for $username"
} elseif ($Forward) {
$null = New-ExoRequest -tenantid $tenantFilter -cmdlet 'Set-mailbox' -cmdParams @{Identity = $userid; ForwardingSMTPAddress = $null; ForwardingAddress = $Forward ; DeliverToMailboxAndForward = $KeepCopy } -Anchor $username
$Message = "Forwarding all email for $username to Internal Address $Forward and keeping a copy set to $KeepCopy"
} elseif ($forwardingSMTPAddress) {
$null = New-ExoRequest -tenantid $tenantFilter -cmdlet 'Set-mailbox' -cmdParams @{Identity = $userid; ForwardingSMTPAddress = $forwardingSMTPAddress; ForwardingAddress = $null ; DeliverToMailboxAndForward = $KeepCopy } -Anchor $username
$Message = "Forwarding all email for $username to External Address $ForwardingSMTPAddress and keeping a copy set to $KeepCopy"
}
}
Write-LogMessage -user $ExecutingUser -API $APIName -message $Message -Sev 'Info' -tenant $TenantFilter
return $Message
Expand Down
40 changes: 0 additions & 40 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4405,46 +4405,6 @@
}
}
},
"/ExecDisableEmailForward": {
"post": {
"description": "ExecDisableEmailForward",
"summary": "ExecDisableEmailForward",
"tags": [
"POST"
],
"parameters": [
{
"required": true,
"schema": {
"type": "string"
},
"name": "tenantfilter",
"in": "body"
},
{
"required": true,
"schema": {
"type": "string"
},
"name": "user",
"in": "body"
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"properties": {},
"type": "object"
}
}
},
"description": "Successful operation"
}
}
}
},
"/ExecEditCalendarPermissions": {
"get": {
"description": "ExecEditCalendarPermissions",
Expand Down