Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ entries are carried over from the manifest's release notes.

### Fixed

- A `Severity` setting that is not a hashtable, such as `Severity = 'Error'` in a settings file
or in `-Settings`, ends `Test-IntuneScript` with `SettingsInvalid` and a message that names the
source. It ended with a strict-mode error, `PropertyNotFoundStrict`, that named neither the
source nor the setting (#105).
- `Export-IntuneAgentDiagnostic` left every registry value whose name starts with `PS`, such as
`PSVersion`, out of the registry text. Only the five properties that the PowerShell provider
adds to each key are left out now.
Expand Down
10 changes: 8 additions & 2 deletions Private/ConvertTo-IslSettingsObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ function ConvertTo-IslSettingsObject {
-Settings. Every key is optional. A key the module does not know is named in a warning and
otherwise ignored. A value outside its set ends the function with the error SettingsInvalid,
which names the source and the first value that is wrong, checked in this order:
MinimumSeverity, ScriptType, Context, Architecture, then the entries of Severity.
MinimumSeverity, ScriptType, Context, Architecture, Severity, which must be a hashtable, then
the entries of Severity.

.PARAMETER Table
The settings, in the shape of a settings file.
Expand Down Expand Up @@ -68,9 +69,14 @@ function ConvertTo-IslSettingsObject {
$problem = 'Context must be System or User'
} elseif ($architecture -and "$architecture" -notin 'x86', 'x64', 'arm64') {
$problem = 'Architecture must be x86, x64 or arm64'
} elseif ($severityTable -and $severityTable -isnot [System.Collections.IDictionary]) {
$problem = 'Severity must be a hashtable of rule names and severities'
}
$severity = @{}
$severityKeys = if ($severityTable) { @($severityTable.Keys | Where-Object { $null -ne $_ }) } else { @() }
$severityKeys = @()
if ($severityTable -is [System.Collections.IDictionary]) {
$severityKeys = @($severityTable.Keys | Where-Object { $null -ne $_ })
}
foreach ($key in $severityKeys) {
if ($null -eq $problem -and "$($severityTable[$key])" -notin $validSeverities) {
$problem = "Severity for $key must be one of $($validSeverities -join ', ')"
Expand Down
8 changes: 8 additions & 0 deletions Tests/Unit/Private/ConvertTo-IslSettingsObject.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ Describe 'ConvertTo-IslSettingsObject' -Tag 'Unit', 'Private' {
Case = 'a severity override outside the set'; Table = @{ Severity = @{ IslLongSleep = 'Loud' } }
Text = '*Severity for IslLongSleep*'
}
@{
Case = 'a severity that is not a hashtable'; Table = @{ Severity = 'Error' }
Text = '*Severity must be a hashtable of rule names*'
}
@{
Case = 'a severity that is a list'; Table = @{ Severity = @('IslLongSleep', 'Error') }
Text = '*Severity must be a hashtable of rule names*'
}
) {
$failure = { ConvertTo-SettingsTable -Table $Table -Source 'C:\repo\IntuneScriptLab.settings.psd1' } |
Should-Throw -ExceptionMessage $Text
Expand Down
13 changes: 13 additions & 0 deletions Tests/Unit/Public/Test-IntuneScript.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ Describe 'Test-IntuneScript' -Tag 'Unit', 'Public' {
Should-Invoke Get-IslScriptContext -ModuleName IntuneScriptLab -Times 0 -Exactly
}

It 'reports a settings file whose Severity is not a hashtable with SettingsInvalid, naming the file' {
$scriptPath = New-TestScript 'severitytext\Detect-One.ps1' 'exit 2'
$settingsFile = Join-Path (Split-Path $scriptPath -Parent) 'IntuneScriptLab.settings.psd1'
Set-Content -LiteralPath $settingsFile -Value "@{ Severity = 'Error' }" -Encoding ascii

$output = Test-IntuneScript -Path $scriptPath -ErrorAction Continue 2>&1
$errors = @($output | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] })

$errors | Should-BeCollection -Count 1
$errors[0].FullyQualifiedErrorId | Should-BeLikeString 'SettingsInvalid*'
$errors[0].Exception.Message | Should-BeLikeString "$settingsFile*Severity must be a hashtable*"
}

It 'leaves a calling script one error for a path that is not there, and the findings of the other' {
$good = New-TestScript 'caller\Detect-Good.ps1' 'exit 2'
$missing = Join-Path $TestDrive 'caller\missing.ps1'
Expand Down