Skip to content

Commit 788ca88

Browse files
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP-API into dev
2 parents 18b4c1e + fff3c60 commit 788ca88

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

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

Lines changed: 39 additions & 16 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,13 +35,11 @@ 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 = @{
41-
Standard = $Standard.templateName
41+
Template = $Standard.templateName
42+
Standard = $Row.Standard
4243
}
4344

4445
if ($Row.IntuneTemplateId) {
@@ -84,6 +85,7 @@ function Invoke-ListLogs {
8485
$username = $Request.Query.User ?? '*'
8586
$TenantFilter = $Request.Query.Tenant
8687
$ApiFilter = $Request.Query.API
88+
$StandardFilter = $Request.Query.StandardTemplateId
8789

8890
$StartDate = $Request.Query.StartDate ?? $Request.Query.DateFilter
8991
$EndDate = $Request.Query.EndDate ?? $Request.Query.DateFilter
@@ -114,7 +116,8 @@ function Invoke-ListLogs {
114116
$_.Severity -in $LogLevel -and
115117
$_.Username -like $username -and
116118
($TenantFilter -eq $null -or $TenantFilter -eq 'AllTenants' -or $_.Tenant -like "*$TenantFilter*" -or $_.TenantID -eq $TenantFilter) -and
117-
($ApiFilter -eq $null -or $_.API -match "$ApiFilter")
119+
($ApiFilter -eq $null -or $_.API -match "$ApiFilter") -and
120+
($StandardFilter -eq $null -or $_.StandardTemplateId -eq $StandardFilter)
118121
}
119122

120123
if ($AllowedTenants -notcontains 'AllTenants') {
@@ -123,26 +126,46 @@ function Invoke-ListLogs {
123126

124127
foreach ($Row in $Rows) {
125128
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)) ) {
129+
if ($Row.StandardTemplateId) {
130+
$Standard = ($Templates | Where-Object { $_.RowKey -eq $Row.StandardTemplateId }).JSON | ConvertFrom-Json
131+
132+
$StandardInfo = @{
133+
Template = $Standard.templateName
134+
Standard = $Row.Standard
135+
}
136+
137+
if ($Row.IntuneTemplateId) {
138+
$IntuneTemplate = ($Templates | Where-Object { $_.RowKey -eq $Row.IntuneTemplateId }).JSON | ConvertFrom-Json
139+
$StandardInfo.IntunePolicy = $IntuneTemplate.displayName
140+
}
141+
if ($Row.ConditionalAccessTemplateId) {
142+
$ConditionalAccessTemplate = ($Templates | Where-Object { $_.RowKey -eq $Row.ConditionalAccessTemplateId }).JSON | ConvertFrom-Json
143+
$StandardInfo.ConditionalAccessPolicy = $ConditionalAccessTemplate.displayName
144+
}
145+
} else {
146+
$StandardInfo = @{}
147+
}
126148

127149
$LogData = if ($Row.LogData -and (Test-Json -Json $Row.LogData -ErrorAction SilentlyContinue)) {
128150
$Row.LogData | ConvertFrom-Json
129151
} else { $Row.LogData }
130152
[PSCustomObject]@{
131-
DateTime = $Row.Timestamp
132-
Tenant = $Row.Tenant
133-
API = $Row.API
134-
Message = $Row.Message
135-
User = $Row.Username
136-
Severity = $Row.Severity
137-
LogData = $LogData
138-
TenantID = if ($Row.TenantID -ne $null) {
153+
DateTime = $Row.Timestamp
154+
Tenant = $Row.Tenant
155+
API = $Row.API
156+
Message = $Row.Message
157+
User = $Row.Username
158+
Severity = $Row.Severity
159+
LogData = $LogData
160+
TenantID = if ($Row.TenantID -ne $null) {
139161
$Row.TenantID
140162
} else {
141163
'None'
142164
}
143-
AppId = $Row.AppId
144-
IP = $Row.IP
145-
RowKey = $Row.RowKey
165+
AppId = $Row.AppId
166+
IP = $Row.IP
167+
RowKey = $Row.RowKey
168+
StandardInfo = $StandardInfo
146169
}
147170
}
148171
}

Modules/CIPPCore/Public/New-CIPPCAPolicy.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function New-CIPPCAPolicy {
153153
name = ($CheckExisting | Where-Object -Property displayName -EQ $Location.displayName).displayName
154154
templateId = $location.id
155155
}
156-
Write-LogMessage -Headers $User -API $APINAME -message "Matched a CA policy with the existing Named Location: $($location.displayName)" -Sev 'Info'
156+
Write-LogMessage -Tenant $TenantFilter -Headers $User -API $APINAME -message "Matched a CA policy with the existing Named Location: $($location.displayName)" -Sev 'Info'
157157

158158
} else {
159159
if ($location.countriesAndRegions) { $location.countriesAndRegions = @($location.countriesAndRegions) }
@@ -169,7 +169,7 @@ function New-CIPPCAPolicy {
169169
Start-Sleep -Seconds 2
170170
$retryCount++
171171
} while ((!$LocationRequest -or !$LocationRequest.id) -and ($retryCount -lt 5))
172-
Write-LogMessage -Headers $User -API $APINAME -message "Created new Named Location: $($location.displayName)" -Sev 'Info'
172+
Write-LogMessage -Tenant $TenantFilter -Headers $User -API $APINAME -message "Created new Named Location: $($location.displayName)" -Sev 'Info'
173173
[pscustomobject]@{
174174
id = $GraphRequest.id
175175
name = $GraphRequest.displayName
@@ -248,7 +248,7 @@ function New-CIPPCAPolicy {
248248
}
249249
} catch {
250250
$ErrorMessage = Get-CippException -Exception $_
251-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to replace displayNames for conditional access rule $($JSONobj.displayName). Error: $($ErrorMessage.NormalizedError)" -sev 'Error' -LogData $ErrorMessage
251+
Write-LogMessage -API 'Standards' -tenant $TenantFilter -message "Failed to replace displayNames for conditional access rule $($JSONobj.displayName). Error: $($ErrorMessage.NormalizedError)" -sev 'Error' -LogData $ErrorMessage
252252
throw "Failed to replace displayNames for conditional access rule $($JSONobj.displayName): $($ErrorMessage.NormalizedError)"
253253
}
254254
}
@@ -278,8 +278,8 @@ function New-CIPPCAPolicy {
278278
#Send request to disable security defaults.
279279
$body = '{ "isEnabled": false }'
280280
try {
281-
$null = New-GraphPostRequest -tenantid $tenant -Uri 'https://graph.microsoft.com/beta/policies/identitySecurityDefaultsEnforcementPolicy' -Type patch -Body $body -asApp $true -ContentType 'application/json'
282-
Write-LogMessage -Headers $User -API 'Create CA Policy' -tenant $($Tenant) -message "Disabled Security Defaults for tenant $($TenantFilter)" -Sev 'Info'
281+
$null = New-GraphPostRequest -tenantid $TenantFilter -Uri 'https://graph.microsoft.com/beta/policies/identitySecurityDefaultsEnforcementPolicy' -Type patch -Body $body -asApp $true -ContentType 'application/json'
282+
Write-LogMessage -Headers $User -API 'Create CA Policy' -tenant $TenantFilter -message "Disabled Security Defaults for tenant $($TenantFilter)" -Sev 'Info'
283283
Start-Sleep 3
284284
} catch {
285285
$ErrorMessage = Get-CippException -Exception $_
@@ -340,7 +340,7 @@ function New-CIPPCAPolicy {
340340
}
341341
} catch {
342342
$ErrorMessage = Get-CippException -Exception $_
343-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to create or update conditional access rule $($JSONobj.displayName): $($ErrorMessage.NormalizedError) " -sev 'Error' -LogData $ErrorMessage
343+
Write-LogMessage -API 'Standards' -tenant $TenantFilter -message "Failed to create or update conditional access rule $($JSONobj.displayName): $($ErrorMessage.NormalizedError) " -sev 'Error' -LogData $ErrorMessage
344344

345345
Write-Warning "Failed to create or update conditional access rule $($JSONobj.displayName): $($ErrorMessage.NormalizedError)"
346346
Write-Information $_.InvocationInfo.PositionMessage

0 commit comments

Comments
 (0)