Skip to content

Commit a348e9e

Browse files
authored
Merge pull request #1 from fadwen/fix/audit-claims-vs-code
0.26.0: fix what the claims audit found, in code and help
2 parents cbf19d6 + 19ab21c commit a348e9e

70 files changed

Lines changed: 941 additions & 361 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Build/Build-RuleReference.ps1‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,20 @@ function Resolve-Text {
6565
param($Ast, [object[]]$Assignments)
6666
if ($null -eq $Ast) { return '' }
6767
switch ($Ast.GetType().Name) {
68-
'StringConstantExpressionAst' { return $Ast.Value }
69-
'ExpandableStringExpressionAst' { return $Ast.Value }
68+
# A literal $ (single-quoted, or escaped in a double-quoted string) is text, not a value:
69+
# marked so the placeholder pass leaves it alone
70+
'StringConstantExpressionAst' { return $Ast.Value.Replace('$', [string][char]1) }
71+
'ExpandableStringExpressionAst' {
72+
$text = $Ast.Value
73+
foreach ($nested in ($Ast.NestedExpressions | Sort-Object { $_.Extent.StartOffset } -Descending)) {
74+
$index = $text.LastIndexOf($nested.Extent.Text)
75+
if ($index -ge 0) {
76+
$text = $text.Substring(0, $index) + '<value>' +
77+
$text.Substring($index + $nested.Extent.Text.Length)
78+
}
79+
}
80+
return $text.Replace('$', [string][char]1)
81+
}
7082
'ParenExpressionAst' {
7183
$inner = $Ast.Pipeline.PipelineElements[0]
7284
if ($inner.PSObject.Properties['Expression']) {
@@ -142,6 +154,7 @@ function ConvertTo-Placeholder {
142154
$text = [regex]::Replace($Text, '\$\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)', '<value>')
143155
$text = [regex]::Replace($text, '\$\{[^}]+\}', '<value>')
144156
$text = [regex]::Replace($text, '\$[A-Za-z_][\w:]*', '<value>')
157+
$text = $text.Replace([string][char]1, '$')
145158
($text -replace '\s+', ' ').Trim()
146159
}
147160

‎CHANGELOG.md‎

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,88 @@ release notes.
1313

1414
Nothing yet.
1515

16+
## [0.26.0] - 2026-09-28
17+
18+
Every claim the module makes, in its README, help, about topic, rule reference, examples and
19+
changelog, was checked against the code and by running it. What follows is what did not hold.
20+
21+
### Fixed
22+
23+
- **`-Settings` never reached the analysis.** `Test-IntuneDeployedScript` and
24+
`Compare-IntuneDeployedScript` overwrote their `Settings` parameter with a body-level
25+
`$settings` hashtable (variable names are case-insensitive) and then tested
26+
`$PSBoundParameters` inside a nested function, where it is that function's own. The
27+
pre-flight ran its normal settings-file search instead, and the drift compare ignored the
28+
hashtable. `Get-IntuneScriptHealth` forwarded the parameter to both, so it lost it too.
29+
- **`-Id` on its own selected every policy** in the three Graph commands, because `-Name`
30+
defaults to `*` and selection was name or id. `-Id` alone now selects by id.
31+
- **`Repair-IntuneScript -Path <folder> -WhatIf` returned nothing.** The folder was enumerated
32+
through `ForEach-Object -MemberName`, which honours `-WhatIf`. `Test-IntuneScript` had the
33+
same construct and returned no findings for a folder while `$WhatIfPreference` was set.
34+
- **The encoding fix corrupted ANSI files.** A BOM-less file that was not UTF-8 was decoded as
35+
UTF-8 and written back with every non-ASCII character replaced by U+FFFD. Repair now reads
36+
such a file in the system ANSI code page, and `IslEncodingIssue` reports it as ANSI
37+
(Information) rather than as UTF-8 without a BOM.
38+
- **A type declared in a directive earned the assumed-context note** and was called a portal
39+
default. A directive is a declaration; the note is for inferred types only.
40+
- **A settings file's `ExcludeRule` beat an explicit `-IncludeRule`.** An explicit include now
41+
sets the file's exclusions aside; `-ExcludeRule` still adds to them.
42+
- **`Should-PassIntuneAnalysis` failed on a pipeline of files**, joining their paths into one.
43+
It now analyzes every file and names the ones that fail.
44+
- **SARIF:** every rule was given the level `warning`; it now carries the level of the most
45+
severe finding it produced in the log. A finding outside `-Root` was written as an escaped
46+
relative URI under the root; it is now an absolute file URI. A relative `-Path` was resolved
47+
against the process directory, as was `Get-IntuneScriptHealth -MarkdownPath`.
48+
- **A missing script path** made the harness return a result with a made-up exit code instead
49+
of an error.
50+
- **`Get-IntuneAgentTimeline -Id`** returned every timeline whose lines mentioned the id (a
51+
relationship report names two apps); it now returns the timeline whose own id it is. A
52+
relationship report is an outcome.
53+
- **`Compare-IntuneDeployedScript`** compared content without regard to case, so a change in
54+
letter case only came back as "the bytes differ outside the UTF-8 text".
55+
- **A user-context Win32 app assigned to All devices** was not flagged, only one assigned to a
56+
device group.
57+
- **`Get-IntuneScriptHealth -SkipAnalysis`** called an unassigned policy Healthy, because the
58+
check read a finding. It now reads the assignments.
59+
- **`IslFilterIssue`** called `-ne` and `-notIn` with a value no device reports "never matches";
60+
such a clause matches every device, and is reported so, as Information.
61+
- **`IslInteractiveCall`** took a bare `-Confirm`, which forces the prompt, as silencing it.
62+
- **`IslOutputIssue`** took `$ErrorActionPreference = 'Stop'` as guarding a probing cmdlet;
63+
Stop puts the miss on stderr, which is the failure the rule warns about.
64+
- **`IslPowerShell7Syntax`** reported a `using module` the parser could not find as PowerShell 7
65+
syntax, and listed `Get-Process -CommandLine` and `New-TemporaryFile -Extension`, which exist
66+
on neither host.
67+
- **`IslScriptSize`** called Win32 detection and requirement scripts remediations; it now names
68+
them and says the remediation limits are assumed for them, since only remediations and
69+
platform scripts were measured.
70+
- **A stored-password task the scheduler never launches** made the harness wait out the whole
71+
timeout. For an account without the "Log on as a batch job" right the lab device no longer
72+
answers `0x80070569`; the task sits Ready with `0x00041303` ("has not run yet") and no error
73+
anywhere. Five seconds of that is now reported as the refusal, with the same hint.
74+
- **`Test-IntuneScript -EnforceSignatureCheck:$false`** was not explicit, so a tenant script's
75+
own directive could turn the check on under the pre-flight.
76+
- A typo in the `IslContextIssue` message; the AgentTimeline `Duration` column dropped days;
77+
the workflow template's runtime job did not split a comma-separated `SCRIPT_PATHS`.
78+
79+
### Changed
80+
81+
- The reporting lag in `Get-IntuneScriptHealth`'s help is the measured one: a remediation's
82+
changed result reaches Graph with the agent's next hourly report batch (65 minutes after the
83+
run on 2026-09-29), a platform script's in 2-8 s, an app's in 30-39 s; an unchanged result is
84+
not re-reported, so `lastStateUpdateDateTime` is the last change. `Get-IntuneAgentTimeline`'s
85+
help gave the remediation report codes wrong: 3 is no issue, 4 is the remediation having run
86+
(fixed or not), 5 is a detection script failure.
87+
- The rule reference keeps literal names such as `$PSScriptRoot` in a message instead of
88+
replacing them with `<value>`.
89+
- The manifest description names the whole module; the README's links into the repository are
90+
absolute, since the README ships in the package and `docs/` and `Validation/` do not.
91+
- Help corrections throughout: what each result carries (`RunAs`, `IntuneError` as the stderr
92+
tail, `SignatureStatus` always present), the complete status lists, the events
93+
`Get-IntuneAgentLog` names, the Id rule, what `-SkipRegistry` leaves out, the ARM64 note on
94+
the x64 default, the base requirements `Test-IntuneWin32Requirement` covers, how names are
95+
matched and which local files count as `NotInTenant`, the Attention rules, and the
96+
`Applied` count under `-WhatIf`.
97+
1698
## [0.25.0] - 2026-09-28
1799

18100
The first release from this repository, and the first published to the PowerShell Gallery.
@@ -280,5 +362,6 @@ Nothing any command does has changed.
280362

281363
- Static rules: `Test-IntuneScript`.
282364

283-
[Unreleased]: https://github.com/fadwen/IntuneScriptLab/compare/v0.25.0...HEAD
365+
[Unreleased]: https://github.com/fadwen/IntuneScriptLab/compare/v0.26.0...HEAD
366+
[0.26.0]: https://github.com/fadwen/IntuneScriptLab/compare/v0.25.0...v0.26.0
284367
[0.25.0]: https://github.com/fadwen/IntuneScriptLab/releases/tag/v0.25.0

‎CLAUDE.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ The harness launches `powershell.exe` hosts by architecture, reads the registry
7070
scheduled tasks, so the suites run on Windows only: the `desktop` job under 5.1 and the `arm64`
7171
job on Windows on ARM. The `help` job proves the module imports on Linux; nothing else there runs.
7272

73+
### Variable names are case-insensitive, and nested functions have their own `$PSBoundParameters`
74+
75+
A body-level `$settings = @{ ... }` silently overwrote the `-Settings` parameter of two commands,
76+
and `$PSBoundParameters.ContainsKey('Settings')` inside a nested helper was the helper's own,
77+
always false. Name locals so they cannot collide with a parameter, and capture what a nested
78+
function needs from `$PSBoundParameters` into a plain variable before defining it. 0.26.0 fixed
79+
both, with tests.
80+
7381
### A nested function returning `@()` hands the caller `$null`
7482

7583
Several public commands use nested helper functions. PowerShell unrolls an empty array on the

‎Examples/IntuneScriptLab.settings.psd1‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
@{
22
# IntuneScriptLab.settings.psd1: put it in the folder that holds the scripts, or any folder
33
# above them; the nearest one applies to every script below it. Every key is optional.
4-
# Explicit parameters to Test-IntuneScript win over these; a '# IntuneScriptLab:' directive in
5-
# a script wins over the type, context, architecture and signature entries.
4+
# Explicit parameters to Test-IntuneScript win over these (-ExcludeRule adds to ExcludeRule,
5+
# -IncludeRule sets it aside); a '# IntuneScriptLab:' directive in a script wins over the type,
6+
# context, architecture and signature entries.
67

78
# Rules to skip everywhere (wildcards allowed). The context note is the usual one to drop once
89
# the folder layout or the entries below settle every script's type.

‎Examples/intune-script-gate.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# IntuneScriptLab gate for a repository of Intune scripts. Copy to .github/workflows/ and set the
22
# paths. On every pull request that touches a script it runs the analysis the way Intune will run
3-
# the scripts, annotates the changed files with the findings, writes a job summary and fails on
3+
# the scripts, annotates the scripts under the paths you set with the findings, writes a job summary and fails on
44
# errors. The optional second job runs the runtime harness on a Windows runner.
55
#
66
# Where the module comes from: a copy checked into the repository when ISL_MODULE_PATH points at
@@ -97,7 +97,7 @@ jobs:
9797
$env:PSModulePath = "$root$([IO.Path]::PathSeparator)$env:PSModulePath"
9898
}
9999
$config = New-PesterConfiguration
100-
$config.Run.Path = $env:SCRIPT_PATHS
100+
$config.Run.Path = @($env:SCRIPT_PATHS -split ',' | ForEach-Object { $_.Trim() })
101101
$config.Run.Exit = $true
102102
$config.Output.Verbosity = 'Detailed'
103103
Invoke-Pester -Configuration $config

‎IntuneScriptLab.Format.ps1xml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@
298298
<PropertyName>Name</PropertyName>
299299
</TableColumnItem>
300300
<TableColumnItem>
301-
<ScriptBlock>$_.Duration.ToString('hh\:mm\:ss')</ScriptBlock>
301+
<ScriptBlock>
302+
if ($_.Duration.Days) { '{0}d {1}' -f $_.Duration.Days, $_.Duration.ToString('hh\:mm\:ss') }
303+
else { $_.Duration.ToString('hh\:mm\:ss') }
304+
</ScriptBlock>
302305
</TableColumnItem>
303306
<TableColumnItem>
304307
<PropertyName>Runs</PropertyName>

‎IntuneScriptLab.psd1‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
@{
22
# Module manifest for IntuneScriptLab
33
RootModule = 'IntuneScriptLab.psm1'
4-
ModuleVersion = '0.25.0'
4+
ModuleVersion = '0.26.0'
55
GUID = '3f6b2c9e-7d41-4a8f-9c2b-5e0d8a1f4b76'
66
Author = 'Jeffrey Stuhr'
77
CompanyName = ''
88
Copyright = '(c) 2026 Jeffrey Stuhr. All rights reserved.'
9-
# One line, within the repository's 115-character limit; the README carries the long form
10-
Description = 'Test Intune scripts before Intune does: static analysis, a runtime harness, Pester assertions'
9+
# Two lines, within the repository's 115-character limit; the README carries the long form
10+
Description = @'
11+
Test Intune scripts before Intune does: static rules, a runtime harness, Pester assertions, a Graph
12+
pre-flight over the tenant's deployed scripts and readers for the agent's logs
13+
'@
1114

1215
# The analyzer itself runs anywhere. The rules describe Windows PowerShell 5.1 behaviour
1316
# because that is what the Intune Management Extension runs scripts with.
@@ -61,6 +64,18 @@
6164
LicenseUri = 'https://github.com/fadwen/IntuneScriptLab/blob/main/LICENSE'
6265
ProjectUri = 'https://github.com/fadwen/IntuneScriptLab'
6366
ReleaseNotes = @'
67+
0.26.0 - Every claim in the README, help, about topic, rule reference and examples was checked
68+
against the code and by running it, and what did not hold was fixed: -Settings never
69+
reached the pre-flight or the drift compare; -Id alone selected every policy;
70+
Repair-IntuneScript -WhatIf on a folder returned nothing; the encoding fix corrupted
71+
ANSI files; a directive earned the assumed-context note; a settings file's ExcludeRule
72+
beat an explicit -IncludeRule; Should-PassIntuneAnalysis failed on a pipeline of files;
73+
SARIF rule levels, outside-root URIs and relative output paths; a missing script path
74+
returned a result; timeline -Id and relationship reports; case-insensitive drift
75+
compare; All devices for a user-context app; -SkipAnalysis hiding 'assigned to nobody';
76+
-ne/-notIn filter values; a bare -Confirm; Stop as a guard; using module and two
77+
parameters in the PowerShell 7 rule; Win32 scripts in the size rule. Help corrected
78+
throughout. See CHANGELOG.md.
6479
0.25.0 - The first release from the module's own repository, github.com/fadwen/IntuneScriptLab, and
6580
the first published to the PowerShell Gallery. Nothing any command does has changed: the
6681
build scripts moved under Build\, the manifest points at the new repository, and releases

‎Private/ConvertFrom-IslFilterRule.ps1‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,16 @@ function ConvertFrom-IslFilterRule {
177177
Write-Failure "an empty string is refused $where; compare with `$null for a device without a value"
178178
return
179179
}
180-
if ($Property.Values -and ($isList -or $Operator -in 'eq', 'ne')) {
180+
if ($Property.Values -and $Operator -in 'eq', 'in', 'ne', 'notIn') {
181+
# -eq and -in with such a value match nobody; -ne and -notIn match every device
182+
$positive = $Operator -in 'eq', 'in'
181183
foreach ($item in @($value)) {
182184
if ($null -ne $item -and "$item".Trim() -notin $Property.Values) {
183-
Add-Warning -Kind 'NeverMatches' -Message ("'$item' is not a value a Windows device reports " +
184-
"for device.$($Property.Name) ($($Property.Values -join ', ')); the clause at position " +
185-
"$($token.Position) never matches")
185+
$warningKind = if ($positive) { 'NeverMatches' } else { 'AlwaysMatches' }
186+
$effect = if ($positive) { 'never matches' } else { 'matches every device' }
187+
Add-Warning -Kind $warningKind -Message ("'$item' is not a value a Windows device reports " +
188+
"for device.$($Property.Name) ($($Property.Values -join ', ')); the clause at character " +
189+
"$($token.Position) $effect")
186190
}
187191
}
188192
}

‎Private/Get-IslOemEncoding.ps1‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,26 @@
88
(437 on US systems), which is what turned "Grüße — ✓" into "Grüße - √" in Intune's
99
reports. Read it from the registry rather than CultureInfo, which lies under invariant
1010
globalization, and register the legacy code pages when running on .NET Core.
11+
12+
.PARAMETER Kind
13+
OEM (the default) is what a console-less powershell.exe writes its output in; ANSI is
14+
what Windows PowerShell 5.1 reads a file without a BOM as.
1115
#>
1216
[CmdletBinding()]
1317
[OutputType([System.Text.Encoding])]
14-
param()
18+
param(
19+
[ValidateSet('OEM', 'ANSI')]
20+
[string]$Kind = 'OEM'
21+
)
1522

16-
$codePage = 437
23+
$valueName = if ($Kind -eq 'ANSI') { 'ACP' } else { 'OEMCP' }
24+
$codePage = if ($Kind -eq 'ANSI') { 1252 } else { 437 }
1725
try {
1826
$key = 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage'
19-
$value = (Get-ItemProperty -Path $key -Name OEMCP -ErrorAction Stop).OEMCP
27+
$value = (Get-ItemProperty -Path $key -Name $valueName -ErrorAction Stop).$valueName
2028
if ($value -match '^\d+$') { $codePage = [int]$value }
2129
}
22-
catch { Write-Verbose "OEMCP not readable from the registry, assuming $codePage" }
30+
catch { Write-Verbose "$valueName not readable from the registry, assuming $codePage" }
2331

2432
try {
2533
if (-not ('System.Text.CodePagesEncodingProvider' -as [type])) { throw 'no provider type' }

‎Private/Invoke-IslProcess.ps1‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Invoke-IslProcess {
1+
function Invoke-IslProcess {
22
<#
33
.SYNOPSIS
44
Runs an executable as the current user, as SYSTEM or as another account, capturing its result.
@@ -162,24 +162,37 @@ function Invoke-IslProcess {
162162
try {
163163
Start-ScheduledTask -TaskName $taskName
164164
$deadline = (Get-Date).AddSeconds($TimeoutSeconds)
165+
$neverStartedAfter = (Get-Date).AddSeconds(5)
165166
$launchFailure = $null
166167
while (-not (Test-Path -LiteralPath $exitFile) -and (Get-Date) -lt $deadline) {
167168
Start-Sleep -Milliseconds 250
168169
# A task the scheduler refuses to start (a logon type the account is not granted)
169170
# ends at once with a result code and never writes the exit file: read it rather
170171
# than waiting for the timeout. 267009 is "running", 267011 "has not run yet"
171172
$info = Get-ScheduledTaskInfo -TaskName $taskName -ErrorAction SilentlyContinue
172-
if ($info -and $info.LastTaskResult -notin 0, 267009, 267011 -and
173-
(Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue).State -ne 'Running') {
173+
if (-not $info) { continue }
174+
$state = (Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue).State
175+
if ($info.LastTaskResult -notin 0, 267009, 267011 -and $state -ne 'Running') {
174176
$launchFailure = [uint32]$info.LastTaskResult
175177
break
176178
}
179+
# The refusal does not always come with a code: on the lab device a stored-password
180+
# task for an account without the batch logon right sits Ready, "has not run yet",
181+
# with no error anywhere. Five seconds of that after Start-ScheduledTask is the same
182+
# failure
183+
$neverStarted = $info.LastTaskResult -eq 267011 -and $state -eq 'Ready'
184+
if ($neverStarted -and (Get-Date) -gt $neverStartedAfter) {
185+
$launchFailure = [uint32]267011
186+
break
187+
}
177188
}
178189
if ($launchFailure) {
179190
$code = '0x{0:X8}' -f $launchFailure
180-
$hint = if ($code -eq '0x80070569') {
181-
' (the account is not granted the "Log on as a batch job" right a stored-password task ' +
182-
'needs; grant it in the local security policy, or run while the account holds a session)'
191+
$never = if ($code -eq '0x00041303') { 'the scheduler never launched it: ' } else { '' }
192+
$hint = if ($code -eq '0x80070569' -or ($code -eq '0x00041303' -and $logon -eq 'Password')) {
193+
" ($($never)the account is not granted the ""Log on as a batch job"" right a " +
194+
'stored-password task needs; grant it in the local security policy, or run while the ' +
195+
'account holds a session)'
183196
}
184197
else { '' }
185198
throw "The scheduled task for $userName did not start: $code$hint"

0 commit comments

Comments
 (0)