diff --git a/Modules/CIPPCore/Public/AuditLogs/Get-CippAuditLogSearches.ps1 b/Modules/CIPPCore/Public/AuditLogs/Get-CippAuditLogSearches.ps1 index ba21f2dedcb2..1aac0b36eeab 100644 --- a/Modules/CIPPCore/Public/AuditLogs/Get-CippAuditLogSearches.ps1 +++ b/Modules/CIPPCore/Public/AuditLogs/Get-CippAuditLogSearches.ps1 @@ -17,7 +17,8 @@ function Get-CippAuditLogSearches { if ($ReadyToProcess.IsPresent) { $AuditLogSearchesTable = Get-CippTable -TableName 'AuditLogSearches' $15MinutesAgo = (Get-Date).AddMinutes(-15).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') - $PendingQueries = Get-CIPPAzDataTableEntity @AuditLogSearchesTable -Filter "Tenant eq '$TenantFilter' and (CippStatus eq 'Pending' or (CippStatus eq 'Processing' and Timestamp le datetime'$15MinutesAgo'))" | Sort-Object Timestamp + $1DayAgo = (Get-Date).AddDays(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') + $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 $BulkRequests = foreach ($PendingQuery in $PendingQueries) { @{ diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1 index 3c682fb8854d..168342bd7701 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1 @@ -6,7 +6,7 @@ function Push-DomainAnalyserDomain { param($Item) $DomainTable = Get-CippTable -tablename 'Domains' $Filter = "PartitionKey eq 'TenantDomains' and RowKey eq '{0}'" -f $Item.RowKey - $DomainObject = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter + $DomainObject = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter | Select-Object * -ExcludeProperty table try { $ConfigTable = Get-CippTable -tablename Config @@ -35,7 +35,7 @@ function Push-DomainAnalyserDomain { try { $Tenant = $DomainObject.TenantDetails | ConvertFrom-Json -ErrorAction Stop } catch { - $Tenant = @{Tenant = 'None' } + $Tenant = @{ Tenant = 'None' } } $Result = [PSCustomObject]@{ @@ -310,7 +310,13 @@ function Push-DomainAnalyserDomain { $Result.ScorePercentage = [int](($Result.Score / $Result.MaximumScore) * 100) $Result.ScoreExplanation = ($ScoreExplanation) -join ', ' - $DomainObject.DomainAnalyser = (ConvertTo-Json -InputObject $Result -Depth 5 -Compress).ToString() + $Json = (ConvertTo-Json -InputObject $Result -Depth 5 -Compress).ToString() + + if ($DomainObject.PSObject.Properties.Name -notcontains 'DomainAnalyser') { + $DomainObject | Add-Member -MemberType NoteProperty -Name DomainAnalyser -Value $Json + } else { + $DomainObject.DomainAnalyser = $Json + } try { $DomainTable.Entity = $DomainObject diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecPartnerWebhook.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecPartnerWebhook.ps1 index cadb2f70a770..841895a7b16c 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecPartnerWebhook.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecPartnerWebhook.ps1 @@ -42,15 +42,13 @@ function Invoke-ExecPartnerWebhook { } $Results = New-CIPPGraphSubscription @Webhook - if ($Request.Body.standardsExcludeAllTenants -eq $true) { - $ConfigTable = Get-CIPPTable -TableName Config - $PartnerWebhookOnboarding = [PSCustomObject]@{ - PartitionKey = 'Config' - RowKey = 'PartnerWebhookOnboarding' - StandardsExcludeAllTenants = $true - } - Add-CIPPAzDataTableEntity @ConfigTable -Entity $PartnerWebhookOnboarding -Force | Out-Null + $ConfigTable = Get-CIPPTable -TableName Config + $PartnerWebhookOnboarding = [PSCustomObject]@{ + PartitionKey = 'Config' + RowKey = 'PartnerWebhookOnboarding' + StandardsExcludeAllTenants = $Request.Body.standardsExcludeAllTenants } + Add-CIPPAzDataTableEntity @ConfigTable -Entity $PartnerWebhookOnboarding -Force | Out-Null } 'SendTest' { $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' diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecRestoreBackup.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecRestoreBackup.ps1 index 476fffa02389..00cb9bd38a36 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecRestoreBackup.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecRestoreBackup.ps1 @@ -17,7 +17,7 @@ Function Invoke-ExecRestoreBackup { Write-Host ($line) $Table = Get-CippTable -tablename $line.table $ht2 = @{} - $line.psobject.properties | ForEach-Object { $ht2[$_.Name] = [string]$_.Value } + $line.psobject.properties | Where-Object { $_.Name -ne 'table' } | ForEach-Object { $ht2[$_.Name] = [string]$_.Value } $Table.Entity = $ht2 Add-CIPPAzDataTableEntity @Table -Force diff --git a/Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-DurableCleanup.ps1 b/Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-DurableCleanup.ps1 index 41b1d55c2081..af01cdd07100 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-DurableCleanup.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-DurableCleanup.ps1 @@ -17,6 +17,7 @@ function Start-DurableCleanup { param( [int]$MaxDuration = 3600 ) + $WarningPreference = 'SilentlyContinue' $StorageContext = New-AzStorageContext -ConnectionString $env:AzureWebJobsStorage $TargetTime = (Get-Date).ToUniversalTime().AddSeconds(-$MaxDuration) @@ -30,15 +31,14 @@ function Start-DurableCleanup { $ClearQueues = $false $FunctionName = $Table.TableName -replace 'Instances', '' $Orchestrators = Get-CIPPAzDataTableEntity @Table -Filter "RuntimeStatus eq 'Running'" | Select-Object * -ExcludeProperty Input - $Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime } | ForEach-Object { - $CreatedTime = [DateTime]::SpecifyKind($_.CreatedTime.DateTime, [DateTimeKind]::Utc) + $LongRunningOrchestrators = $Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime } + foreach ($Orchestrator in $LongRunningOrchestrators) { + $CreatedTime = [DateTime]::SpecifyKind($Orchestrator.CreatedTime.DateTime, [DateTimeKind]::Utc) $TimeSpan = New-TimeSpan -Start $CreatedTime -End (Get-Date).ToUniversalTime() $RunningDuration = [math]::Round($TimeSpan.TotalMinutes, 2) - Write-Information "Orchestrator: $($_.PartitionKey), created: $CreatedTime, running for: $RunningDuration minutes" + Write-Information "Orchestrator: $($Orchestrator.PartitionKey), created: $CreatedTime, running for: $RunningDuration minutes" $ClearQueues = $true - $_.RuntimeStatus = 'Failed' if ($PSCmdlet.ShouldProcess($_.PartitionKey, 'Terminate Orchestrator')) { - $Orchestrator = Get-CIPPAzDataTableEntity @Table -PartitionKey $_.PartitionKey -RowKey $_.RowKey $Orchestrator.RuntimeStatus = 'Failed' Update-AzDataTableEntity @Table -Entity $Orchestrator $CleanupCount++ diff --git a/Modules/CIPPCore/Public/New-CIPPBackup.ps1 b/Modules/CIPPCore/Public/New-CIPPBackup.ps1 index 65e55aa03455..d161967509be 100644 --- a/Modules/CIPPCore/Public/New-CIPPBackup.ps1 +++ b/Modules/CIPPCore/Public/New-CIPPBackup.ps1 @@ -24,7 +24,7 @@ function New-CIPPBackup { ) $CSVfile = foreach ($CSVTable in $BackupTables) { $Table = Get-CippTable -tablename $CSVTable - Get-AzDataTableEntity @Table | Select-Object *, @{l = 'table'; e = { $CSVTable } } -ExcludeProperty DomainAnalyser + Get-AzDataTableEntity @Table | Select-Object * -ExcludeProperty DomainAnalyser, table | Select-Object *, @{l = 'table'; e = { $CSVTable } } } $RowKey = 'CIPPBackup' + '_' + (Get-Date).ToString('yyyy-MM-dd-HHmm') $CSVfile diff --git a/Modules/CippEntrypoints/CippEntrypoints.psm1 b/Modules/CippEntrypoints/CippEntrypoints.psm1 index 5aa18dee11e2..ae942d328329 100644 --- a/Modules/CippEntrypoints/CippEntrypoints.psm1 +++ b/Modules/CippEntrypoints/CippEntrypoints.psm1 @@ -220,6 +220,9 @@ function Receive-CIPPTimerTrigger { } } try { + if ($FunctionStatus.PSObject.Properties.Name -contains 'ErrorMsg') { + $FunctionStatus.ErrorMsg = '' + } $Results = Invoke-Command -ScriptBlock { & $Function.Command } if ($Results -match '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$') { $FunctionStatus.OrchestratorId = $Results @@ -229,10 +232,17 @@ function Receive-CIPPTimerTrigger { } } catch { $Status = 'Failed' + $ErrorMsg = $_.Exception.Message + if ($FunctionStatus.PSObject.Properties.Name -contains 'ErrorMsg') { + $FunctionStatus.ErrorMsg = $ErrorMsg + } else { + $FunctionStatus | Add-Member -MemberType NoteProperty -Name ErrorMsg -Value $ErrorMsg + } Write-Information "Error in CIPPTimer for $($Function.Command): $($_.Exception.Message)" } $FunctionStatus.LastOccurrence = $UtcNow $FunctionStatus.Status = $Status + Add-CIPPAzDataTableEntity @Table -Entity $FunctionStatus -Force } }