Skip to content

Commit 0966093

Browse files
authored
Merge pull request #193 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 116e6e1 + 1d1166a commit 0966093

File tree

6 files changed

+193
-11
lines changed

6 files changed

+193
-11
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
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using namespace System.Net
2+
3+
Function Invoke-ExecRenameAPDevice {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Endpoint.Autopilot.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
$APIName = $Request.Params.CIPPEndpoint
13+
$Headers = $Request.Headers
14+
Write-LogMessage -Headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
15+
$TenantFilter = $Request.Body.tenantFilter
16+
17+
18+
try {
19+
$DeviceId = $Request.Body.deviceId
20+
$SerialNumber = $Request.Body.serialNumber
21+
$DisplayName = $Request.Body.displayName
22+
23+
# Validation
24+
if ($DisplayName.Length -gt 15) {
25+
$ValidationError = 'Display name cannot exceed 15 characters.'
26+
} elseif ($DisplayName -notmatch '^[a-zA-Z0-9-]+$') {
27+
# This regex also implicitly checks for spaces
28+
$ValidationError = 'Display name can only contain letters (a-z, A-Z), numbers (0-9), and hyphens (-).'
29+
} elseif ($DisplayName -match '^\d+$') {
30+
$ValidationError = 'Display name cannot consist solely of numbers.'
31+
}
32+
33+
if ($null -ne $ValidationError) {
34+
$Result = "Validation failed: $ValidationError"
35+
$StatusCode = [HttpStatusCode]::BadRequest
36+
} else {
37+
# Validation passed, proceed with Graph API call
38+
$body = @{
39+
displayName = $DisplayName
40+
} | ConvertTo-Json
41+
42+
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities/$($DeviceId)/UpdateDeviceProperties" -tenantid $TenantFilter -body $body -method POST | Out-Null
43+
$Result = "Successfully renamed device '$($DeviceId)' with serial number '$($SerialNumber)' to '$($DisplayName)'"
44+
Write-LogMessage -Headers $User -API $APINAME -message $Result -Sev Info
45+
$StatusCode = [HttpStatusCode]::OK
46+
}
47+
} catch {
48+
$ErrorMessage = Get-CippException -Exception $_
49+
$Result = "Could not rename device '$($DeviceId)' with serial number '$($SerialNumber)' to '$($DisplayName)'. Error: $($ErrorMessage.NormalizedError)"
50+
Write-LogMessage -Headers $User -API $APINAME -message $Result -Sev Error -LogData $ErrorMessage
51+
$StatusCode = [HttpStatusCode]::BadRequest
52+
}
53+
54+
55+
# Associate values to output bindings by calling 'Push-OutputBinding'.
56+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
57+
StatusCode = $StatusCode
58+
Body = @{ Results = $Result }
59+
})
60+
61+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using namespace System.Net
2+
3+
Function Invoke-ExecSetAPDeviceGroupTag {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Endpoint.Autopilot.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
$APIName = $Request.Params.CIPPEndpoint
13+
$Headers = $Request.Headers
14+
Write-LogMessage -Headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
15+
$TenantFilter = $Request.Body.tenantFilter
16+
17+
try {
18+
$DeviceId = $Request.Body.deviceId
19+
$SerialNumber = $Request.Body.serialNumber
20+
$GroupTag = $Request.Body.groupTag
21+
22+
# Validation - GroupTag can be empty, but if provided, validate it
23+
if ($null -ne $GroupTag -and $GroupTag -ne '' -and $GroupTag.Length -gt 128) {
24+
$ValidationError = 'Group tag cannot exceed 128 characters.'
25+
}
26+
27+
if ($null -ne $ValidationError) {
28+
$Result = "Validation failed: $ValidationError"
29+
$StatusCode = [HttpStatusCode]::BadRequest
30+
} else {
31+
# Validation passed, proceed with Graph API call
32+
$body = @{
33+
groupTag = $GroupTag
34+
} | ConvertTo-Json
35+
36+
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities/$($DeviceId)/UpdateDeviceProperties" -tenantid $TenantFilter -body $body -method POST | Out-Null
37+
$Result = "Successfully updated group tag for device '$($DeviceId)' with serial number '$($SerialNumber)' to '$($GroupTag)'"
38+
Write-LogMessage -Headers $Headers -API $APIName -message $Result -Sev Info
39+
$StatusCode = [HttpStatusCode]::OK
40+
}
41+
} catch {
42+
$ErrorMessage = Get-CippException -Exception $_
43+
$Result = "Could not update group tag for device '$($DeviceId)' with serial number '$($SerialNumber)' to '$($GroupTag)'. Error: $($ErrorMessage.NormalizedError)"
44+
Write-LogMessage -Headers $Headers -API $APIName -message $Result -Sev Error -LogData $ErrorMessage
45+
$StatusCode = [HttpStatusCode]::BadRequest
46+
}
47+
48+
# Associate values to output bindings by calling 'Push-OutputBinding'.
49+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
50+
StatusCode = $StatusCode
51+
Body = @{ Results = $Result }
52+
})
53+
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ function Invoke-CIPPStandardDisableAddShortcutsToOneDrive {
3333

3434
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant | Select-Object _ObjectIdentity_, TenantFilter, DisableAddToOneDrive
3535

36-
if ($Settings.report -eq $true) {
37-
Set-CIPPStandardsCompareField -FieldName 'standards.DisableAddShortcutsToOneDrive' -FieldValue $CurrentState.DisableAddToOneDrive -TenantFilter $Tenant
38-
Add-CIPPBPAField -FieldName 'OneDriveAddShortcutButtonDisabled' -FieldValue $CurrentState.DisableAddToOneDrive -StoreAs bool -Tenant $Tenant
39-
}
40-
4136
# Input validation
4237
$StateValue = $Settings.state.value ?? $Settings.state
4338
if (([string]::IsNullOrWhiteSpace($StateValue) -or $StateValue -eq 'Select a value') -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {
@@ -49,6 +44,16 @@ function Invoke-CIPPStandardDisableAddShortcutsToOneDrive {
4944
$StateIsCorrect = if ($CurrentState.DisableAddToOneDrive -eq $WantedState) { $true } else { $false }
5045
$HumanReadableState = if ($WantedState -eq $true) { 'disabled' } else { 'enabled' }
5146

47+
if ($Settings.report -eq $true) {
48+
if ($StateIsCorrect -eq $true) {
49+
$FieldValue = $true
50+
} else {
51+
$FieldValue = $CurrentState | Select-Object -Property DisableAddToOneDrive
52+
}
53+
Set-CIPPStandardsCompareField -FieldName 'standards.DisableAddShortcutsToOneDrive' -FieldValue $FieldValue -TenantFilter $Tenant
54+
Add-CIPPBPAField -FieldName 'OneDriveAddShortcutButtonDisabled' -FieldValue $CurrentState.DisableAddToOneDrive -StoreAs bool -Tenant $Tenant
55+
}
56+
5257
If ($Settings.remediate -eq $true) {
5358
Write-Host 'Time to remediate'
5459

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)