Skip to content

Commit f57e286

Browse files
version latest
1 parent 20f94fc commit f57e286

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
function Invoke-ListStandardsCurrentState {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
.ROLE
6+
Tenant.Standards.Read
7+
#>
8+
[CmdletBinding()]
9+
param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$TenantFilter = $Request.Query.tenantFilter
13+
14+
if (-not $TenantFilter) {
15+
return [HttpResponseContext]@{
16+
StatusCode = [HttpStatusCode]::BadRequest
17+
Body = @{ Results = 'tenantFilter is required' }
18+
}
19+
}
20+
21+
try {
22+
$Table = Get-CIPPTable -TableName 'CippStandardsReports'
23+
$Filter = "PartitionKey eq '$TenantFilter'"
24+
$Standards = @(Get-CIPPAzDataTableEntity @Table -Filter $Filter)
25+
26+
$Results = foreach ($Standard in $Standards) {
27+
$CurrentValue = if ($Standard.CurrentValue -and (Test-Json -Json $Standard.CurrentValue -ErrorAction SilentlyContinue)) {
28+
ConvertFrom-Json -InputObject $Standard.CurrentValue -ErrorAction SilentlyContinue
29+
} else {
30+
$Standard.CurrentValue
31+
}
32+
33+
$ExpectedValue = if ($Standard.ExpectedValue -and (Test-Json -Json $Standard.ExpectedValue -ErrorAction SilentlyContinue)) {
34+
ConvertFrom-Json -InputObject $Standard.ExpectedValue -ErrorAction SilentlyContinue
35+
} else {
36+
$Standard.ExpectedValue
37+
}
38+
39+
$FieldValue = $Standard.Value
40+
if ($FieldValue -is [System.Boolean]) {
41+
$FieldValue = [bool]$FieldValue
42+
} elseif ($FieldValue -and (Test-Json -Json "$FieldValue" -ErrorAction SilentlyContinue)) {
43+
$FieldValue = ConvertFrom-Json -InputObject $FieldValue -ErrorAction SilentlyContinue
44+
}
45+
46+
$IsCompliant = ($FieldValue -eq $true) -or ($Standard.CurrentValue -and $Standard.CurrentValue -eq $Standard.ExpectedValue)
47+
48+
[PSCustomObject]@{
49+
StandardName = $Standard.RowKey
50+
Compliant = $IsCompliant
51+
CurrentValue = $CurrentValue
52+
ExpectedValue = $ExpectedValue
53+
Value = $FieldValue
54+
LicenseAvailable = $Standard.LicenseAvailable
55+
LastRefresh = if ($Standard.TimeStamp) { $Standard.TimeStamp.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') } else { $null }
56+
}
57+
}
58+
59+
return [HttpResponseContext]@{
60+
StatusCode = [HttpStatusCode]::OK
61+
Body = @($Results)
62+
}
63+
} catch {
64+
$ErrorMessage = Get-CippException -Exception $_
65+
Write-LogMessage -API $APIName -tenant $TenantFilter -message "Failed to get standards current state: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
66+
return [HttpResponseContext]@{
67+
StatusCode = [HttpStatusCode]::InternalServerError
68+
Body = @{ Results = "Failed: $($ErrorMessage.NormalizedError)" }
69+
}
70+
}
71+
}

version_latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10.3.1
1+
10.4.0

0 commit comments

Comments
 (0)