Skip to content

Commit aae0b44

Browse files
committed
Enhance log listing with template details and filtering
Adds retrieval of template data at the start of the function and supports filtering logs by StandardTemplateId. Log entries now include detailed standard, Intune, and conditional access policy information when available.
1 parent 5404a56 commit aae0b44

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ function Invoke-ListLogs {
99
param($Request, $TriggerMetadata)
1010
$Table = Get-CIPPTable
1111

12+
$TemplatesTable = Get-CIPPTable -tablename 'templates'
13+
$Templates = Get-CIPPAzDataTableEntity @TemplatesTable
14+
1215
$ReturnedLog = if ($Request.Query.ListLogs) {
1316
Get-AzDataTableEntity @Table -Property PartitionKey | Sort-Object -Unique PartitionKey | Select-Object PartitionKey | ForEach-Object {
1417
@{
@@ -32,9 +35,6 @@ function Invoke-ListLogs {
3235
if ($AllowedTenants -contains 'AllTenants' -or ($AllowedTenants -notcontains 'AllTenants' -and ($TenantList.defaultDomainName -contains $Row.Tenant -or $Row.Tenant -eq 'CIPP' -or $TenantList.customerId -contains $Row.TenantId)) ) {
3336

3437
if ($Row.StandardTemplateId) {
35-
$TemplatesTable = Get-CIPPTable -tablename 'templates'
36-
$Templates = Get-CIPPAzDataTableEntity @TemplatesTable
37-
3838
$Standard = ($Templates | Where-Object { $_.RowKey -eq $Row.StandardTemplateId }).JSON | ConvertFrom-Json
3939

4040
$StandardInfo = @{
@@ -84,6 +84,7 @@ function Invoke-ListLogs {
8484
$username = $Request.Query.User ?? '*'
8585
$TenantFilter = $Request.Query.Tenant
8686
$ApiFilter = $Request.Query.API
87+
$StandardFilter = $Request.Query.StandardTemplateId
8788

8889
$StartDate = $Request.Query.StartDate ?? $Request.Query.DateFilter
8990
$EndDate = $Request.Query.EndDate ?? $Request.Query.DateFilter
@@ -114,7 +115,8 @@ function Invoke-ListLogs {
114115
$_.Severity -in $LogLevel -and
115116
$_.Username -like $username -and
116117
($TenantFilter -eq $null -or $TenantFilter -eq 'AllTenants' -or $_.Tenant -like "*$TenantFilter*" -or $_.TenantID -eq $TenantFilter) -and
117-
($ApiFilter -eq $null -or $_.API -match "$ApiFilter")
118+
($ApiFilter -eq $null -or $_.API -match "$ApiFilter") -and
119+
($StandardFilter -eq $null -or $_.StandardTemplateId -eq $StandardFilter)
118120
}
119121

120122
if ($AllowedTenants -notcontains 'AllTenants') {
@@ -123,6 +125,24 @@ function Invoke-ListLogs {
123125

124126
foreach ($Row in $Rows) {
125127
if ($AllowedTenants -contains 'AllTenants' -or ($AllowedTenants -notcontains 'AllTenants' -and ($TenantList.defaultDomainName -contains $Row.Tenant -or $Row.Tenant -eq 'CIPP' -or $TenantList.customerId -contains $Row.TenantId)) ) {
128+
if ($Row.StandardTemplateId) {
129+
$Standard = ($Templates | Where-Object { $_.RowKey -eq $Row.StandardTemplateId }).JSON | ConvertFrom-Json
130+
131+
$StandardInfo = @{
132+
Standard = $Standard.templateName
133+
}
134+
135+
if ($Row.IntuneTemplateId) {
136+
$IntuneTemplate = ($Templates | Where-Object { $_.RowKey -eq $Row.IntuneTemplateId }).JSON | ConvertFrom-Json
137+
$StandardInfo.IntunePolicy = $IntuneTemplate.displayName
138+
}
139+
if ($Row.ConditionalAccessTemplateId) {
140+
$ConditionalAccessTemplate = ($Templates | Where-Object { $_.RowKey -eq $Row.ConditionalAccessTemplateId }).JSON | ConvertFrom-Json
141+
$StandardInfo.ConditionalAccessPolicy = $ConditionalAccessTemplate.displayName
142+
}
143+
} else {
144+
$StandardInfo = @{}
145+
}
126146

127147
$LogData = if ($Row.LogData -and (Test-Json -Json $Row.LogData -ErrorAction SilentlyContinue)) {
128148
$Row.LogData | ConvertFrom-Json
@@ -143,6 +163,7 @@ function Invoke-ListLogs {
143163
AppId = $Row.AppId
144164
IP = $Row.IP
145165
RowKey = $Row.RowKey
166+
Standard = $StandardInfo
146167
}
147168
}
148169
}

0 commit comments

Comments
 (0)