@@ -28,13 +28,7 @@ function Get-CIPPTenantAlignment {
2828 $TemplateFilter = " PartitionKey eq 'StandardsTemplateV2'"
2929 try {
3030 # Get all standard templates
31- $Templates = Measure-CippTask - TaskName ' LoadTemplates' - EventName ' CIPP.AlignmentStatus' - Metadata @ {
32- Tenant = $TenantFilter
33- Section = ' LoadTemplates'
34- } - Script {
35-
36-
37- (Get-CIPPAzDataTableEntity @TemplateTable - Filter $TemplateFilter ) | ForEach-Object {
31+ $Templates = (Get-CIPPAzDataTableEntity @TemplateTable - Filter $TemplateFilter ) | ForEach-Object {
3832 $JSON = $_.JSON -replace ' "Action":' , ' "action":'
3933 try {
4034 $RowKey = $_.RowKey
@@ -48,7 +42,6 @@ function Get-CIPPTenantAlignment {
4842 $Data
4943 }
5044 }
51- }
5245
5346 if (-not $Templates ) {
5447 Write-Warning ' No templates found matching the criteria'
@@ -71,25 +64,16 @@ function Get-CIPPTenantAlignment {
7164 }
7265
7366 # Filter by tenant if specified
74- $Standards = Measure-CippTask - TaskName ' FilterTenants' - EventName ' CIPP.AlignmentStatus' - Metadata @ {
75- Tenant = $TenantFilter
76- Section = ' FilterTenants'
77- } - Script {
78- if ($TenantFilter ) {
79- $AllStandards | Where-Object { $_.PartitionKey -eq $TenantFilter }
80- } else {
81- $Tenants = Get-Tenants - IncludeErrors
82- $AllStandards | Where-Object { $_.PartitionKey -in $Tenants.defaultDomainName }
83- }
67+ $Standards = if ($TenantFilter ) {
68+ $AllStandards | Where-Object { $_.PartitionKey -eq $TenantFilter }
69+ } else {
70+ $Tenants = Get-Tenants - IncludeErrors
71+ $AllStandards | Where-Object { $_.PartitionKey -in $Tenants.defaultDomainName }
8472 }
8573
8674 # Build tenant standards data structure
87- $TenantStandards = Measure-CippTask - TaskName ' BuildTenantData' - EventName ' CIPP.AlignmentStatus' - Metadata @ {
88- Tenant = $TenantFilter
89- Section = ' BuildTenantData'
90- } - Script {
91- $tenantData = @ {}
92- foreach ($Standard in $Standards ) {
75+ $tenantData = @ {}
76+ foreach ($Standard in $Standards ) {
9377 $FieldName = $Standard.RowKey
9478 $FieldValue = $Standard.Value
9579 $Tenant = $Standard.PartitionKey
@@ -111,25 +95,20 @@ function Get-CIPPTenantAlignment {
11195 $FieldValue = [string ]$FieldValue
11296 }
11397
114- if (-not $tenantData.ContainsKey ($Tenant )) {
115- $tenantData [$Tenant ] = @ {}
116- }
117- $tenantData [$Tenant ][$FieldName ] = @ {
118- Value = $FieldValue
119- LastRefresh = $Standard.TimeStamp.ToUniversalTime ().ToString(' yyyy-MM-ddTHH:mm:ssZ' )
120- }
98+ if (-not $tenantData.ContainsKey ($Tenant )) {
99+ $tenantData [$Tenant ] = @ {}
100+ }
101+ $tenantData [$Tenant ][$FieldName ] = @ {
102+ Value = $FieldValue
103+ LastRefresh = $Standard.TimeStamp.ToUniversalTime ().ToString(' yyyy-MM-ddTHH:mm:ssZ' )
121104 }
122- return $tenantData
123105 }
106+ $TenantStandards = $tenantData
124107
125108 $Results = [System.Collections.Generic.List [object ]]::new()
126109
127110 # Process each template against all tenants
128- Measure-CippTask - TaskName ' ProcessTemplates' - EventName ' CIPP.AlignmentStatus' - Metadata @ {
129- Tenant = $TenantFilter
130- Section = ' ProcessTemplates'
131- } - Script {
132- foreach ($Template in $Templates ) {
111+ foreach ($Template in $Templates ) {
133112 $TemplateStandards = $Template.standards
134113 if (-not $TemplateStandards ) {
135114 continue
@@ -332,7 +311,6 @@ function Get-CIPPTenantAlignment {
332311 $Results.Add ($Result )
333312 }
334313 }
335- }
336314
337315 return $Results
338316 } catch {
0 commit comments