From b6f0953467919164e5a9b97ff715742b9cec2195 Mon Sep 17 00:00:00 2001 From: Matthias Fleschuetz <13959569+blindzero@users.noreply.github.com> Date: Sat, 31 Oct 2026 21:53:20 +0000 Subject: [PATCH] fix: resolve all 17 PSScriptAnalyzer code scanning findings - New-IdleEntraIDAdapter.ps1: fix aligned-assignment whitespace and replace empty catch blocks with explicit null assignments to satisfy PSAvoidUsingEmptyCatchBlock without changing behaviour - New-IdleEntraIDIdentityProvider.ps1: remove alignment spacing before = in groupOperations/administrativeUnitResults declarations; refactor multi-line -or expression to single-line via $kindIsEmpty helper to fix PSUseConsistentIndentation on continuation lines - New-IdleEntraConnectDirectorySyncProvider.ps1: extract inline script blocks passed as arguments to InvokeRemoteCommand into named variables so that PSScriptAnalyzer can consistently verify their indentation Co-Authored-By: Claude Sonnet 4.6 Claude-Session: https://claude.ai/code/session_01GwCt3MWjHysJWoaP4Nrzrk --- .../New-IdleEntraConnectDirectorySyncProvider.ps1 | 10 ++++++---- .../Private/New-IdleEntraIDAdapter.ps1 | 4 ++-- .../Public/New-IdleEntraIDIdentityProvider.ps1 | 15 +++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/IdLE.Provider.DirectorySync.EntraConnect/Public/New-IdleEntraConnectDirectorySyncProvider.ps1 b/src/IdLE.Provider.DirectorySync.EntraConnect/Public/New-IdleEntraConnectDirectorySyncProvider.ps1 index 68e90a6f..77333cbc 100644 --- a/src/IdLE.Provider.DirectorySync.EntraConnect/Public/New-IdleEntraConnectDirectorySyncProvider.ps1 +++ b/src/IdLE.Provider.DirectorySync.EntraConnect/Public/New-IdleEntraConnectDirectorySyncProvider.ps1 @@ -152,11 +152,12 @@ function New-IdleEntraConnectDirectorySyncProvider { try { $remoteSession = $this.NewRemoteSession($ComputerName, $AuthSession) - $this.InvokeRemoteCommand($remoteSession, { + $syncScript = { param([string] $RemotePolicyType) Import-Module -Name ADSync -ErrorAction Stop Start-ADSyncSyncCycle -PolicyType $RemotePolicyType -ErrorAction Stop - }, @($PolicyType)) | Out-Null + } + $this.InvokeRemoteCommand($remoteSession, $syncScript, @($PolicyType)) | Out-Null return [pscustomobject]@{ Started = $true @@ -220,10 +221,11 @@ function New-IdleEntraConnectDirectorySyncProvider { try { $remoteSession = $this.NewRemoteSession($ComputerName, $AuthSession) - $scheduler = $this.InvokeRemoteCommand($remoteSession, { + $schedulerScript = { Import-Module -Name ADSync -ErrorAction Stop Get-ADSyncScheduler -ErrorAction Stop - }, @()) + } + $scheduler = $this.InvokeRemoteCommand($remoteSession, $schedulerScript, @()) # Determine if sync is in progress # Get-ADSyncScheduler returns an object with SyncCycleInProgress property diff --git a/src/IdLE.Provider.EntraID/Private/New-IdleEntraIDAdapter.ps1 b/src/IdLE.Provider.EntraID/Private/New-IdleEntraIDAdapter.ps1 index 683fc47a..70f23169 100644 --- a/src/IdLE.Provider.EntraID/Private/New-IdleEntraIDAdapter.ps1 +++ b/src/IdLE.Provider.EntraID/Private/New-IdleEntraIDAdapter.ps1 @@ -78,8 +78,8 @@ function New-IdleEntraIDAdapter { # HttpResponseHeaders (PowerShell 7 / HttpClient) does not support # indexer-style access. Use GetValues() with a safety catch for the # case where the header is absent (GetValues throws in that case). - try { $requestId = $_.Exception.Response.Headers.GetValues('request-id') | Select-Object -First 1 } catch { } - try { $retryAfter = $_.Exception.Response.Headers.GetValues('Retry-After') | Select-Object -First 1 } catch { } + try { $requestId = $_.Exception.Response.Headers.GetValues('request-id') | Select-Object -First 1 } catch { $requestId = $null } + try { $retryAfter = $_.Exception.Response.Headers.GetValues('Retry-After') | Select-Object -First 1 } catch { $retryAfter = $null } } } diff --git a/src/IdLE.Provider.EntraID/Public/New-IdleEntraIDIdentityProvider.ps1 b/src/IdLE.Provider.EntraID/Public/New-IdleEntraIDIdentityProvider.ps1 index e201ce85..3db487b9 100644 --- a/src/IdLE.Provider.EntraID/Public/New-IdleEntraIDIdentityProvider.ps1 +++ b/src/IdLE.Provider.EntraID/Public/New-IdleEntraIDIdentityProvider.ps1 @@ -841,10 +841,9 @@ function New-IdleEntraIDIdentityProvider { # When Kind is supplied, only fetch the relevant directory objects. # When Kind is null/empty, fetch both (backward-compatible, e.g. host-level reports). - $includeGroups = [string]::IsNullOrEmpty($Kind) -or - [string]::Equals($Kind, 'Group', [System.StringComparison]::OrdinalIgnoreCase) - $includeAUs = [string]::IsNullOrEmpty($Kind) -or - [string]::Equals($Kind, 'AdministrativeUnit', [System.StringComparison]::OrdinalIgnoreCase) + $kindIsEmpty = [string]::IsNullOrEmpty($Kind) + $includeGroups = $kindIsEmpty -or [string]::Equals($Kind, 'Group', [System.StringComparison]::OrdinalIgnoreCase) + $includeAUs = $kindIsEmpty -or [string]::Equals($Kind, 'AdministrativeUnit', [System.StringComparison]::OrdinalIgnoreCase) $result = @() @@ -1009,8 +1008,8 @@ function New-IdleEntraIDIdentityProvider { # Split entitlements by kind: Groups use the Graph $batch path; AUs are processed per-item # (no Graph batch API exists for Administrative Unit membership changes). - $groupOperations = @() - $administrativeUnitResults = @() + $groupOperations = @() + $administrativeUnitResults = @() foreach ($ent in $Entitlements) { $normalized = $this.ConvertToEntitlement($ent) @@ -1107,8 +1106,8 @@ function New-IdleEntraIDIdentityProvider { # Split entitlements by kind: Groups use the Graph $batch path; AUs are processed per-item # (no Graph batch API exists for Administrative Unit membership changes). - $groupOperations = @() - $administrativeUnitResults = @() + $groupOperations = @() + $administrativeUnitResults = @() foreach ($ent in $Entitlements) { $normalized = $this.ConvertToEntitlement($ent)