Repository navigation
Expand file tree
/
Copy pathIntuneScriptLab.psm1
More file actions
105 lines (97 loc) · 3.97 KB
/
Copy pathIntuneScriptLab.psm1
File metadata and controls
105 lines (97 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#Requires -Version 5.1
# IntuneScriptLab PowerShell Module
# Static analysis for scripts that the Intune Management Extension will run: remediation
# detection/remediation scripts, platform scripts and Win32 app detection/requirement scripts.
# Every rule is backed by an observation in ..\Validation\Findings.md rather than by the docs.
Set-StrictMode -Version Latest
# Private helpers first, then the rules that use them, then the public functions. A folder that
# is missing or a file that fails to load fails the import: without that the module would import
# with commands missing.
$privateFolder = Join-Path -Path $PSScriptRoot -ChildPath 'Private'
$functionFolders = @(
$privateFolder
(Join-Path -Path $privateFolder -ChildPath 'Rules')
(Join-Path -Path $PSScriptRoot -ChildPath 'Public')
)
foreach ($functionFolder in $functionFolders) {
if (-not (Test-Path -LiteralPath $functionFolder -PathType Container)) {
throw "The module folder '$functionFolder' is missing."
}
foreach ($functionFile in Get-ChildItem -LiteralPath $functionFolder -Filter '*.ps1' -File) {
try {
Write-Verbose "Loading $($functionFile.FullName)"
. $functionFile.FullName
} catch {
# Not dead code: an error in a dot-sourced file, such as one that does not parse, ends
# only that statement. Rethrown here it ends the root module, and so the import.
throw
}
}
}
# Rule registry: every Find-* function in Private\Rules is a rule. Test-IntuneScript runs them
# in this order so the output reads from "will it run at all" down to "will it report well".
$script:RuleOrder = @(
'Find-IslPowerShell7Syntax'
'Find-IslEncodingIssue'
'Find-IslInteractiveCall'
'Find-IslExitCodeIssue'
'Find-IslOutputIssue'
'Find-IslContextIssue'
'Find-IslArchitectureIssue'
'Find-IslArm64Assumption'
'Find-IslRebootCommand'
'Find-IslRelativePath'
'Find-IslLongSleep'
'Find-IslSignatureIssue'
'Find-IslExecutionPolicyCall'
'Find-IslModuleDependency'
'Find-IslScriptSize'
)
# Pester assertions: approved-verb functions, exported under the Should-* names Pester users
# expect (aliases are not verb-checked, so Import-Module stays warning-free)
Set-Alias -Name Should-HaveIntuneStatus -Value Assert-HaveIntuneStatus
Set-Alias -Name Should-BeIntuneDetected -Value Assert-BeIntuneDetected
Set-Alias -Name Should-NotBeIntuneDetected -Value Assert-NotBeIntuneDetected
Set-Alias -Name Should-HaveIntuneRunState -Value Assert-HaveIntuneRunState
Set-Alias -Name Should-PassIntuneAnalysis -Value Assert-PassIntuneAnalysis
Set-Alias -Name Should-BeIntuneApplicable -Value Assert-BeIntuneApplicable
Set-Alias -Name Should-NotBeIntuneApplicable -Value Assert-NotBeIntuneApplicable
Export-ModuleMember -Function @(
'Test-IntuneScript'
'Invoke-IntuneDetectionTest'
'Invoke-IntuneRemediationTest'
'Invoke-IntunePlatformScriptTest'
'Invoke-IntuneWin32AppTest'
'Invoke-IntuneRequirementTest'
'Test-IntuneWin32Rule'
'Test-IntuneWin32Requirement'
'Get-IntuneAgentLog'
'Get-IntuneAgentTimeline'
'Export-IntuneAgentDiagnostic'
'Get-IntuneAnalyzerRulePath'
'Test-IntuneDeployedScript'
'Compare-IntuneDeployedScript'
'Get-IntuneScriptHealth'
'Export-IntuneFindingSarif'
'Repair-IntuneScript'
'Test-IntuneAssignmentFilter'
'Assert-HaveIntuneStatus'
'Assert-BeIntuneDetected'
'Assert-NotBeIntuneDetected'
'Assert-HaveIntuneRunState'
'Assert-PassIntuneAnalysis'
'Assert-BeIntuneApplicable'
'Assert-NotBeIntuneApplicable'
) -Alias @(
'Should-HaveIntuneStatus'
'Should-BeIntuneDetected'
'Should-NotBeIntuneDetected'
'Should-HaveIntuneRunState'
'Should-PassIntuneAnalysis'
'Should-BeIntuneApplicable'
'Should-NotBeIntuneApplicable'
)
$ExecutionContext.SessionState.Module.OnRemove = {
Write-Verbose 'Cleaning up IntuneScriptLab module'
Remove-Variable -Name RuleOrder -Scope Script -ErrorAction SilentlyContinue
}