Skip to content

Commit 52738e6

Browse files
committed
Remove all PowerShell modules from module path
1 parent 70ab41b commit 52738e6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

extensions/powershell/convert-resource.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@ param (
66

77
begin {
88
$lines = [System.Collections.Generic.List[string]]::new()
9-
$Operation = 'Trace'
9+
10+
if ($PSVersionTable.PSEdition -ne 'Core') {
11+
# Remove all PowerShell paths
12+
$env:PSModulePath = ($env:PSModulePath -split ';' | Where-Object {
13+
$_ -notmatch 'PowerShell[\\/]7' -and
14+
$_ -notmatch 'Program Files[\\/]PowerShell[\\/]' -and
15+
$_ -notmatch 'Documents[\\/]PowerShell[\\/]'
16+
}) -join ';'
1017

11-
$trace = @{$Operation.ToLower() = "The current module paths: $env:PSModulePath" } | ConvertTo-Json -Compress
12-
$host.ui.WriteErrorLine($trace)
18+
# Make sure the default path is Windows PowerShell is included
19+
$winPsPath = "$env:windir\System32\WindowsPowerShell\v1.0\Modules"
20+
if ($env:PSModulePath -notmatch [regex]::Escape($winPsPath)) {
21+
# Separator is already at the end
22+
$env:PSModulePath = $env:PSModulePath + $winPsPath
23+
}
24+
}
1325

1426
$scriptModule = Import-Module "$PSScriptRoot/convertDscResource.psd1" -Force -PassThru -WarningAction SilentlyContinue -ErrorAction Stop
1527
}

0 commit comments

Comments
 (0)