Skip to content

Commit b203424

Browse files
committed
feat: implement the function needed for manipulation lit holds
1 parent e16a412 commit b203424

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,45 @@
1414

1515
# Interact with the query or body of the request
1616
$TenantFilter = $Request.Body.tenantFilter
17-
$DisableLitHold = $Request.Body.disable -as [bool]
18-
Write-Host "TenantFilter: $TenantFilter"
19-
Write-Host "DisableLitHold: $DisableLitHold"
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]
2021

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+
}
2131

32+
# Add the duration of the hold if specified
33+
if ($Days -ne 0 -and $LitHoldState -eq $true) {
34+
$ExoRequest.cmdParams['LitigationHoldDuration'] = $Days
35+
}
2236

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+
})
2358
}

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

Lines changed: 4 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'
@@ -72,7 +72,9 @@ Function Invoke-ListMailboxes {
7272
MessageCopyForSentAsEnabled,
7373
LitigationHoldEnabled,
7474
LitigationHoldDate,
75-
LitigationHoldDuration
75+
LitigationHoldDuration,
76+
@{ Name = 'LicensedForLitigationHold'; Expression = { ($_.PersistedCapabilities -contains 'BPOS_S_DlpAddOn' -or $_.PersistedCapabilities -contains 'BPOS_S_Enterprise') } }
77+
7678
$StatusCode = [HttpStatusCode]::OK
7779
} catch {
7880
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message

0 commit comments

Comments
 (0)