Skip to content

Commit 971fd09

Browse files
authored
Merge pull request #370 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 685144a + 368d857 commit 971fd09

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function Push-ExecScheduledCommand {
55
#>
66
param($Item)
77
$item = $Item | ConvertTo-Json -Depth 100 | ConvertFrom-Json
8-
Write-Host "We are going to be running a scheduled task: $($Item.TaskInfo | ConvertTo-Json -Depth 10)"
8+
Write-Information "We are going to be running a scheduled task: $($Item.TaskInfo | ConvertTo-Json -Depth 10)"
99

1010
$Table = Get-CippTable -tablename 'ScheduledTasks'
1111
$task = $Item.TaskInfo
@@ -51,49 +51,53 @@ function Push-ExecScheduledCommand {
5151
$commandParameters.Remove($key)
5252
}
5353
} catch {
54-
Write-Host "Failed to remove parameters: $($_.Exception.Message)"
54+
Write-Information "Failed to remove parameters: $($_.Exception.Message)"
5555
}
5656

57-
Write-Host "Started Task: $($Item.Command) for tenant: $Tenant"
57+
Write-Information "Started Task: $($Item.Command) for tenant: $Tenant"
5858
try {
5959

6060
try {
61-
Write-Host "Starting task: $($Item.Command) with parameters: $($commandParameters | ConvertTo-Json)"
61+
Write-Information "Starting task: $($Item.Command) with parameters: $($commandParameters | ConvertTo-Json)"
6262
$results = & $Item.Command @commandParameters
6363
} catch {
6464
$results = "Task Failed: $($_.Exception.Message)"
6565
$State = 'Failed'
6666
}
6767

68-
Write-Host 'ran the command. Processing results'
69-
Write-Host "Results: $($results | ConvertTo-Json -Depth 10)"
68+
Write-Information 'Ran the command. Processing results'
69+
Write-Information "Results: $($results | ConvertTo-Json -Depth 10)"
7070
if ($item.command -like 'Get-CIPPAlert*') {
71-
Write-Host 'This is an alert task. Processing results as alerts.'
71+
Write-Information 'This is an alert task. Processing results as alerts.'
7272
$results = @($results)
7373
$TaskType = 'Alert'
7474
} else {
75-
Write-Host 'This is a scheduled task. Processing results as scheduled task.'
75+
Write-Information 'This is a scheduled task. Processing results as scheduled task.'
7676
$TaskType = 'Scheduled Task'
77+
78+
if (!$results) {
79+
$results = 'Task completed successfully'
80+
}
81+
7782
if ($results -is [String]) {
7883
$results = @{ Results = $results }
79-
}
80-
if ($results -is [array] -and $results[0] -is [string] -or $results[0].resultText -is [string]) {
84+
} elseif ($results -is [array] -and $results[0] -is [string] -or $results[0].resultText -is [string]) {
8185
$results = $results | Where-Object { $_ -is [string] -or $_.resultText -is [string] }
8286
$results = $results | ForEach-Object {
8387
$Message = $_.resultText ?? $_
8488
@{ Results = $Message }
8589
}
8690
}
87-
Write-Host "Results after processing: $($results | ConvertTo-Json -Depth 10)"
88-
write0host 'Moving onto storing results'
91+
Write-Information "Results after processing: $($results | ConvertTo-Json -Depth 10)"
92+
Write-Information 'Moving onto storing results'
8993
if ($results -is [string]) {
9094
$StoredResults = $results
9195
} else {
9296
$results = $results | Select-Object * -ExcludeProperty RowKey, PartitionKey
9397
$StoredResults = $results | ConvertTo-Json -Compress -Depth 20 | Out-String
9498
}
9599
}
96-
Write-Host "Results: $($results | ConvertTo-Json -Depth 10)"
100+
Write-Information "Results: $($results | ConvertTo-Json -Depth 10)"
97101
if ($StoredResults.Length -gt 64000 -or $task.Tenant -eq 'AllTenants' -or $task.TenantGroup) {
98102
$TaskResultsTable = Get-CippTable -tablename 'ScheduledTaskResults'
99103
$TaskResults = @{
@@ -105,7 +109,7 @@ function Push-ExecScheduledCommand {
105109
$StoredResults = @{ Results = 'Completed, details are available in the More Info pane' } | ConvertTo-Json -Compress
106110
}
107111
} catch {
108-
Write-Host "Failed to run task: $($_.Exception.Message)"
112+
Write-Information "Failed to run task: $($_.Exception.Message)"
109113
$errorMessage = $_.Exception.Message
110114
#if recurrence is just a number, add it in days.
111115
if ($task.Recurrence -match '^\d+$') {
@@ -127,6 +131,7 @@ function Push-ExecScheduledCommand {
127131

128132
$nextRunUnixTime = [int64]$task.ScheduledTime + [int64]$secondsToAdd
129133
if ($task.Recurrence -ne 0) { $State = 'Failed - Planned' } else { $State = 'Failed' }
134+
Write-Information "The job is recurring, but failed. It was scheduled for $($task.ScheduledTime). The next runtime should be $nextRunUnixTime"
130135
Update-AzDataTableEntity -Force @Table -Entity @{
131136
PartitionKey = $task.PartitionKey
132137
RowKey = $task.RowKey
@@ -136,15 +141,15 @@ function Push-ExecScheduledCommand {
136141
}
137142
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $Tenant -tenantid $TenantInfo.customerId -message "Failed to execute task $($task.Name): $errorMessage" -sev Error -LogData (Get-CippExceptionData -Exception $_.Exception)
138143
}
139-
Write-Host 'Sending task results to target. Updating the task state.'
144+
Write-Information 'Sending task results to target. Updating the task state.'
140145

141146
if ($Results) {
142147
$TableDesign = '<style>table.blueTable{border:1px solid #1C6EA4;background-color:#EEE;width:100%;text-align:left;border-collapse:collapse}table.blueTable td,table.blueTable th{border:1px solid #AAA;padding:3px 2px}table.blueTable tbody td{font-size:13px}table.blueTable tr:nth-child(even){background:#D0E4F5}table.blueTable thead{background:#1C6EA4;background:-moz-linear-gradient(top,#5592bb 0,#327cad 66%,#1C6EA4 100%);background:-webkit-linear-gradient(top,#5592bb 0,#327cad 66%,#1C6EA4 100%);background:linear-gradient(to bottom,#5592bb 0,#327cad 66%,#1C6EA4 100%);border-bottom:2px solid #444}table.blueTable thead th{font-size:15px;font-weight:700;color:#FFF;border-left:2px solid #D0E4F5}table.blueTable thead th:first-child{border-left:none}table.blueTable tfoot{font-size:14px;font-weight:700;color:#FFF;background:#D0E4F5;background:-moz-linear-gradient(top,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);background:-webkit-linear-gradient(top,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);background:linear-gradient(to bottom,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);border-top:2px solid #444}table.blueTable tfoot td{font-size:14px}table.blueTable tfoot .links{text-align:right}table.blueTable tfoot .links a{display:inline-block;background:#1C6EA4;color:#FFF;padding:2px 8px;border-radius:5px}</style>'
143148
$FinalResults = if ($results -is [array] -and $results[0] -is [string]) { $Results | ConvertTo-Html -Fragment -Property @{ l = 'Text'; e = { $_ } } } else { $Results | ConvertTo-Html -Fragment }
144149
$HTML = $FinalResults -replace '<table>', "This alert is for tenant $Tenant. <br /><br /> $TableDesign<table class=blueTable>" | Out-String
145150
$title = "$TaskType - $Tenant - $($task.Name)"
146-
Write-Host 'Scheduler: Sending the results to the target.'
147-
Write-Host "The content of results is: $Results"
151+
Write-Information 'Scheduler: Sending the results to the target.'
152+
Write-Information "The content of results is: $Results"
148153
switch -wildcard ($task.PostExecution) {
149154
'*psa*' { Send-CIPPAlert -Type 'psa' -Title $title -HTMLContent $HTML -TenantFilter $Tenant }
150155
'*email*' { Send-CIPPAlert -Type 'email' -Title $title -HTMLContent $HTML -TenantFilter $Tenant }
@@ -159,11 +164,11 @@ function Push-ExecScheduledCommand {
159164
}
160165
}
161166
}
162-
Write-Host 'Sent the results to the target. Updating the task state.'
167+
Write-Information 'Sent the results to the target. Updating the task state.'
163168

164169
try {
165170
if ($task.Recurrence -eq '0' -or [string]::IsNullOrEmpty($task.Recurrence)) {
166-
Write-Host 'Recurrence empty or 0. Task is not recurring. Setting task state to completed.'
171+
Write-Information 'Recurrence empty or 0. Task is not recurring. Setting task state to completed.'
167172
Update-AzDataTableEntity -Force @Table -Entity @{
168173
PartitionKey = $task.PartitionKey
169174
RowKey = $task.RowKey
@@ -190,7 +195,7 @@ function Push-ExecScheduledCommand {
190195
}
191196

192197
$nextRunUnixTime = [int64]$task.ScheduledTime + [int64]$secondsToAdd
193-
Write-Host "The job is recurring. It was scheduled for $($task.ScheduledTime). The next runtime should be $nextRunUnixTime"
198+
Write-Information "The job is recurring. It was scheduled for $($task.ScheduledTime). The next runtime should be $nextRunUnixTime"
194199
Update-AzDataTableEntity -Force @Table -Entity @{
195200
PartitionKey = $task.PartitionKey
196201
RowKey = $task.RowKey

Modules/CIPPCore/Public/Get-CIPPTenantCapabilities.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ function Get-CIPPTenantCapabilities {
2121
}
2222
Add-CIPPAzDataTableEntity @ConfigTable -Entity $Entity -Force
2323
}
24-
$Plans = $Org.servicePlans | Where-Object { $_.provisioningStatus -eq 'Success' } | Sort-Object -Property serviceplanName -Unique | Select-Object servicePlanName, provisioningStatus
24+
$Plans = $Org.servicePlans | Where-Object { $_.provisioningStatus -eq 'Success' -or $_.provisioningStatus -eq 'PendingInput' } | Sort-Object -Property serviceplanName -Unique | Select-Object servicePlanName, provisioningStatus
2525
$Results = @{}
2626
foreach ($Plan in $Plans) {
27-
$Results."$($Plan.servicePlanName)" = $Plan.provisioningStatus -eq 'Success'
27+
$Results."$($Plan.servicePlanName)" = $Plan.provisioningStatus -eq 'Success' -or $Plan.provisioningStatus -eq 'PendingInput'
2828
}
2929
[PSCustomObject]$Results
3030
}

Modules/CippExtensions/Public/Extension Functions/Sync-CippExtensionData.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function Sync-CippExtensionData {
217217
try {
218218
$TenantResults = New-GraphBulkRequest -Requests @($TenantRequests) -tenantid $TenantFilter
219219
} catch {
220-
Throw "Failed to fetch bulk company data: $_"
220+
throw "Failed to fetch bulk company data: $_"
221221
}
222222

223223
$TenantResults | Select-Object id, body | ForEach-Object {
@@ -302,7 +302,6 @@ function Sync-CippExtensionData {
302302
}
303303
}
304304

305-
306305
$LastSync.LastSync = [datetime]::UtcNow.ToString('yyyy-MM-ddTHH:mm:ssZ')
307306
$LastSync.Status = 'Completed'
308307
$LastSync.Error = ''
@@ -313,4 +312,5 @@ function Sync-CippExtensionData {
313312
} finally {
314313
Add-CIPPAzDataTableEntity @Table -Entity $LastSync -Force
315314
}
315+
return $LastSync
316316
}

version_latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.2.1
1+
8.2.2

0 commit comments

Comments
 (0)