2222 then by name).
2323
2424 . PARAMETER Path
25- Folders or scripts to analyze; folders are searched for .ps1 files recursively. Default:
26- the current directory.
25+ Folders or scripts to analyze; folders are searched for .ps1 files recursively, leaving out
26+ Pester suites (*.Tests.ps1), which the suite template places next to the scripts. A suite
27+ named directly is analyzed. Default: the current directory.
2728
2829 . PARAMETER FailOn
2930 The lowest severity that fails the build: Error (default), Warning, Information, or None
@@ -147,11 +148,30 @@ function ConvertTo-AnnotationText {
147148 $Text.Replace (' %' , ' %25' ).Replace(" `r " , ' %0D' ).Replace(" `n " , ' %0A' )
148149}
149150
150- $testSplat = @ { Path = $Path ; ScriptType = $ScriptType }
151+ function ConvertTo-AnnotationProperty {
152+ # A property value (file=, title=) also encodes the ':' and ',' that delimit the command, or a
153+ # path outside -Root, which stays absolute, ends the property list at its drive letter
154+ param ([string ]$Text )
155+ (ConvertTo-AnnotationText - Text $Text ).Replace(' :' , ' %3A' ).Replace(' ,' , ' %2C' )
156+ }
157+
158+ # Folders are searched here rather than by Test-IntuneScript, so that a Pester suite next to the
159+ # scripts (IntuneScripts.Tests.ps1, where the suite template puts it) is not analyzed as an Intune
160+ # script; a suite named directly on -Path still is
161+ $scriptFiles = @ (foreach ($item in $Path ) {
162+ foreach ($resolved in (Resolve-Path - Path $item )) {
163+ if (Test-Path - LiteralPath $resolved.ProviderPath - PathType Container) {
164+ Get-ChildItem - LiteralPath $resolved.ProviderPath - Recurse - Filter * .ps1 - File |
165+ Where-Object { $_.Name -notlike ' *.Tests.ps1' } | ForEach-Object { $_.FullName }
166+ }
167+ else { $resolved.ProviderPath }
168+ }
169+ })
170+ $testSplat = @ { Path = $scriptFiles ; ScriptType = $ScriptType }
151171if ($PSBoundParameters.ContainsKey (' Settings' )) { $testSplat.Settings = $Settings }
152172if ($IncludeRule ) { $testSplat.IncludeRule = $IncludeRule }
153173if ($ExcludeRule ) { $testSplat.ExcludeRule = $ExcludeRule }
154- $findings = @ (Test-IntuneScript @testSplat )
174+ $findings = if ( $scriptFiles .Count ) { @ (Test-IntuneScript @testSplat ) } else { @ () }
155175$scripts = @ ($findings | ForEach-Object { $_.ScriptPath } | Sort-Object - Unique)
156176$counts = @ { Error = 0 ; Warning = 0 ; Information = 0 }
157177foreach ($finding in $findings ) { $counts [$finding.Severity ]++ }
@@ -162,10 +182,11 @@ Write-Host ("IntuneScriptLab: $($findings.Count) finding(s) in $($scripts.Count)
162182
163183if ($Annotate ) {
164184 foreach ($finding in $findings ) {
165- $location = " file=$ ( Get-RelativePath - FullPath $finding.ScriptPath ) "
185+ $location = " file=$ ( ConvertTo-AnnotationProperty - Text ( Get-RelativePath - FullPath $finding.ScriptPath ) ) "
166186 if ($finding.Line -gt 0 ) { $location += " ,line=$ ( $finding.Line ) ,col=$ ( [Math ]::Max(1 , $finding.Column )) " }
167187 $message = ConvertTo-AnnotationText - Text $finding.Message
168- Write-Host " ::$ ( $annotationLevel [$finding.Severity ]) $location ,title=$ ( $finding.RuleName ) ::$message "
188+ $title = ConvertTo-AnnotationProperty - Text $finding.RuleName
189+ Write-Host " ::$ ( $annotationLevel [$finding.Severity ]) $location ,title=${title} ::$message "
169190 }
170191}
171192
0 commit comments