|
| 1 | +function Invoke-CippTestZTNA21865 { |
| 2 | + param($Tenant) |
| 3 | + |
| 4 | + $TestId = 'ZTNA21865' |
| 5 | + |
| 6 | + try { |
| 7 | + $NamedLocations = New-CIPPDbRequest -TenantFilter $Tenant -Type 'NamedLocations' |
| 8 | + |
| 9 | + if (-not $NamedLocations) { |
| 10 | + Add-CippTestResult -TenantFilter $Tenant -TestId $TestId -TestType 'Identity' -Status 'Investigate' -ResultMarkdown 'Named locations not found in database' -Risk 'Medium' -Name 'Named locations are configured' -UserImpact 'Low' -ImplementationEffort 'Low' -Category 'Application management' |
| 11 | + return |
| 12 | + } |
| 13 | + |
| 14 | + $TrustedLocations = @($NamedLocations | Where-Object { $_.isTrusted -eq $true }) |
| 15 | + $Passed = $TrustedLocations.Count -gt 0 |
| 16 | + |
| 17 | + if ($Passed) { |
| 18 | + $ResultMarkdown = "✅ Trusted named locations are configured.`n`n" |
| 19 | + } else { |
| 20 | + $ResultMarkdown = "❌ No trusted named locations configured.`n`n" |
| 21 | + } |
| 22 | + |
| 23 | + $ResultMarkdown += "## Named Locations`n`n" |
| 24 | + $ResultMarkdown += "$($NamedLocations.Count) named locations found.`n`n" |
| 25 | + |
| 26 | + if ($NamedLocations.Count -gt 0) { |
| 27 | + $ResultMarkdown += "| Name | Type | Trusted |`n" |
| 28 | + $ResultMarkdown += "| :--- | :--- | :------ |`n" |
| 29 | + |
| 30 | + foreach ($Location in $NamedLocations) { |
| 31 | + $Name = $Location.displayName |
| 32 | + $Type = if ($Location.'@odata.type' -eq '#microsoft.graph.ipNamedLocation') { 'IP-based' } |
| 33 | + elseif ($Location.'@odata.type' -eq '#microsoft.graph.countryNamedLocation') { 'Country-based' } |
| 34 | + else { 'Unknown' } |
| 35 | + $Trusted = if ($Location.isTrusted) { 'Yes' } else { 'No' } |
| 36 | + $ResultMarkdown += "| $Name | $Type | $Trusted |`n" |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + $Status = if ($Passed) { 'Passed' } else { 'Failed' } |
| 41 | + Add-CippTestResult -TenantFilter $Tenant -TestId $TestId -TestType 'Identity' -Status $Status -ResultMarkdown $ResultMarkdown -Risk 'Medium' -Name 'Named locations are configured' -UserImpact 'Low' -ImplementationEffort 'Low' -Category 'Application management' |
| 42 | + |
| 43 | + } catch { |
| 44 | + $ErrorMessage = Get-CippException -Exception $_ |
| 45 | + Write-LogMessage -API 'Tests' -tenant $Tenant -message "Failed to run test: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage |
| 46 | + Add-CippTestResult -TenantFilter $Tenant -TestId $TestId -TestType 'Identity' -Status 'Failed' -ResultMarkdown "Error running test: $($ErrorMessage.NormalizedError)" -Risk 'Medium' -Name 'Named locations are configured' -UserImpact 'Low' -ImplementationEffort 'Low' -Category 'Application management' |
| 47 | + } |
| 48 | +} |
0 commit comments