Skip to content

Commit 47fa612

Browse files
authored
Merge pull request KelvinTegelaar#1193 from JohnDuprey/dev
bugfixes
2 parents 6822e4b + 819c270 commit 47fa612

9 files changed

Lines changed: 58 additions & 26 deletions

File tree

Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function Add-CIPPScheduledTask {
2121
$Parameters = [System.Collections.Hashtable]@{}
2222
foreach ($Key in $task.Parameters.PSObject.Properties.Name) {
2323
$Param = $task.Parameters.$Key
24-
if ($Param -is [System.Collections.IDictionary]) {
24+
if ($Param -is [System.Collections.IDictionary] -or $Param.Key) {
2525
$ht = @{}
2626
foreach ($p in $Param.GetEnumerator()) {
2727
$ht[$p.Key] = $p.Value

Modules/CIPPCore/Public/AuditLogs/Get-CippAuditLogSearchResults.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@ function Get-CippAuditLogSearchResults {
1414
[string]$TenantFilter,
1515
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
1616
[Alias('id')]
17-
[string]$QueryId
17+
[string]$QueryId,
18+
[switch]$CountOnly
1819
)
1920

2021
process {
21-
New-GraphGetRequest -uri ('https://graph.microsoft.com/beta/security/auditLog/queries/{0}/records?$top=999' -f $QueryId) -AsApp $true -tenantid $TenantFilter -ErrorAction Stop
22+
$GraphRequest = @{
23+
Uri = ('https://graph.microsoft.com/beta/security/auditLog/queries/{0}/records?$top=999&$count=true' -f $QueryId)
24+
Method = 'GET'
25+
AsApp = $true
26+
tenantid = $TenantFilter
27+
}
28+
if ($CountOnly.IsPresent) {
29+
$GraphRequest.CountOnly = $true
30+
}
31+
32+
New-GraphGetRequest @GraphRequest -ErrorAction Stop
2233
}
2334
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecRestoreBackup.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Function Invoke-ExecRestoreBackup {
1313
$APIName = $TriggerMetadata.FunctionName
1414
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1515
try {
16-
foreach ($line in ($Request.body | ConvertFrom-Json | Select-Object * -ExcludeProperty ETag)) {
16+
foreach ($line in ($Request.body | ConvertFrom-Json | Select-Object * -ExcludeProperty ETag, Timestamp)) {
1717
Write-Host ($line)
1818
$Table = Get-CippTable -tablename $line.table
1919
$ht2 = @{}

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,28 @@ function Start-AuditLogOrchestrator {
77
param()
88
try {
99
$AuditLogSearchesTable = Get-CIPPTable -TableName 'AuditLogSearches'
10-
$AuditLogSearches = Get-CIPPAzDataTableEntity @AuditLogSearchesTable -Filter "CippStatus eq 'Pending'"
10+
$15MinutesAgo = (Get-Date).AddMinutes(-15).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
11+
$1DayAgo = (Get-Date).AddDays(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
12+
$AuditLogSearches = Get-CIPPAzDataTableEntity @AuditLogSearchesTable -Filter "(CippStatus eq 'Pending' or (CippStatus eq 'Processing' and Timestamp le datetime'$15MinutesAgo')) and Timestamp ge datetime'$1DayAgo'" -Property PartitionKey, RowKey, Tenant, CippStatus, Timestamp
13+
14+
$WebhookRulesTable = Get-CIPPTable -TableName 'WebhookRules'
15+
$WebhookRules = Get-CIPPAzDataTableEntity @WebhookRulesTable
1116

1217
if (($AuditLogSearches | Measure-Object).Count -eq 0) {
1318
Write-Information 'No audit log searches available'
19+
} elseif (($WebhookRules | Measure-Object).Count -eq 0) {
20+
Write-Information 'No webhook rules defined'
1421
} else {
15-
$Queue = New-CippQueueEntry -Name 'Audit Log Collection' -Reference 'AuditLogCollection' -TotalTasks ($AuditLogSearches).Count
16-
$Batch = $AuditLogSearches | Sort-Object -Property Tenant -Unique | Select-Object @{Name = 'TenantFilter'; Expression = { $_.Tenant } }, @{Name = 'QueueId'; Expression = { $Queue.RowKey } }, @{Name = 'FunctionName'; Expression = { 'AuditLogTenant' } }
17-
18-
$InputObject = [PSCustomObject]@{
19-
OrchestratorName = 'AuditLogs'
20-
Batch = @($Batch)
21-
SkipLog = $true
22-
}
22+
Write-Information "Audit Logs: Processing $($AuditLogSearches.Count) searches"
2323
if ($PSCmdlet.ShouldProcess('Start-AuditLogOrchestrator', 'Starting Audit Log Polling')) {
24+
$Queue = New-CippQueueEntry -Name 'Audit Log Collection' -Reference 'AuditLogCollection' -TotalTasks ($AuditLogSearches).Count
25+
$Batch = $AuditLogSearches | Sort-Object -Property Tenant -Unique | Select-Object @{Name = 'TenantFilter'; Expression = { $_.Tenant } }, @{Name = 'QueueId'; Expression = { $Queue.RowKey } }, @{Name = 'FunctionName'; Expression = { 'AuditLogTenant' } }
26+
27+
$InputObject = [PSCustomObject]@{
28+
OrchestratorName = 'AuditLogs'
29+
Batch = @($Batch)
30+
SkipLog = $true
31+
}
2432
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
2533
}
2634
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Start-UserTasksOrchestrator {
1616
$currentUnixTime = [int64](([datetime]::UtcNow) - (Get-Date '1/1/1970')).TotalSeconds
1717
if ($currentUnixTime -ge $task.ScheduledTime) {
1818
try {
19-
$null = Update-AzDataTableEntity @Table -Entity @{
19+
$null = Update-AzDataTableEntity -Force @Table -Entity @{
2020
PartitionKey = $task.PartitionKey
2121
RowKey = $task.RowKey
2222
ExecutedTime = "$currentUnixTime"
@@ -36,7 +36,9 @@ function Start-UserTasksOrchestrator {
3636
if ($task.Tenant -eq 'AllTenants') {
3737
$AllTenantCommands = foreach ($Tenant in $TenantList) {
3838
$NewParams = $task.Parameters.Clone()
39-
$NewParams.TenantFilter = $Tenant.defaultDomainName
39+
if ((Get-Command $task.Command).Parameters.TenantFilter) {
40+
$NewParams.TenantFilter = $Tenant.defaultDomainName
41+
}
4042
[pscustomobject]@{
4143
Command = $task.Command
4244
Parameters = $NewParams
@@ -46,13 +48,15 @@ function Start-UserTasksOrchestrator {
4648
}
4749
$Batch.AddRange($AllTenantCommands)
4850
} else {
49-
$ScheduledCommand.Parameters['TenantFilter'] = $task.Tenant
51+
if ((Get-Command $task.Command).Parameters.TenantFilter) {
52+
$ScheduledCommand.Parameters['TenantFilter'] = $task.Tenant
53+
}
5054
$Batch.Add($ScheduledCommand)
5155
}
5256
} catch {
5357
$errorMessage = $_.Exception.Message
5458

55-
$null = Update-AzDataTableEntity @Table -Entity @{
59+
$null = Update-AzDataTableEntity -Force @Table -Entity @{
5660
PartitionKey = $task.PartitionKey
5761
RowKey = $task.RowKey
5862
Results = "$errorMessage"

Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ function Get-GraphRequestList {
8585
$GraphQuery = [System.UriBuilder]('https://graph.microsoft.com/{0}/{1}' -f $Version, $Endpoint)
8686
$ParamCollection = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)
8787
foreach ($Item in ($Parameters.GetEnumerator() | Sort-Object -CaseSensitive -Property Key)) {
88-
$ParamCollection.Add($Item.Key, $Item.Value)
88+
if ($Item.Value -is [System.Boolean]) {
89+
$Item.Value = $Item.Value.ToString().ToLower()
90+
}
91+
if ($Item.Value) {
92+
$ParamCollection.Add($Item.Key, $Item.Value)
93+
}
8994
}
9095
$GraphQuery.Query = $ParamCollection.ToString()
9196
$PartitionKey = Get-StringHash -String (@($Endpoint, $ParamCollection.ToString()) -join '-')
@@ -246,6 +251,7 @@ function Get-GraphRequestList {
246251
default {
247252
try {
248253
$QueueThresholdExceeded = $false
254+
249255
if ($Parameters.'$count' -and !$SkipCache -and !$NoPagination) {
250256
if ($Count -gt $singleTenantThreshold) {
251257
$QueueThresholdExceeded = $true
@@ -290,7 +296,7 @@ function Get-GraphRequestList {
290296

291297
if (!$QueueThresholdExceeded) {
292298
#nextLink should ONLY be used in direct calls with manual pagination. It should not be used in queueing
293-
if ($nextLink) { $GraphRequest.uri = $nextLink }
299+
if ($NoPagination.IsPresent -and $nextLink -match '^https://.+') { $GraphRequest.uri = $nextLink }
294300

295301
$GraphRequestResults = New-GraphGetRequest @GraphRequest -Caller 'Get-GraphRequestList' -ErrorAction Stop
296302
$GraphRequestResults = $GraphRequestResults | Select-Object *, @{n = 'Tenant'; e = { $TenantFilter } }, @{n = 'CippStatus'; e = { 'Good' } }
@@ -313,7 +319,8 @@ function Get-GraphRequestList {
313319
}
314320

315321
} catch {
316-
throw $_.Exception
322+
$Message = ('Exception at {0}:{1} - {2}' -f $_.InvocationInfo.ScriptName, $_.InvocationInfo.ScriptLineNumber, $_.Exception.Message)
323+
throw $Message
317324
}
318325
}
319326
}

Modules/CIPPCore/Public/New-CIPPBackup.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function New-CIPPBackup {
2424
)
2525
$CSVfile = foreach ($CSVTable in $BackupTables) {
2626
$Table = Get-CippTable -tablename $CSVTable
27-
Get-AzDataTableEntity @Table | Select-Object * -ExcludeProperty DomainAnalyser, table | Select-Object *, @{l = 'table'; e = { $CSVTable } }
27+
Get-AzDataTableEntity @Table | Select-Object * -ExcludeProperty DomainAnalyser, table, Timestamp, ETag | Select-Object *, @{l = 'table'; e = { $CSVTable } }
2828
}
2929
$RowKey = 'CIPPBackup' + '_' + (Get-Date).ToString('yyyy-MM-dd-HHmm')
3030
$CSVfile

Modules/CIPPCore/Public/Webhooks/Test-CIPPAuditLogRules.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ function Test-CIPPAuditLogRules {
3737
}
3838
#write-warning 'Getting audit records from Graph API'
3939
try {
40+
$LogCount = Get-CippAuditLogSearchResults -TenantFilter $TenantFilter -QueryId $SearchId -CountOnly
41+
$RunGuid = (New-Guid).Guid
42+
Write-Warning "Logs to process: $LogCount - SearchId: $SearchId - RunGuid: $($RunGuid) - $($TenantFilter)"
43+
$Results.TotalLogs = $LogCount
44+
Write-Information "RunGuid: $RunGud - Collecting logs"
4045
$SearchResults = Get-CippAuditLogSearchResults -TenantFilter $TenantFilter -QueryId $SearchId
4146
} catch {
4247
Write-Warning "Error getting audit logs: $($_.Exception.Message)"
4348
Write-LogMessage -API 'Webhooks' -message "Error getting audit logs for search $($SearchId)" -LogData (Get-CippException -Exception $_) -sev Error -tenant $TenantFilter
4449
throw $_
4550
}
46-
$LogCount = ($SearchResults | Measure-Object).Count
47-
$RunGuid = New-Guid
48-
Write-Warning "Logs to process: $LogCount - RunGuid: $($RunGuid) - $($TenantFilter)"
49-
$Results.TotalLogs = $LogCount
51+
5052
if ($LogCount -gt 0) {
5153
$LocationTable = Get-CIPPTable -TableName 'knownlocationdb'
5254
$ProcessedData = foreach ($AuditRecord in $SearchResults) {

profile.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if (!$LastStartup -or $CurrentVersion -ne $LastStartup.Version) {
6363
Version = $CurrentVersion
6464
}
6565
}
66-
Update-AzDataTableEntity @Table -Entity $LastStartup
66+
Update-AzDataTableEntity @Table -Entity $LastStartup -Force
6767
}
6868
# Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
6969
# Enable-AzureRmAlias

0 commit comments

Comments
 (0)