Skip to content

Commit f71d987

Browse files
committed
Update PSModulePath during discovery
1 parent 526ca6c commit f71d987

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

extensions/powershell/win_powershell.tests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ BeforeDiscovery {
66
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
77
$principal = [System.Security.Principal.WindowsPrincipal]::new($identity)
88
$isElevated = $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
9+
10+
if ($env:GITHUB_ACTION) {
11+
Write-Verbose -Message "Running in GitHub Actions" -Verbose
12+
# Uninstall the PSDesiredStateConfiguration module as this requires v1.1 and the build script installs it
13+
Uninstall-PSResource -Name 'PSDesiredStateConfiguration' -Version 2.0.7 -ErrorAction Stop
14+
# Get current PSModulePath and exclude PowerShell 7 paths
15+
$currentPaths = $env:PSModulePath -split ';' | Where-Object {
16+
$_ -notmatch 'PowerShell[\\/]7' -and
17+
$_ -notmatch 'Program Files[\\/]PowerShell[\\/]' -and
18+
$_ -notmatch 'Documents[\\/]PowerShell[\\/]'
19+
}
20+
21+
# Check if Windows PowerShell modules path exists
22+
$windowsPSPath = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\Modules"
23+
if ($windowsPSPath -notin $currentPaths) {
24+
$currentPaths += $windowsPSPath
25+
}
26+
27+
# Update PSModulePath
28+
$env:PSModulePath = $currentPaths -join ';'
29+
}
930
}
1031
}
1132

0 commit comments

Comments
 (0)