Remove Powershell 7 modules from path to prevent module loading issues in the script

This commit is contained in:
Raphire
2026-03-09 23:21:22 +01:00
parent 8401474a79
commit 94e5c95d57

View File

@@ -167,16 +167,14 @@ else {
$windowStyle = "Normal" $windowStyle = "Normal"
} }
# Use powershell 7 to launch the script if the current environment is powershell 7, otherwise use powershell 5.1 # Remove Powershell 7 modules from path to prevent module loading issues in the script
if ($PSVersionTable.PSVersion.Major -ge 7) { if ($PSVersionTable.PSVersion.Major -ge 7) {
$powershellExe = "pwsh.exe" $NewPSModulePath = $env:PSModulePath -split ';' | Where-Object -FilterScript { $_ -like '*WindowsPowerShell*' }
} $env:PSModulePath = $NewPSModulePath -join ';'
else {
$powershellExe = "powershell.exe"
} }
# Run Win11Debloat script with the provided arguments # Run Win11Debloat script with the provided arguments
$debloatProcess = Start-Process $powershellExe -WindowStyle $windowStyle -PassThru -ArgumentList "-executionpolicy bypass -File $env:TEMP\Win11Debloat\Win11Debloat.ps1 $arguments" -Verb RunAs $debloatProcess = Start-Process powershell.exe -WindowStyle $windowStyle -PassThru -ArgumentList "-executionpolicy bypass -File $env:TEMP\Win11Debloat\Win11Debloat.ps1 $arguments" -Verb RunAs
# Wait for the process to finish before continuing # Wait for the process to finish before continuing
if ($null -ne $debloatProcess) { if ($null -ne $debloatProcess) {