Skip to content

Commit 463e40e

Browse files
authored
General optimization
1 parent a0dc873 commit 463e40e

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

EntraID/ConditionalAccess/Export-CAPolicies.ps1

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ function Get-NamedLocationDisplayName {
181181
return $ConvertedNames
182182
}
183183

184+
function Join-Array {
185+
param ([array]$Values)
186+
return ($Values -join ',')
187+
}
188+
184189
#Prep
185190
if (-not (Test-Path -Path $OutputDirectory)) {
186191
New-Item -Path $OutputDirectory -ItemType Directory -Force | Out-Null
@@ -199,7 +204,7 @@ if (-not $IncludeEmptyColumns) {
199204
'Include Device Platform', 'Exclude Device Platform',
200205
'Client Apps', 'Signin Risk',
201206
'Access Control', 'Access Control Operator',
202-
'Authentication Strength', 'Auth Strength Allowed Combo',
207+
'Authentication Strength',
203208
'Signin Frequency Value',
204209
'Creation Time', 'Modified Time'
205210
)
@@ -229,7 +234,7 @@ if (-not $IncludeEmptyColumns) {
229234
'Include Applications', 'Exclude Applications', 'User Action', 'User Risk',
230235
'Signin Risk', 'Client Apps', 'Include Device Platform', 'Exclude Device Platform',
231236
'Include Locations', 'Exclude Locations', 'Access Control', 'Access Control Operator',
232-
'Authentication Strength', 'Auth Strength Allowed Combo',
237+
'Authentication Strength',
233238
'App Enforced Restrictions Enabled', 'Cloud App Security', 'CAE Mode',
234239
'Disable Resilience Defaults', 'Is Signin Frequency Enabled', 'Signin Frequency Value'
235240
)
@@ -268,13 +273,13 @@ $AllPolicies | ForEach-Object {
268273
}
269274

270275
#Calculating recently created and modified days
271-
if ($CreationTime -eq $null) {
276+
if ($null -eq $CreationTime) {
272277
$CreationTime = "-"
273278
} else {
274279
$CreatedInDays = (New-TimeSpan -Start $CreationTime).Days
275280
}
276281

277-
if ($LastModifiedTime -eq $null) {
282+
if ($null -eq $LastModifiedTime) {
278283
$LastModifiedTime = "-"
279284
} else {
280285
$ModifiedInDays = (New-TimeSpan -Start $LastModifiedTime).Days
@@ -306,49 +311,49 @@ $AllPolicies | ForEach-Object {
306311
if ($IncludeUsers.Count -ne 0 -and ($IncludeUsers -ne 'All' -and $IncludeUsers -ne 'None' )) {
307312
$IncludeUsers = ConvertTo-Name -InputIds $IncludeUsers
308313
}
309-
$IncludeUsers = $IncludeUsers -join ","
314+
$IncludeUsers = Join-Array $IncludeUsers
310315

311316
if (($ExcludeUsers.Count -ne 0) -and ($ExcludeUsers -ne 'GuestsOrExternalUsers' )) {
312317
$ExcludeUsers = ConvertTo-Name -InputIds $ExcludeUsers
313318
}
314-
$ExcludeUsers = $ExcludeUsers -join ","
319+
$ExcludeUsers = Join-Array $ExcludeUsers
315320
if ($IncludeGroups.Count -ne 0) {
316321
$IncludeGroups = ConvertTo-Name -InputIds $IncludeGroups
317322
}
318-
$IncludeGroups = $IncludeGroups -join ","
323+
$IncludeGroups = Join-Array $IncludeGroups
319324
if ($ExcludeGroups.Count -ne 0) {
320325
$ExcludeGroups = ConvertTo-Name -InputIds $ExcludeGroups
321326
}
322-
$ExcludeGroups = $ExcludeGroups -join ","
327+
$ExcludeGroups = Join-Array $ExcludeGroups
323328
if ($IncludeRoles.Count -ne 0 -and ($IncludeRoles -ne 'All' -and $IncludeRoles -ne 'None' )) {
324329
$IncludeRoles = ConvertTo-Name -InputIds $IncludeRoles
325330
}
326-
$IncludeRoles = $IncludeRoles -join ","
331+
$IncludeRoles = Join-Array $IncludeRoles
327332
if ($ExcludeRoles.Count -ne 0) {
328333
$ExcludeRoles = ConvertTo-Name -InputIds $ExcludeRoles
329334
}
330-
$ExcludeRoles = $ExcludeRoles -join ","
335+
$ExcludeRoles = Join-Array $ExcludeRoles
331336

332-
$IncludeGuestsOrExtUsers = $IncludeGuestsOrExtUsers -join ","
333-
$ExcludeGuestsOrExtUsers = $ExcludeGuestsOrExtUsers -join ","
337+
$IncludeGuestsOrExtUsers = Join-Array $IncludeGuestsOrExtUsers
338+
$ExcludeGuestsOrExtUsers = Join-Array $ExcludeGuestsOrExtUsers
334339

335340

336341

337342
#Target Resources
338343
$IncludeApplications = $_.Conditions.Applications.IncludeApplications
339344
$ExcludeApplications = $_.Conditions.Applications.ExcludeApplications
340345
$UserAction = $_.Conditions.Applications.IncludeUserActions
341-
$UserAction = $UserAction -join ","
346+
$UserAction = Join-Array $UserAction
342347

343348
#Convert id to names for Target resource properties
344349
if ($IncludeApplications.Count -ne 0 -and ($IncludeApplications -ne 'All' -and $IncludeApplications -ne 'None' )) {
345350
$IncludeApplications = Get-ServicePrincipalDisplayName -InputIds $IncludeApplications
346351
}
347-
$IncludeApplications = $IncludeApplications -join ","
352+
$IncludeApplications = Join-Array $IncludeApplications
348353
if ($ExcludeApplications.Count -ne 0) {
349354
$ExcludeApplications = Get-ServicePrincipalDisplayName -InputIds $ExcludeApplications
350355
}
351-
$ExcludeApplications = $ExcludeApplications -join ","
356+
$ExcludeApplications = Join-Array $ExcludeApplications
352357

353358

354359

@@ -361,30 +366,29 @@ $AllPolicies | ForEach-Object {
361366
$IncludeLocations = $_.Conditions.Locations.IncludeLocations
362367
$ExcludeLocations = $_.Conditions.Locations.ExcludeLocations
363368

364-
$UserRisk = $UserRisk -join ","
365-
$SigninRisk = $SigninRisk -join ","
366-
$ClientApps = $ClientApps -join ","
367-
$IncludeDevicePlatform = $IncludeDevicePlatform -join ","
368-
$ExcludeDevicePlatform = $ExcludeDevicePlatform -join ","
369+
$UserRisk = Join-Array $UserRisk
370+
$SigninRisk = Join-Array $SigninRisk
371+
$ClientApps = Join-Array $ClientApps
372+
$IncludeDevicePlatform = Join-Array $IncludeDevicePlatform
373+
$ExcludeDevicePlatform = Join-Array $ExcludeDevicePlatform
369374

370375
#Convert location id to Name
371376
if ($IncludeLocations.Count -ne 0 -and $IncludeLocations -ne 'All' -and $IncludeLocations -ne 'AllTrusted') {
372377
$IncludeLocations = Get-NamedLocationDisplayName -InputIds $IncludeLocations
373378
}
374-
$IncludeLocations = $IncludeLocations -join ","
379+
$IncludeLocations = Join-Array $IncludeLocations
375380

376381
if ($ExcludeLocations.Count -ne 0) {
377382
$ExcludeLocations = Get-NamedLocationDisplayName -InputIds $ExcludeLocations
378383
}
379-
$ExcludeLocations = $ExcludeLocations -join ","
384+
$ExcludeLocations = Join-Array $ExcludeLocations
380385

381386

382387

383388
#Grant Control
384389
$AccessControl = $_.GrantControls.BuiltInControls -join ","
385390
$AccessControlOperator = $_.GrantControls.Operator
386391
$AuthenticationStrength = $_.GrantControls.AuthenticationStrength.DisplayName
387-
$AuthenticationStrengthAllowedCombo = $_.GrantControls.AuthenticationStrength.AllowedCombinations -join ","
388392

389393
#Session Control
390394
$AppEnforcedRestrictions = $_.SessionControls.ApplicationEnforcedRestrictions.IsEnabled
@@ -433,7 +437,6 @@ $AllPolicies | ForEach-Object {
433437
'Access Control' = $AccessControl;
434438
'Access Control Operator' = $AccessControlOperator;
435439
'Authentication Strength' = $AuthenticationStrength;
436-
'Auth Strength Allowed Combo' = $AuthenticationStrengthAllowedCombo;
437440
'App Enforced Restrictions Enabled' = $AppEnforcedRestrictions;
438441
'Cloud App Security' = $CloudAppSecurity;
439442
'CAE Mode' = $CAEMode;
@@ -442,7 +445,7 @@ $AllPolicies | ForEach-Object {
442445
'Signin Frequency Value' = $SignInFrequencyValue;
443446
'State' = $State
444447
}
445-
$Results += New-Object PSObject -Property $Result
448+
$Results += [pscustomobject]$Result
446449
}
447450

448451

0 commit comments

Comments
 (0)