Skip to content

Commit ac8901f

Browse files
committed
fix bpa run without templates imported
1 parent 91d48b0 commit ac8901f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,32 @@ function Start-BPAOrchestrator {
3030
}
3131

3232
Write-Verbose 'Getting BPA templates'
33+
34+
3335
$BPATemplateTable = Get-CippTable -tablename 'templates'
3436
$Filter = "PartitionKey eq 'BPATemplate'"
35-
$Templates = ((Get-CIPPAzDataTableEntity @BPATemplateTable -Filter $Filter).JSON | ConvertFrom-Json).Name
37+
try {
38+
$TemplateRows = Get-CIPPAzDataTableEntity @BPATemplateTable -Filter $Filter
39+
40+
if (!$TemplateRows) {
41+
$null = Get-ChildItem 'Config\*.BPATemplate.json' | ForEach-Object {
42+
$TemplateJson = Get-Content $_ | ConvertFrom-Json | ConvertTo-Json -Compress -Depth 10
43+
$Entity = @{
44+
JSON = "$TemplateJson"
45+
RowKey = "$($_.name)"
46+
PartitionKey = 'BPATemplate'
47+
GUID = "$($_.name)"
48+
}
49+
Add-CIPPAzDataTableEntity @Table -Entity $Entity -Force
50+
}
51+
$TemplateRows = Get-CIPPAzDataTableEntity @BPATemplateTable -Filter $Filter
52+
}
3653

54+
$Templates = ($TemplateRows.JSON | ConvertFrom-Json).Name
55+
} catch {
56+
Write-LogMessage -API 'BestPracticeAnalyser' -message 'Could not get BPA templates' -sev Error
57+
return $false
58+
}
3759
Write-Verbose 'Creating orchestrator batch'
3860
$BPAReports = foreach ($Tenant in $TenantList) {
3961
foreach ($Template in $Templates) {

0 commit comments

Comments
 (0)