Skip to content

Commit 1d223eb

Browse files
Merge pull request KelvinTegelaar#1392 from Zacgoose/dev
feat: Create Invoke-ExecSetRetentionHold function
2 parents 2fef3bc + 64c89bd commit 1d223eb

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function Invoke-ExecSetRetentionHold {
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+
$RetentionHoldState = -not $Request.Body.disable -as [bool]
18+
$Identity = $Request.Body.Identity
19+
$UserPrincipalName = $Request.Body.UPN
20+
21+
# Set the parameters for the EXO request
22+
$ExoRequest = @{
23+
tenantid = $TenantFilter
24+
cmdlet = 'Set-Mailbox'
25+
cmdParams = @{
26+
Identity = $Identity
27+
RetentionHoldEnabled = $RetentionHoldState
28+
}
29+
}
30+
31+
# Execute the EXO request
32+
try {
33+
$null = New-ExoRequest @ExoRequest
34+
$Results = "Retention hold for $UserPrincipalName with Id $Identity has been set to $RetentionHoldState"
35+
36+
Write-LogMessage -API $APIName -tenant $TenantFilter -message $Results -sev Info
37+
$StatusCode = [HttpStatusCode]::OK
38+
} catch {
39+
$ErrorMessage = Get-CippException -Exception $_
40+
$Results = "Could not set retention hold for $UserPrincipalName with Id $Identity to $RetentionHoldState. Error: $($ErrorMessage.NormalizedError)"
41+
Write-LogMessage -API $APIName -tenant $TenantFilter -message $Results -sev Error -LogData $ErrorMessage
42+
$StatusCode = [HttpStatusCode]::InternalServerError
43+
}
44+
45+
# Associate values to output bindings by calling 'Push-OutputBinding'.
46+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
47+
StatusCode = $StatusCode
48+
Body = @{ Results = $Results }
49+
})
50+
}

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

Lines changed: 2 additions & 1 deletion
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,PersistedCapabilities,LitigationHoldEnabled,LitigationHoldDate,LitigationHoldDuration,ComplianceTagHoldApplied,RetentionHoldEnabled'
20+
$Select = 'id,ExchangeGuid,ArchiveGuid,UserPrincipalName,DisplayName,PrimarySMTPAddress,RecipientType,RecipientTypeDetails,EmailAddresses,WhenSoftDeleted,IsInactiveMailbox,ForwardingSmtpAddress,DeliverToMailboxAndForward,ForwardingAddress,HiddenFromAddressListsEnabled,ExternalDirectoryObjectId,MessageCopyForSendOnBehalfEnabled,MessageCopyForSentAsEnabled,PersistedCapabilities,LitigationHoldEnabled,LitigationHoldDate,LitigationHoldDuration,ComplianceTagHoldApplied,RetentionHoldEnabled,InPlaceHolds'
2121
$ExoRequest = @{
2222
tenantid = $TenantFilter
2323
cmdlet = 'Get-Mailbox'
@@ -76,6 +76,7 @@ Function Invoke-ListMailboxes {
7676
@{ Name = 'LicensedForLitigationHold'; Expression = { ($_.PersistedCapabilities -contains 'BPOS_S_DlpAddOn' -or $_.PersistedCapabilities -contains 'BPOS_S_Enterprise') } },
7777
ComplianceTagHoldApplied,
7878
RetentionHoldEnabled,
79+
InPlaceHolds,
7980

8081
$StatusCode = [HttpStatusCode]::OK
8182
} catch {

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListUserMailboxDetails.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,50 @@ function Invoke-ListUserMailboxDetails {
177177
$TotalArchiveItemCount = try { [math]::Round($ArchiveSizeRequest.ItemCount, 2) } catch { 0 }
178178
}
179179

180+
# Parse InPlaceHolds to determine hold types if avaliable
181+
$InPlaceHold = $false
182+
$EDiscoveryHold = $false
183+
$PurviewRetentionHold = $false
184+
$ExcludedFromOrgWideHold = $false
185+
186+
# Check if InPlaceHolds property exists and has values
187+
if ($MailboxDetailedRequest.InPlaceHolds) {
188+
foreach ($hold in $MailboxDetailedRequest.InPlaceHolds) {
189+
# eDiscovery hold - starts with UniH
190+
if ($hold -like 'UniH*') {
191+
$EDiscoveryHold = $true
192+
}
193+
# In-Place Hold - no prefix or starts with cld
194+
# Check if it doesn't match any of the other known prefixes
195+
elseif (($hold -like 'cld*' -or
196+
($hold -notlike 'UniH*' -and
197+
$hold -notlike 'mbx*' -and
198+
$hold -notlike 'skp*' -and
199+
$hold -notlike '-mbx*'))) {
200+
$InPlaceHold = $true
201+
}
202+
# Microsoft Purview retention policy - starts with mbx or skp
203+
elseif ($hold -like 'mbx*' -or $hold -like 'skp*') {
204+
$PurviewRetentionHold = $true
205+
}
206+
# Excluded from organization-wide Microsoft Purview retention policy - starts with -mbx
207+
elseif ($hold -like '-mbx*') {
208+
$ExcludedFromOrgWideHold = $true
209+
}
210+
}
211+
}
212+
180213
# Build the GraphRequest object
181214
$GraphRequest = [ordered]@{
182215
ForwardAndDeliver = $MailboxDetailedRequest.DeliverToMailboxAndForward
183216
ForwardingAddress = $ForwardingAddress
184217
LitigationHold = $MailboxDetailedRequest.LitigationHoldEnabled
185218
RetentionHold = $MailboxDetailedRequest.RetentionHoldEnabled
186219
ComplianceTagHold = $MailboxDetailedRequest.ComplianceTagHoldApplied
220+
InPlaceHold = $InPlaceHold
221+
EDiscoveryHold = $EDiscoveryHold
222+
PurviewRetentionHold = $PurviewRetentionHold
223+
ExcludedFromOrgWideHold = $ExcludedFromOrgWideHold
187224
HiddenFromAddressLists = $MailboxDetailedRequest.HiddenFromAddressListsEnabled
188225
EWSEnabled = $CASRequest.EwsEnabled
189226
MailboxMAPIEnabled = $CASRequest.MAPIEnabled

0 commit comments

Comments
 (0)