Skip to content

Commit 4a25595

Browse files
authored
Merge pull request #107 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents e8daf58 + 8ffae09 commit 4a25595

File tree

15 files changed

+293
-117
lines changed

15 files changed

+293
-117
lines changed

Modules/CIPPCore/Public/AuditLogs/New-CIPPAuditLogSearchResultsCache.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function New-CIPPAuditLogSearchResultsCache {
7474
$FailedDownloadsTable = Get-CippTable -TableName 'FailedAuditLogDownloads'
7575
$failedEntities = Get-CIPPAzDataTableEntity @FailedDownloadsTable -Filter "PartitionKey eq '$TenantFilter' and SearchId eq '$SearchId'"
7676
if ($failedEntities) {
77-
Remove-AzDataTableEntity @FailedDownloadsTable -Entity $failedEntities
77+
Remove-AzDataTableEntity @FailedDownloadsTable -Entity $failedEntities -Force
7878
Write-Information "Removed failed download records for search ID: $SearchId, tenant: $TenantFilter"
7979
}
8080
} catch {

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Webhooks/Push-AuditLogTenantProcess.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ function Push-AuditLogTenantProcess {
2020
if ($Rows.Count -gt 0) {
2121
Write-Information "Retrieved $($Rows.Count) rows from cache for processing"
2222
Test-CIPPAuditLogRules -TenantFilter $TenantFilter -Rows $Rows
23+
exit 0
2324
} else {
2425
Write-Information 'No rows found in cache for the provided row IDs'
26+
exit 0
2527
}
2628
} catch {
2729
Write-Information ('Push-AuditLogTenant: Error {0} line {1} - {2}' -f $_.InvocationInfo.ScriptName, $_.InvocationInfo.ScriptLineNumber, $_.Exception.Message)

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-ListScheduledItems.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ Function Invoke-ListScheduledItems {
4949
}
5050

5151
$AllowedTenants = Test-CIPPAccess -Request $Request -TenantList
52+
5253
if ($AllowedTenants -notcontains 'AllTenants') {
53-
$Tasks = $Tasks | Where-Object -Property TenantId -In $AllowedTenants
54+
$TenantList = Get-Tenants -IncludeErrors | Select-Object customerId, defaultDomainName
55+
$AllowedTenantDomains = $TenantList | Where-Object -Property customerId -In $AllowedTenants | Select-Object -ExpandProperty defaultDomainName
56+
$Tasks = $Tasks | Where-Object -Property Tenant -In $AllowedTenantDomains
5457
}
5558
$ScheduledTasks = foreach ($Task in $tasks) {
5659
if ($Task.Parameters) {

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,32 @@ Function Invoke-ExecStartManagedFolderAssistant {
1414
$Headers = $Request.Headers
1515
Write-LogMessage -Headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

17-
1817
# Interact with query parameters or the body of the request.
1918
$Tenant = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
20-
$ID = $Request.Query.ID ?? $Request.Body.ID
19+
$ID = $Request.Query.Id ?? $Request.Body.Id
20+
$UserPrincipalName = $Request.Body.UserPrincipalName
21+
$Identity = $ID ?? $UserPrincipalName
22+
$ShownName = $UserPrincipalName ?? $ID
23+
24+
25+
$ExoParams = @{
26+
Identity = $Identity
27+
AggMailboxCleanup = $true
28+
FullCrawl = $true
29+
}
2130

2231
try {
23-
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Start-ManagedFolderAssistant' -cmdParams @{Identity = $ID }
24-
$Result = "Successfully started Managed Folder Assistant for mailbox $($ID)."
32+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Start-ManagedFolderAssistant' -cmdParams $ExoParams
33+
$Result = "Successfully started Managed Folder Assistant for mailbox $($ShownName)."
2534
$Severity = 'Info'
2635
$StatusCode = [HttpStatusCode]::OK
2736
} catch {
2837
$ErrorMessage = Get-CippException -Exception $_
29-
$Result = "Failed to start Managed Folder Assistant for mailbox $($ID). Error: $($ErrorMessage.NormalizedError)"
38+
$Result = "Failed to start Managed Folder Assistant for mailbox $($ShownName). Error: $($ErrorMessage.NormalizedError)"
3039
$Severity = 'Error'
3140
$StatusCode = [HttpStatusCode]::InternalServerError
3241
} finally {
3342
Write-LogMessage -Headers $Headers -API $APIName -tenant $Tenant -message $Result -Sev $Severity -LogData $ErrorMessage
34-
3543
}
3644

3745
$Body = [pscustomobject] @{ 'Results' = $Result }

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Tenant/Invoke-ListTenants.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Function Invoke-ListTenants {
2323
}
2424

2525
# Clear Cache
26-
if ($Request.Query.ClearCache -eq $true) {
27-
Remove-CIPPCache -tenantsOnly $Request.Query.TenantsOnly
26+
if ($Request.Body.ClearCache -eq $true) {
27+
$Results = Remove-CIPPCache -tenantsOnly $Request.Body.TenantsOnly
2828

2929
$InputObject = [PSCustomObject]@{
3030
Batch = @(
@@ -40,7 +40,12 @@ Function Invoke-ListTenants {
4040
$GraphRequest = [pscustomobject]@{'Results' = 'Cache has been cleared and a tenant refresh is queued.' }
4141
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
4242
StatusCode = [HttpStatusCode]::OK
43-
Body = $GraphRequest
43+
Body = @{
44+
Results = @($GraphRequest)
45+
Metadata = @{
46+
Details = $Results
47+
}
48+
}
4449
})
4550
#Get-Tenants -IncludeAll -TriggerRefresh
4651
return

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

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

1717
# Write to the Azure Functions log stream.
1818
Write-Host 'PowerShell HTTP trigger function processed a request.'
19-
$Table = Get-CIPPTable -TableName 'knownlocationdb'
19+
$Table = Get-CIPPTable -TableName 'knownlocationdbv2'
2020
$Filter = "Tenant eq '$($Request.Query.TenantFilter)'"
2121
$KnownIPDb = Get-CIPPAzDataTableEntity @Table -Filter $Filter
2222

Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-AuditLogOrchestrator.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ function Start-AuditLogOrchestrator {
3939
$ProcessQueue = New-CippQueueEntry -Name 'Audit Logs Process' -Reference 'AuditLogsProcess' -TotalTasks ($TenantGroups | Measure-Object -Property Count -Sum).Sum
4040
$ProcessBatch = foreach ($TenantGroup in $TenantGroups) {
4141
$TenantFilter = $TenantGroup.Name
42-
$RowIds = $TenantGroup.Group.RowKey
42+
$RowIds = @($TenantGroup.Group.RowKey)
4343
for ($i = 0; $i -lt $RowIds.Count; $i += 1000) {
44+
Write-Host "Processing $TenantFilter with $($RowIds.Count) row IDs. We're processing id $($RowIds[$i]) to $($RowIds[[Math]::Min($i + 999, $RowIds.Count - 1)])"
4445
$BatchRowIds = $RowIds[$i..([Math]::Min($i + 999, $RowIds.Count - 1))]
45-
4646
[PSCustomObject]@{
4747
TenantFilter = $TenantFilter
4848
RowIds = $BatchRowIds

Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-TableCleanup.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,27 @@ function Start-TableCleanup {
4848
}
4949
)
5050

51+
$DeleteTables = @(
52+
'knownlocationdb'
53+
)
54+
5155
if ($PSCmdlet.ShouldProcess('Start-TableCleanup', 'Starting Table Cleanup')) {
56+
foreach ($Table in $DeleteTables) {
57+
try {
58+
$Table = Get-CIPPTable -tablename $Table
59+
if ($Table) {
60+
Write-Information "Deleting table $($Table.Context.TableName)"
61+
try {
62+
Remove-AzDataTable -Context $Table.Context -Force
63+
} catch {
64+
Write-LogMessage -API 'TableCleanup' -message "Failed to delete table $($Table.Context.TableName)" -sev Error -LogData (Get-CippException -Exception $_)
65+
}
66+
}
67+
} catch {
68+
Write-Information "Table $Table not found"
69+
}
70+
}
71+
5272
Write-Information 'Starting table cleanup'
5373
foreach ($Rule in $CleanupRules) {
5474
if ($Rule.Where) {

Modules/CIPPCore/Public/GraphHelper/Remove-CIPPCache.ps1

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,36 @@ function Remove-CIPPCache {
1313
if ($ClearIncludedTenants) {
1414
Remove-AzDataTableEntity -Force @TenantsTable -Entity $ClearIncludedTenants
1515
}
16+
"Removed $($ClearIncludedTenants.Count) tenants"
1617

17-
if ($TenantsOnly -eq 'false') {
18-
Write-Host 'Clearing all'
18+
if ($TenantsOnly -eq $false) {
19+
'Clearing all cached table data'
20+
$Context = New-AzDataTableContext -ConnectionString $env:AzureWebJobsStorage
21+
$Tables = Get-AzDataTable -Context $Context
22+
foreach ($Table in $Tables) {
23+
if ($Table -match '^cache') {
24+
"Removing cache table $Table"
25+
$TableContext = Get-CIPPTable -TableName $Table
26+
Remove-AzDataTable @TableContext
27+
}
28+
}
29+
30+
'Clearing domain analyser results'
1931
# Remove Domain Analyser cached results
2032
$DomainsTable = Get-CippTable -tablename 'Domains'
2133
$Filter = "PartitionKey eq 'TenantDomains'"
2234
$ClearDomainAnalyserRows = Get-CIPPAzDataTableEntity @DomainsTable -Filter $Filter | ForEach-Object {
23-
$_.DomainAnalyser = ''
35+
$_ | Add-Member -MemberType NoteProperty -Name DomainAnalyser -Value '' -Force
2436
$_
2537
}
2638
if ($ClearDomainAnalyserRows) {
2739
Update-AzDataTableEntity -Force @DomainsTable -Entity $ClearDomainAnalyserRows
2840
}
29-
#Clear BPA
30-
$BPATable = Get-CippTable -tablename 'cachebpav2'
31-
$ClearBPARows = Get-CIPPAzDataTableEntity @BPATable
32-
if ($ClearBPARows) {
33-
Remove-AzDataTableEntity -Force @BPATable -Entity $ClearBPARows
34-
}
41+
3542
$ENV:SetFromProfile = $null
3643
$Script:SkipListCache = $Null
3744
$Script:SkipListCacheEmpty = $Null
3845
$Script:IncludedTenantsCache = $Null
3946
}
47+
'Cache cleanup complete'
4048
}

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

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)