Skip to content

Commit 8a77197

Browse files
authored
Merge pull request KelvinTegelaar#1373 from kris6673/feat-lithold
2 parents 60c04fa + 360f226 commit 8a77197

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
function Invoke-ExecSetLitigationHold {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
.ROLE
6+
Exchange.Mailbox.ReadWrite
7+
#>
8+
[CmdletBinding()]
9+
param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
Write-LogMessage -Headers $Headers -API $APIName -tenant $TenantFilter -message 'Accessed this API' -Sev 'Debug'
14+
15+
# Interact with the query or body of the request
16+
$TenantFilter = $Request.Body.tenantFilter
17+
$LitHoldState = -not $Request.Body.disable -as [bool]
18+
$Identity = $Request.Body.Identity
19+
$UserPrincipalName = $Request.Body.UPN
20+
$Days = $Request.Body.days -as [int]
21+
22+
# Set the parameters for the EXO request
23+
$ExoRequest = @{
24+
tenantid = $TenantFilter
25+
cmdlet = 'Set-Mailbox'
26+
cmdParams = @{
27+
Identity = $Identity
28+
LitigationHoldEnabled = $LitHoldState
29+
}
30+
}
31+
32+
# Add the duration of the hold if specified
33+
if ($Days -ne 0 -and $LitHoldState -eq $true) {
34+
$ExoRequest.cmdParams['LitigationHoldDuration'] = $Days
35+
}
36+
37+
# Execute the EXO request
38+
try {
39+
$null = New-ExoRequest @ExoRequest
40+
$Results = "Litigation hold for $UserPrincipalName with Id $Identity has been set to $LitHoldState"
41+
if ($Days -ne 0 -and $LitHoldState -eq $true) {
42+
$Results += " for $Days days"
43+
}
44+
Write-LogMessage -API $APIName -tenant $TenantFilter -message $Results -sev Info
45+
$StatusCode = [HttpStatusCode]::OK
46+
} catch {
47+
$ErrorMessage = Get-CippException -Exception $_
48+
$Results = "Could not set litigation hold for $UserPrincipalName with Id $Identity to $LitHoldState. Error: $($ErrorMessage.NormalizedError)"
49+
Write-LogMessage -API $APIName -tenant $TenantFilter -message $Results -sev Error -LogData $ErrorMessage
50+
$StatusCode = [HttpStatusCode]::InternalServerError
51+
}
52+
53+
# Associate values to output bindings by calling 'Push-OutputBinding'.
54+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
55+
StatusCode = $StatusCode
56+
Body = @{ Results = $Results }
57+
})
58+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ListMailboxes.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Function Invoke-ListMailboxes {
1717
# Interact with query parameters or the body of the request.
1818
$TenantFilter = $Request.Query.tenantFilter
1919
try {
20-
$Select = 'id,ExchangeGuid,ArchiveGuid,UserPrincipalName,DisplayName,PrimarySMTPAddress,RecipientType,RecipientTypeDetails,EmailAddresses,WhenSoftDeleted,IsInactiveMailbox,ForwardingSmtpAddress,DeliverToMailboxAndForward,ForwardingAddress,HiddenFromAddressListsEnabled,ExternalDirectoryObjectId,MessageCopyForSendOnBehalfEnabled,MessageCopyForSentAsEnabled'
20+
$Select = 'id,ExchangeGuid,ArchiveGuid,UserPrincipalName,DisplayName,PrimarySMTPAddress,RecipientType,RecipientTypeDetails,EmailAddresses,WhenSoftDeleted,IsInactiveMailbox,ForwardingSmtpAddress,DeliverToMailboxAndForward,ForwardingAddress,HiddenFromAddressListsEnabled,ExternalDirectoryObjectId,MessageCopyForSendOnBehalfEnabled,MessageCopyForSentAsEnabled,PersistedCapabilities,LitigationHoldEnabled,LitigationHoldDate,LitigationHoldDuration'
2121
$ExoRequest = @{
2222
tenantid = $TenantFilter
2323
cmdlet = 'Get-Mailbox'
@@ -69,7 +69,12 @@ Function Invoke-ListMailboxes {
6969
HiddenFromAddressListsEnabled,
7070
ExternalDirectoryObjectId,
7171
MessageCopyForSendOnBehalfEnabled,
72-
MessageCopyForSentAsEnabled
72+
MessageCopyForSentAsEnabled,
73+
LitigationHoldEnabled,
74+
LitigationHoldDate,
75+
LitigationHoldDuration,
76+
@{ Name = 'LicensedForLitigationHold'; Expression = { ($_.PersistedCapabilities -contains 'BPOS_S_DlpAddOn' -or $_.PersistedCapabilities -contains 'BPOS_S_Enterprise') } }
77+
7378
$StatusCode = [HttpStatusCode]::OK
7479
} catch {
7580
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardEnableLitigationHold.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function Invoke-CIPPStandardEnableLitigationHold {
3030
param($Tenant, $Settings)
3131
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'EnableLitigationHold'
3232

33-
$MailboxesNoLitHold = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-Mailbox' -cmdparams @{ Filter = 'LitigationHoldEnabled -eq "False"' } -Select 'UserPrincipalName,PersistedCapabilities,LitigationHoldEnabled' | Where-Object { $_.PersistedCapabilities -contains 'BPOS_S_DlpAddOn' -or $_.PersistedCapabilities -contains 'BPOS_S_Enterprise' }
33+
$MailboxesNoLitHold = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-Mailbox' -cmdParams @{ Filter = 'LitigationHoldEnabled -eq "False"' } -Select 'UserPrincipalName,PersistedCapabilities,LitigationHoldEnabled' | Where-Object { $_.PersistedCapabilities -contains 'BPOS_S_DlpAddOn' -or $_.PersistedCapabilities -contains 'BPOS_S_Enterprise' }
3434

3535
if ($Settings.remediate -eq $true) {
3636
if ($null -eq $MailboxesNoLitHold) {
@@ -44,19 +44,19 @@ function Invoke-CIPPStandardEnableLitigationHold {
4444
Parameters = @{ Identity = $_.UserPrincipalName; LitigationHoldEnabled = $true }
4545
}
4646
}
47-
if ($Settings.days -ne $null) {
47+
if ($null -ne $Settings.days) {
4848
$params.CmdletInput.Parameters['LitigationHoldDuration'] = $Settings.days
4949
}
5050
$params
5151
}
5252

5353

54-
$BatchResults = New-ExoBulkRequest -tenantid $tenant -cmdletArray @($Request)
54+
$BatchResults = New-ExoBulkRequest -tenantid $Tenant -cmdletArray @($Request)
5555
$BatchResults | ForEach-Object {
5656
if ($_.error) {
5757
$ErrorMessage = Get-NormalizedError -Message $_.error
5858
Write-Host "Failed to Enable Litigation Hold for $($_.Target). Error: $ErrorMessage"
59-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to Enable Litigation Hold for $($_.Target). Error: $ErrorMessage" -sev Error
59+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to Enable Litigation Hold for $($_.Target). Error: $ErrorMessage" -sev Error
6060
}
6161
}
6262
} catch {

0 commit comments

Comments
 (0)