Skip to content

Commit 4e4491c

Browse files
authored
Merge pull request KelvinTegelaar#1179 from JohnDuprey/dev
Bugfixes and cleanup
2 parents 6267eaf + 8a04b30 commit 4e4491c

7 files changed

Lines changed: 34 additions & 19 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function Get-CippAuditLogSearches {
1717
if ($ReadyToProcess.IsPresent) {
1818
$AuditLogSearchesTable = Get-CippTable -TableName 'AuditLogSearches'
1919
$15MinutesAgo = (Get-Date).AddMinutes(-15).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
20-
$PendingQueries = Get-CIPPAzDataTableEntity @AuditLogSearchesTable -Filter "Tenant eq '$TenantFilter' and (CippStatus eq 'Pending' or (CippStatus eq 'Processing' and Timestamp le datetime'$15MinutesAgo'))" | Sort-Object Timestamp
20+
$1DayAgo = (Get-Date).AddDays(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
21+
$PendingQueries = Get-CIPPAzDataTableEntity @AuditLogSearchesTable -Filter "Tenant eq '$TenantFilter' and (CippStatus eq 'Pending' or (CippStatus eq 'Processing' and Timestamp le datetime'$15MinutesAgo')) and Timestamp ge datetime'$1DayAgo'" | Sort-Object Timestamp
2122

2223
$BulkRequests = foreach ($PendingQuery in $PendingQueries) {
2324
@{

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Push-DomainAnalyserDomain {
66
param($Item)
77
$DomainTable = Get-CippTable -tablename 'Domains'
88
$Filter = "PartitionKey eq 'TenantDomains' and RowKey eq '{0}'" -f $Item.RowKey
9-
$DomainObject = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter
9+
$DomainObject = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter | Select-Object * -ExcludeProperty table
1010

1111
try {
1212
$ConfigTable = Get-CippTable -tablename Config
@@ -35,7 +35,7 @@ function Push-DomainAnalyserDomain {
3535
try {
3636
$Tenant = $DomainObject.TenantDetails | ConvertFrom-Json -ErrorAction Stop
3737
} catch {
38-
$Tenant = @{Tenant = 'None' }
38+
$Tenant = @{ Tenant = 'None' }
3939
}
4040

4141
$Result = [PSCustomObject]@{
@@ -310,7 +310,13 @@ function Push-DomainAnalyserDomain {
310310
$Result.ScorePercentage = [int](($Result.Score / $Result.MaximumScore) * 100)
311311
$Result.ScoreExplanation = ($ScoreExplanation) -join ', '
312312

313-
$DomainObject.DomainAnalyser = (ConvertTo-Json -InputObject $Result -Depth 5 -Compress).ToString()
313+
$Json = (ConvertTo-Json -InputObject $Result -Depth 5 -Compress).ToString()
314+
315+
if ($DomainObject.PSObject.Properties.Name -notcontains 'DomainAnalyser') {
316+
$DomainObject | Add-Member -MemberType NoteProperty -Name DomainAnalyser -Value $Json
317+
} else {
318+
$DomainObject.DomainAnalyser = $Json
319+
}
314320

315321
try {
316322
$DomainTable.Entity = $DomainObject

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecPartnerWebhook.ps1

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ function Invoke-ExecPartnerWebhook {
4242
}
4343
$Results = New-CIPPGraphSubscription @Webhook
4444

45-
if ($Request.Body.standardsExcludeAllTenants -eq $true) {
46-
$ConfigTable = Get-CIPPTable -TableName Config
47-
$PartnerWebhookOnboarding = [PSCustomObject]@{
48-
PartitionKey = 'Config'
49-
RowKey = 'PartnerWebhookOnboarding'
50-
StandardsExcludeAllTenants = $true
51-
}
52-
Add-CIPPAzDataTableEntity @ConfigTable -Entity $PartnerWebhookOnboarding -Force | Out-Null
45+
$ConfigTable = Get-CIPPTable -TableName Config
46+
$PartnerWebhookOnboarding = [PSCustomObject]@{
47+
PartitionKey = 'Config'
48+
RowKey = 'PartnerWebhookOnboarding'
49+
StandardsExcludeAllTenants = $Request.Body.standardsExcludeAllTenants
5350
}
51+
Add-CIPPAzDataTableEntity @ConfigTable -Entity $PartnerWebhookOnboarding -Force | Out-Null
5452
}
5553
'SendTest' {
5654
$Results = New-GraphPOSTRequest -uri 'https://api.partnercenter.microsoft.com/webhooks/v1/registration/validationEvents' -tenantid $env:TenantID -NoAuthCheck $true -scope 'https://api.partnercenter.microsoft.com/.default'

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
@@ -17,7 +17,7 @@ Function Invoke-ExecRestoreBackup {
1717
Write-Host ($line)
1818
$Table = Get-CippTable -tablename $line.table
1919
$ht2 = @{}
20-
$line.psobject.properties | ForEach-Object { $ht2[$_.Name] = [string]$_.Value }
20+
$line.psobject.properties | Where-Object { $_.Name -ne 'table' } | ForEach-Object { $ht2[$_.Name] = [string]$_.Value }
2121
$Table.Entity = $ht2
2222
Add-CIPPAzDataTableEntity @Table -Force
2323

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function Start-DurableCleanup {
1717
param(
1818
[int]$MaxDuration = 3600
1919
)
20+
2021
$WarningPreference = 'SilentlyContinue'
2122
$StorageContext = New-AzStorageContext -ConnectionString $env:AzureWebJobsStorage
2223
$TargetTime = (Get-Date).ToUniversalTime().AddSeconds(-$MaxDuration)
@@ -30,15 +31,14 @@ function Start-DurableCleanup {
3031
$ClearQueues = $false
3132
$FunctionName = $Table.TableName -replace 'Instances', ''
3233
$Orchestrators = Get-CIPPAzDataTableEntity @Table -Filter "RuntimeStatus eq 'Running'" | Select-Object * -ExcludeProperty Input
33-
$Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime } | ForEach-Object {
34-
$CreatedTime = [DateTime]::SpecifyKind($_.CreatedTime.DateTime, [DateTimeKind]::Utc)
34+
$LongRunningOrchestrators = $Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime }
35+
foreach ($Orchestrator in $LongRunningOrchestrators) {
36+
$CreatedTime = [DateTime]::SpecifyKind($Orchestrator.CreatedTime.DateTime, [DateTimeKind]::Utc)
3537
$TimeSpan = New-TimeSpan -Start $CreatedTime -End (Get-Date).ToUniversalTime()
3638
$RunningDuration = [math]::Round($TimeSpan.TotalMinutes, 2)
37-
Write-Information "Orchestrator: $($_.PartitionKey), created: $CreatedTime, running for: $RunningDuration minutes"
39+
Write-Information "Orchestrator: $($Orchestrator.PartitionKey), created: $CreatedTime, running for: $RunningDuration minutes"
3840
$ClearQueues = $true
39-
$_.RuntimeStatus = 'Failed'
4041
if ($PSCmdlet.ShouldProcess($_.PartitionKey, 'Terminate Orchestrator')) {
41-
$Orchestrator = Get-CIPPAzDataTableEntity @Table -PartitionKey $_.PartitionKey -RowKey $_.RowKey
4242
$Orchestrator.RuntimeStatus = 'Failed'
4343
Update-AzDataTableEntity @Table -Entity $Orchestrator
4444
$CleanupCount++

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 *, @{l = 'table'; e = { $CSVTable } } -ExcludeProperty DomainAnalyser
27+
Get-AzDataTableEntity @Table | Select-Object * -ExcludeProperty DomainAnalyser, table | Select-Object *, @{l = 'table'; e = { $CSVTable } }
2828
}
2929
$RowKey = 'CIPPBackup' + '_' + (Get-Date).ToString('yyyy-MM-dd-HHmm')
3030
$CSVfile

Modules/CippEntrypoints/CippEntrypoints.psm1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ function Receive-CIPPTimerTrigger {
220220
}
221221
}
222222
try {
223+
if ($FunctionStatus.PSObject.Properties.Name -contains 'ErrorMsg') {
224+
$FunctionStatus.ErrorMsg = ''
225+
}
223226
$Results = Invoke-Command -ScriptBlock { & $Function.Command }
224227
if ($Results -match '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$') {
225228
$FunctionStatus.OrchestratorId = $Results
@@ -229,10 +232,17 @@ function Receive-CIPPTimerTrigger {
229232
}
230233
} catch {
231234
$Status = 'Failed'
235+
$ErrorMsg = $_.Exception.Message
236+
if ($FunctionStatus.PSObject.Properties.Name -contains 'ErrorMsg') {
237+
$FunctionStatus.ErrorMsg = $ErrorMsg
238+
} else {
239+
$FunctionStatus | Add-Member -MemberType NoteProperty -Name ErrorMsg -Value $ErrorMsg
240+
}
232241
Write-Information "Error in CIPPTimer for $($Function.Command): $($_.Exception.Message)"
233242
}
234243
$FunctionStatus.LastOccurrence = $UtcNow
235244
$FunctionStatus.Status = $Status
245+
236246
Add-CIPPAzDataTableEntity @Table -Entity $FunctionStatus -Force
237247
}
238248
}

0 commit comments

Comments
 (0)