From 992c80bc1e7061f6f2c4701b654cad96784f4ee0 Mon Sep 17 00:00:00 2001 From: Raphire <9938813+Raphire@users.noreply.github.com> Date: Mon, 9 Mar 2026 22:49:07 +0100 Subject: [PATCH] Launch main script using pwsh.exe when Get.ps1 is run in Powershell 7 --- Scripts/Get.ps1 | 10 +++++++++- Win11Debloat.ps1 | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Scripts/Get.ps1 b/Scripts/Get.ps1 index 9f43619..1eae966 100644 --- a/Scripts/Get.ps1 +++ b/Scripts/Get.ps1 @@ -166,8 +166,16 @@ else { $windowStyle = "Normal" } +# Use powershell 7 to launch the script if the current environment is powershell 7, otherwise use powershell 5.1 +if ($PSVersionTable.PSVersion.Major -ge 7) { + $powershellExe = "pwsh.exe" +} +else { + $powershellExe = "powershell.exe" +} + # Run Win11Debloat script with the provided arguments -$debloatProcess = Start-Process powershell.exe -WindowStyle $windowStyle -PassThru -ArgumentList "-executionpolicy bypass -File $env:TEMP\Win11Debloat\Win11Debloat.ps1 $arguments" -Verb RunAs +$debloatProcess = Start-Process $powershellExe -WindowStyle $windowStyle -PassThru -ArgumentList "-executionpolicy bypass -File $env:TEMP\Win11Debloat\Win11Debloat.ps1 $arguments" -Verb RunAs # Wait for the process to finish before continuing if ($null -ne $debloatProcess) { diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index 1be2cc3..3b81f7f 100755 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -101,8 +101,6 @@ param ( -Import-Module Microsoft.PowerShell.Security -SkipEditionCheck - # Define script-level variables & paths $script:Version = "2026.03.07" $script:AppsListFilePath = "$PSScriptRoot/Config/Apps.json"