Summary
Import-GatekeeperConfig pre-parses logging scripts into $script:GatekeeperLogging. Invoke-Logging ignores this cache entirely and re-creates the scriptblock from raw config on every matching rule evaluation. Beyond the unnecessary overhead, calling [scriptblock]::Create() on a value that is already a scriptblock stringifies it first, losing any closure context.
File
Gatekeeper/Private/Invoke-Logging.ps1:17
Current Code
$sb = [scriptblock]::Create($logSettings.Script) # ignores $script:GatekeeperLogging
& $sb -Rule $Rule
Fix
$sb = $script:GatekeeperLogging[$Effect]
if ($null -ne $sb) {
& $sb -Rule $Rule
}
This also resolves the inconsistency where Test-FeatureFlag loads config in begin{} into an unused $config variable (that dead code can be removed, see Issue #24).
Notes
- Found by Jordan B. and Sage Nakamura
Summary
Import-GatekeeperConfigpre-parses logging scripts into$script:GatekeeperLogging.Invoke-Loggingignores this cache entirely and re-creates the scriptblock from raw config on every matching rule evaluation. Beyond the unnecessary overhead, calling[scriptblock]::Create()on a value that is already a scriptblock stringifies it first, losing any closure context.File
Gatekeeper/Private/Invoke-Logging.ps1:17Current Code
Fix
This also resolves the inconsistency where
Test-FeatureFlagloads config inbegin{}into an unused$configvariable (that dead code can be removed, see Issue #24).Notes