@@ -15,38 +15,72 @@ function Invoke-CIPPStandardsRun {
15
15
[Parameter (Mandatory = $false )]
16
16
$TemplateID ,
17
17
[Parameter (Mandatory = $false )]
18
- $runManually = $false
19
-
18
+ $runManually = $false ,
19
+ [Parameter (Mandatory = $false )]
20
+ [switch ]$Drift
20
21
)
21
- Write-Host " Starting process for standards - $ ( $tenantFilter ) . TemplateID: $ ( $TemplateID ) RunManually: $ ( $runManually ) Force: $ ( $Force.IsPresent ) "
22
+ Write-Information " Starting process for standards - $ ( $tenantFilter ) . TemplateID: $ ( $TemplateID ) RunManually: $ ( $runManually ) Force: $ ( $Force.IsPresent ) Drift: $ ( $Drift .IsPresent ) "
22
23
23
- $AllTasks = Get-CIPPStandards
24
+ if ($Drift.IsPresent ) {
25
+ Write-Information ' Drift Standards Run'
26
+ $AllTasks = Get-CIPPTenantAlignment | Where-Object - Property standardtype -EQ ' drift' | Select-Object - Property Tenant | Sort-Object - Unique - Property Tenant
24
27
25
- if ($Force.IsPresent ) {
26
- Write-Host ' Clearing Rerun Cache'
27
- Test-CIPPRerun - ClearAll - TenantFilter $TenantFilter - Type ' Standard'
28
- }
28
+ # For each item in our object, run the queue.
29
+ $Queue = New-CippQueueEntry - Name ' Drift Standards' - TotalTasks ($AllTasks | Measure-Object ).Count
29
30
30
- # For each item in our object, run the queue.
31
- $Queue = New-CippQueueEntry - Name " Applying Standards ($TenantFilter )" - TotalTasks ($AllTasks | Measure-Object ).Count
32
-
33
- $InputObject = [PSCustomObject ]@ {
34
- OrchestratorName = ' StandardsOrchestrator'
35
- QueueFunction = @ {
36
- FunctionName = ' GetStandards'
37
- QueueId = $Queue.RowKey
38
- StandardParams = @ {
39
- TenantFilter = $TenantFilter
40
- runManually = $runManually
31
+ $Batch = foreach ($Task in $AllTasks ) {
32
+ [PSCustomObject ]@ {
33
+ FunctionName = ' CIPPDriftManagement'
34
+ Tenant = $Task.Tenant
41
35
}
42
36
}
43
- SkipLog = $true
44
- }
45
- if ($TemplateID ) {
46
- $InputObject.QueueFunction.StandardParams [' TemplateId' ] = $TemplateID
37
+
38
+ $InputObject = [PSCustomObject ]@ {
39
+ OrchestratorName = ' DriftStandardsOrchestrator'
40
+ Batch = @ ($Batch )
41
+ SkipLog = $true
42
+ }
43
+
44
+ $InstanceId = Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($InputObject | ConvertTo-Json - Depth 5 - Compress)
45
+ Write-Information " Started orchestration with ID = '$InstanceId ' for drift standards run"
46
+ # $Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
47
+ return
48
+ } else {
49
+ Write-Information ' Classic Standards Run'
50
+ $AllTasks = Get-CIPPStandards
51
+
52
+ if ($Force.IsPresent ) {
53
+ Write-Information ' Clearing Rerun Cache'
54
+ Test-CIPPRerun - ClearAll - TenantFilter $TenantFilter - Type ' Standard'
55
+ }
56
+
57
+ if ($AllTasks.Count -eq 0 ) {
58
+ Write-Information " No standards found for tenant $ ( $TenantFilter ) ."
59
+ return
60
+ }
61
+
62
+ # For each item in our object, run the queue.
63
+ $Queue = New-CippQueueEntry - Name " Applying Standards ($TenantFilter )" - TotalTasks ($AllTasks | Measure-Object ).Count
64
+
65
+ $InputObject = [PSCustomObject ]@ {
66
+ OrchestratorName = ' StandardsOrchestrator'
67
+ QueueFunction = @ {
68
+ FunctionName = ' GetStandards'
69
+ QueueId = $Queue.RowKey
70
+ StandardParams = @ {
71
+ TenantFilter = $TenantFilter
72
+ runManually = $runManually
73
+ Drift = $Drift.IsPresent
74
+ }
75
+ }
76
+ SkipLog = $true
77
+ }
78
+ if ($TemplateID ) {
79
+ $InputObject.QueueFunction.StandardParams [' TemplateId' ] = $TemplateID
80
+ }
81
+ Write-Information " InputObject: $ ( $InputObject | ConvertTo-Json - Depth 5 - Compress) "
82
+ $InstanceId = Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($InputObject | ConvertTo-Json - Depth 5 - Compress)
83
+ Write-Information " Started orchestration with ID = '$InstanceId '"
84
+ # $Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
47
85
}
48
- Write-Host " InputObject: $ ( $InputObject | ConvertTo-Json - Depth 5 - Compress) "
49
- $InstanceId = Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($InputObject | ConvertTo-Json - Depth 5 - Compress)
50
- Write-Host " Started orchestration with ID = '$InstanceId '"
51
- # $Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
52
86
}
0 commit comments