Skip to content

Commit 0d99203

Browse files
authored
Merge pull request #246 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 10c68c8 + 1efed26 commit 0d99203

12 files changed

+211
-23
lines changed

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ListMailboxRulesQueue.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Push-ListMailboxRulesQueue {
2626
Rules = [string]($Rule | ConvertTo-Json)
2727
RowKey = [string](New-Guid).guid
2828
Tenant = [string]$domainName
29-
PartitionKey = 'mailboxrules'
29+
PartitionKey = 'MailboxRules'
3030
}
3131

3232
}
@@ -38,7 +38,7 @@ function Push-ListMailboxRulesQueue {
3838
Rules = [string]$Rules
3939
RowKey = [string]$domainName
4040
Tenant = [string]$domainName
41-
PartitionKey = 'mailboxrules'
41+
PartitionKey = 'MailboxRules'
4242
}
4343
}
4444
} catch {
@@ -49,7 +49,7 @@ function Push-ListMailboxRulesQueue {
4949
Rules = [string]$Rules
5050
RowKey = [string]$domainName
5151
Tenant = [string]$domainName
52-
PartitionKey = 'mailboxrules'
52+
PartitionKey = 'MailboxRules'
5353
}
5454
}
5555
Add-CIPPAzDataTableEntity @Table -Entity $GraphRequest -Force | Out-Null

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,24 @@ Function Invoke-ListMailboxRules {
2222
$Table.Filter = "Tenant eq '$TenantFilter'"
2323
}
2424
$Rows = Get-CIPPAzDataTableEntity @Table | Where-Object -Property Timestamp -GT (Get-Date).AddHours(-1)
25+
$PartitionKey = 'MailboxRules'
26+
$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
27+
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
2528

2629
$Metadata = @{}
27-
if (!$Rows -or ($TenantFilter -eq 'AllTenants' -and ($Rows | Measure-Object).Count -eq 1)) {
30+
# If a queue is running, we will not start a new one
31+
if ($RunningQueue) {
2832
$Metadata = [PSCustomObject]@{
29-
QueueMessage = 'Loading data. Please check back in 1 minute'
33+
QueueMessage = "Still loading data for $TenantFilter. Please check back in a few more minutes"
34+
}
35+
[PSCustomObject]@{
36+
Waiting = $true
37+
}
38+
} elseif ((!$Rows -and !$RunningQueue) -or ($TenantFilter -eq 'AllTenants' -and ($Rows | Measure-Object).Count -eq 1)) {
39+
# If no rows are found and no queue is running, we will start a new one
40+
$Metadata = [PSCustomObject]@{
41+
QueueMessage = "Loading data for $TenantFilter. Please check back in 1 minute"
3042
}
31-
$GraphRequest = @()
3243

3344
if ($TenantFilter -eq 'AllTenants') {
3445
$Tenants = Get-Tenants -IncludeErrors | Select-Object defaultDomainName
@@ -37,7 +48,7 @@ Function Invoke-ListMailboxRules {
3748
$Tenants = @(@{ defaultDomainName = $TenantFilter })
3849
$Type = $TenantFilter
3950
}
40-
$Queue = New-CippQueueEntry -Name "Mailbox Rules ($Type)" -TotalTasks ($Tenants | Measure-Object).Count
51+
$Queue = New-CippQueueEntry -Name "Mailbox Rules ($Type)" -Reference $QueueReference -TotalTasks ($Tenants | Measure-Object).Count
4152
$Batch = $Tenants | Select-Object defaultDomainName, @{Name = 'FunctionName'; Expression = { 'ListMailboxRulesQueue' } }, @{Name = 'QueueName'; Expression = { $_.defaultDomainName } }, @{Name = 'QueueId'; Expression = { $Queue.RowKey } }
4253
if (($Batch | Measure-Object).Count -gt 0) {
4354
$InputObject = [PSCustomObject]@{
@@ -53,6 +64,7 @@ Function Invoke-ListMailboxRules {
5364
} else {
5465
if ($TenantFilter -ne 'AllTenants') {
5566
$Rows = $Rows | Where-Object -Property Tenant -EQ $TenantFilter
67+
$Rows = $Rows
5668
}
5769
$GraphRequest = $Rows | ForEach-Object {
5870
$NewObj = $_.Rules | ConvertFrom-Json -ErrorAction SilentlyContinue
@@ -61,6 +73,8 @@ Function Invoke-ListMailboxRules {
6173
}
6274
}
6375

76+
# If no results are found, we will return an empty message to prevent null reference errors in the frontend
77+
$GraphRequest = $GraphRequest ?? @()
6478
$Body = @{
6579
Results = @($GraphRequest)
6680
Metadata = $Metadata

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,27 @@ Function Invoke-ExecRestoreDeleted {
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

1717
# Interact with query parameters or the body of the request.
18-
$TenantFilter = $Request.Query.TenantFilter ?? $Request.Body.TenantFilter
18+
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
1919
$RequestID = $Request.Query.ID ?? $Request.Body.ID
20+
$UserPrincipalName = $Request.Body.userPrincipalName
21+
$DisplayName = $Request.Body.displayName
2022

2123
try {
2224
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/v1.0/directory/deletedItems/$($RequestID)/restore" -tenantid $TenantFilter -type POST -body '{}' -Verbose
23-
$Result = "Successfully restored deleted item with ID: $($RequestID)"
24-
Write-LogMessage -headers $Request.Headers -tenant $TenantFilter -API $APIName -message $Result -Sev 'Info'
25+
$Result = "Successfully restored deleted item with ID: '$($RequestID)'"
26+
if ($UserPrincipalName) { $Result += " User Principal Name: '$($UserPrincipalName)'" }
27+
if ($DisplayName) { $Result += " Display Name: '$($DisplayName)'" }
28+
29+
Write-LogMessage -headers $Headers -tenant $TenantFilter -API $APIName -message $Result -Sev 'Info'
2530
$StatusCode = [HttpStatusCode]::OK
2631
} catch {
2732
$ErrorMessage = Get-CippException -Exception $_
28-
$Result = "Failed to restore deleted item with ID: $($RequestID). Error: $($ErrorMessage.NormalizedError)"
29-
Write-LogMessage -headers $Request.Headers -tenant $TenantFilter -API $APIName -message $Result -Sev 'Error' -LogData $ErrorMessage
33+
$Result = "Failed to restore deleted item with ID: '$($RequestID)'"
34+
if ($UserPrincipalName) { $Result += " User Principal Name: '$($UserPrincipalName)'" }
35+
if ($DisplayName) { $Result += " Display Name: '$($DisplayName)'" }
36+
$Result += " Error: $($ErrorMessage.NormalizedError)"
37+
38+
Write-LogMessage -headers $Headers -tenant $TenantFilter -API $APIName -message $Result -Sev 'Error' -LogData $ErrorMessage
3039
$StatusCode = [HttpStatusCode]::InternalServerError
3140
}
3241

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Function Invoke-ListDeletedItems {
1616
Write-LogMessage -Headers $Headers -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1717

1818
# Interact with query parameters or the body of the request.
19-
$Types = 'Application', 'User', 'Device', 'Group'
19+
$Types = 'Application', 'User', 'Group'
2020
$GraphRequest = foreach ($Type in $Types) {
2121
(New-GraphGetRequest -uri "https://graph.microsoft.com/beta/directory/deletedItems/microsoft.graph.$($Type)" -tenantid $TenantFilter) |
2222
Where-Object -Property '@odata.context' -NotLike '*graph.microsoft.com*' |
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using namespace System.Net
2+
3+
Function Invoke-RemoveDeletedObject {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Tenant.Directory.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $Request.Params.CIPPEndpoint
14+
$Headers = $Request.Headers
15+
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
16+
17+
# Interact with query parameters or the body of the request.
18+
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
19+
$RequestID = $Request.Query.ID ?? $Request.Body.ID
20+
$UserPrincipalName = $Request.Body.userPrincipalName
21+
$DisplayName = $Request.Body.displayName
22+
23+
try {
24+
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/v1.0/directory/deletedItems/$($RequestID)" -tenantid $TenantFilter -type DELETE -body '{}' -Verbose
25+
$Result = "Successfully permanently deleted item with ID: '$($RequestID)'"
26+
if ($UserPrincipalName) { $Result += " User Principal Name: '$($UserPrincipalName)'" }
27+
if ($DisplayName) { $Result += " Display Name: '$($DisplayName)'" }
28+
29+
Write-LogMessage -headers $Headers -tenant $TenantFilter -API $APIName -message $Result -Sev 'Info'
30+
$StatusCode = [HttpStatusCode]::OK
31+
} catch {
32+
$ErrorMessage = Get-CippException -Exception $_
33+
$Result = "Failed to permanently delete item with ID: $($RequestID)"
34+
if ($UserPrincipalName) { $Result += " User Principal Name: '$($UserPrincipalName)'" }
35+
if ($DisplayName) { $Result += " Display Name: '$($DisplayName)'" }
36+
$Result += " Error: $($ErrorMessage.NormalizedError)"
37+
38+
Write-LogMessage -headers $Headers -tenant $TenantFilter -API $APIName -message $Result -Sev 'Error' -LogData $ErrorMessage
39+
$StatusCode = [HttpStatusCode]::InternalServerError
40+
}
41+
42+
$Results = [pscustomobject]@{'Results' = $Result }
43+
# Associate values to output bindings by calling 'Push-OutputBinding'.
44+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
45+
StatusCode = $StatusCode
46+
Body = $Results
47+
})
48+
49+
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ Function Invoke-RemoveUser {
1717
# Interact with query parameters or the body of the request.
1818
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
1919
$UserID = $Request.Query.ID ?? $Request.Body.ID
20+
$UserPrincipalName = $Request.Query.userPrincipalName ?? $Request.Body.userPrincipalName
2021

2122
if (!$UserID) { exit }
2223
try {
2324
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($UserID)" -type DELETE -tenant $TenantFilter
24-
$Result = "Successfully deleted $UserID."
25+
$Result = "Successfully deleted user with ID: '$UserID'"
26+
if ($UserPrincipalName) { $Result += " and User Principal Name: '$UserPrincipalName'" }
2527
Write-LogMessage -Headers $Headers -API $APIName -message $Result -Sev 'Info' -tenant $TenantFilter
2628
$StatusCode = [HttpStatusCode]::OK
2729

2830
} catch {
2931
$ErrorMessage = Get-CippException -Exception $_
30-
$Result = "Could not delete user $($UserID). $($ErrorMessage.NormalizedError)"
32+
$Result = "Failed to delete user $($UserID). $($ErrorMessage.NormalizedError)"
33+
if ($UserPrincipalName) { $Result += " User Principal Name: '$($UserPrincipalName)'" }
3134
Write-LogMessage -Headers $Headers -API $APIName -message $Result -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
3235
$StatusCode = [HttpStatusCode]::InternalServerError
3336
}

Modules/CIPPCore/Public/Entrypoints/Invoke-ListTenantAllowBlockList.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Function Invoke-ListTenantAllowBlockList {
1616

1717
# Interact with query parameters or the body of the request.
1818
$TenantFilter = $Request.Query.tenantFilter
19-
$ListTypes = 'Sender', 'Url', 'FileHash'
19+
$ListTypes = 'Sender', 'Url', 'FileHash', 'IP'
2020
try {
2121
$Results = $ListTypes | ForEach-Object -Parallel {
2222
Import-Module CIPPCore

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ function Invoke-CIPPStandardAutopilotProfile {
1414
Device Management Standards
1515
TAG
1616
DISABLEDFEATURES
17-
{"report":true,"warn":true,"remediate":false}
17+
{"report":false,"warn":false,"remediate":false}
1818
ADDEDCOMPONENT
1919
{"type":"textField","name":"standards.AutopilotProfile.DisplayName","label":"Profile Display Name"}
2020
{"type":"textField","name":"standards.AutopilotProfile.Description","label":"Profile Description"}
2121
{"type":"textField","name":"standards.AutopilotProfile.DeviceNameTemplate","label":"Unique Device Name Template"}
22-
{"type":"autoComplete","multiple":false,"creatable":false,"name":"standards.AutopilotProfile.Languages","label":"Languages","api":{"url":"/languageList.json","labelField":"language","valueField":"tag"}}
22+
{"type":"autoComplete","multiple":false,"creatable":false,"required":false,"name":"standards.AutopilotProfile.Languages","label":"Languages","api":{"url":"/languageList.json","labelField":"language","valueField":"tag"}}
2323
{"type":"switch","name":"standards.AutopilotProfile.CollectHash","label":"Convert all targeted devices to Autopilot","defaultValue":true}
2424
{"type":"switch","name":"standards.AutopilotProfile.AssignToAllDevices","label":"Assign to all devices","defaultValue":true}
2525
{"type":"switch","name":"standards.AutopilotProfile.SelfDeployingMode","label":"Enable Self-deploying Mode","defaultValue":true}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function Invoke-CIPPStandardAutopilotStatusPage {
1414
Device Management Standards
1515
TAG
1616
DISABLEDFEATURES
17-
{"report":true,"warn":true,"remediate":false}
17+
{"report":false,"warn":false,"remediate":false}
1818
ADDEDCOMPONENT
1919
{"type":"number","name":"standards.AutopilotStatusPage.TimeOutInMinutes","label":"Timeout in minutes","defaultValue":60}
2020
{"type":"textField","name":"standards.AutopilotStatusPage.ErrorMessage","label":"Custom Error Message","required":false}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ function Invoke-CIPPStandardDisableGuests {
3232
param($Tenant, $Settings)
3333
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableGuests'
3434

35-
$Lookup = (Get-Date).AddDays(-90).ToUniversalTime().ToString('o')
35+
$90Days = (Get-Date).AddDays(-90).ToUniversalTime()
36+
$Lookup = $90Days.ToString('o')
3637
$AuditLookup = (Get-Date).AddDays(-7).ToUniversalTime().ToString('o')
3738

38-
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users?`$filter=(signInActivity/lastSuccessfulSignInDateTime le $Lookup)&`$select=id,UserPrincipalName,signInActivity,mail,userType,accountEnabled" -scope 'https://graph.microsoft.com/.default' -tenantid $Tenant |
39-
Where-Object { $_.userType -eq 'Guest' -and $_.AccountEnabled -eq $true }
39+
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users?`$filter=createdDateTime le $Lookup and userType eq 'Guest' and accountEnabled eq true &`$select=id,UserPrincipalName,signInActivity,mail,userType,accountEnabled,createdDateTime,externalUserState" -scope 'https://graph.microsoft.com/.default' -tenantid $Tenant |
40+
Where-Object { $_.signInActivity.lastSuccessfulSignInDateTime -le $90Days }
4041

4142
$RecentlyReactivatedUsers = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/auditLogs/directoryAudits?`$filter=activityDisplayName eq 'Enable account' and activityDateTime ge $AuditLookup" -scope 'https://graph.microsoft.com/.default' -tenantid $Tenant |
4243
ForEach-Object { $_.targetResources[0].id } | Select-Object -Unique)

0 commit comments

Comments
 (0)