Skip to content

Commit 8f8d65d

Browse files
audit log tenant searches improvements
1 parent b919903 commit 8f8d65d

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function Push-AuditLogTenantDownload {
5151
$SearchEntity.CippStatus = 'Processing'
5252
Add-CIPPAzDataTableEntity @LogSearchesTable -Entity $SearchEntity -Force
5353
try {
54-
Write-Information "Audit Log search: Processing search ID: $($Search.id) for tenant: $TenantFilter"
54+
Write-Information "Audit Log search: Processing search ID: $($Search.id) for tenant: $TenantFilter"
5555
$Downloads = New-CIPPAuditLogSearchResultsCache -TenantFilter $TenantFilter -searchId $Search.id
5656
$SearchEntity.CippStatus = 'Downloaded'
5757
} catch {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ function Start-AuditLogSearchCreation {
1717

1818
Write-Information 'Audit Logs: Creating new searches'
1919
foreach ($Tenant in $TenantList) {
20+
$TenantsList = Expand-CIPPTenantGroups -TenantFilter ($ConfigEntries.Tenants | ConvertFrom-Json)
2021
$Configuration = $ConfigEntries | Where-Object { ($_.Tenants -match $TenantFilter -or $_.Tenants -match 'AllTenants') }
21-
if ($Configuration) {
22+
if ($Configuration -and $Tenant -in $TenantsList) {
2223
$ServiceFilters = $Configuration | Select-Object -Property type | Sort-Object -Property type -Unique | ForEach-Object { $_.type.split('.')[1] }
2324
try {
2425
$LogSearch = @{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function Expand-CIPPTenantGroups {
2+
<#
3+
.SYNOPSIS
4+
Expands a list of groups to their members.
5+
.DESCRIPTION
6+
This function takes a a tenant filter object and expands it to include all members of the groups.
7+
.EXAMPLE
8+
9+
#>
10+
[CmdletBinding(SupportsShouldProcess = $true)]
11+
param (
12+
[Parameter(Mandatory = $true)]
13+
$TenantFilter
14+
)
15+
$TenantList = Get-Tenants -IncludeErrors
16+
$ExpandedGroups = $TenantFilter | ForEach-Object {
17+
$FilterValue = $_
18+
# Group lookup
19+
if ($_.type -eq 'Group') {
20+
$members = (Get-TenantGroups -GroupId $_.value).members
21+
$TenantList | Where-Object -Property customerId -In $members.customerId | ForEach-Object {
22+
$GroupMember = $_
23+
[PSCustomObject]@{
24+
value = $GroupMember.defaultDomainName
25+
label = $GroupMember.displayName
26+
addedFields = $GroupMember | Select-Object defaultDomainName, displayName, customerId
27+
type = 'Tenant'
28+
}
29+
}
30+
} else {
31+
$FilterValue
32+
}
33+
}
34+
return $ExpandedGroups | Sort-Object -Property value -Unique
35+
}

0 commit comments

Comments
 (0)