@@ -49,6 +49,7 @@ Revision History:
4949 0.1.0 – 06/30/2024 – Initial version from upstream
5050#>
5151
52+ # region Parameters
5253param
5354(
5455 [switch ]$ActiveCAPoliciesOnly ,
6667
6768)
6869
70+ # endregion
71+
72+ # region Module Loading
6973$RequiredModules = @ (' Microsoft.Graph.Beta' )
7074
7175foreach ($mod in $RequiredModules ) {
@@ -94,10 +98,16 @@ foreach ($sub in $RequiredSubmodules) {
9498
9599
96100
101+ # endregion
102+
103+ # region Global Hash Caches
97104$global :DirectoryObjsHash = @ {}
98105$global :ServicePrincipalsHash = @ {}
99106$global :NamedLocationHash = @ {}
100107
108+ # endregion
109+
110+ # region Graph Connection
101111function Connect-MgGraphSession {
102112 if ($CreateSession.IsPresent ) {
103113 Disconnect-MgGraph - ErrorAction SilentlyContinue
@@ -114,6 +124,9 @@ function Connect-MgGraphSession {
114124
115125Connect-MgGraphSession
116126
127+ # endregion
128+
129+ # region Conversion Helpers
117130function ConvertTo-DirectoryObjectName {
118131 param (
119132 [Parameter (Mandatory = $true )]
@@ -182,11 +195,17 @@ function Get-NamedLocationDisplayName {
182195 return $ConvertedNames
183196}
184197
198+ # endregion
199+
200+ # region Utility Functions
185201function Join-Array {
186202 param ([array ]$Values )
187203 return ($Values -join ' ,' )
188204}
189205
206+ # endregion
207+
208+ # region Prep and Output Path Setup
190209# Prep
191210if (-not (Test-Path - Path $OutputDirectory )) {
192211 New-Item - Path $OutputDirectory - ItemType Directory - Force | Out-Null
@@ -242,6 +261,9 @@ if (-not $IncludeEmptyColumns) {
242261 $Results | Select-Object - Property $orderedHeaders | Export-Csv - Path $ExportCSV - NoTypeInformation
243262}
244263
264+ # endregion
265+
266+ # region Service Principal and Location Lookup
245267$ProcessedCount = 0
246268$OutputCount = 0
247269# Get all service principals
@@ -252,6 +274,9 @@ $NamedLocationHash = Get-MgBetaIdentityConditionalAccessNamedLocation -All | Gro
252274Write-Progress - Activity " Exporting" - Status " Retrieving CA policies..." - PercentComplete 30
253275
254276
277+ # endregion
278+
279+ # region Policy Retrieval and Processing
255280# Processing all CA policies
256281$AllPolicies = Get-MgBetaIdentityConditionalAccessPolicy - All
257282$total = $AllPolicies.Count
@@ -450,6 +475,9 @@ $AllPolicies | ForEach-Object {
450475}
451476
452477
478+ # endregion
479+
480+ # region Final Output and Export
453481if ($Results.Count -eq 0 ) {
454482 Write-Host " No data found for the given criteria."
455483} else {
0 commit comments