From 589f2e82dfc88b60e0362e69a67ecd33f6507fb8 Mon Sep 17 00:00:00 2001 From: Raphire <9938813+Raphire@users.noreply.github.com> Date: Wed, 26 Jun 2024 20:27:25 +0200 Subject: [PATCH] Show error if powershell functionality is restricted (#79) --- Get.ps1 | 9 +++++++++ Win11Debloat.ps1 | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Get.ps1 b/Get.ps1 index d5251e7..1a8a4ad 100644 --- a/Get.ps1 +++ b/Get.ps1 @@ -35,6 +35,15 @@ param ( [switch]$DisableShare, [switch]$HideShare ) +# Show error if current powershell environment does not have LanguageMode set to FullLanguage +if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") { + Write-Host "Error: Win11Debloat is unable to run on your system. Powershell execution is restricted by security policies" -ForegroundColor Red + Write-Output "" + Write-Output "Press enter to exit..." + Read-Host | Out-Null + Exit +} + Clear-Host Write-Output "-------------------------------------------------------------------------------------------" Write-Output " Win11Debloat Script - Get" diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index cf299b5..53040b4 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -39,6 +39,16 @@ param ( ) +# Show error if current powershell environment does not have LanguageMode set to FullLanguage +if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") { + Write-Host "Error: Win11Debloat is unable to run on your system. Powershell execution is restricted by security policies" -ForegroundColor Red + Write-Output "" + Write-Output "Press enter to exit..." + Read-Host | Out-Null + Exit +} + + # Shows application selection form that allows the user to select what apps they want to remove or keep function ShowAppSelectionForm { [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null @@ -525,7 +535,7 @@ else { Write-Warning "Winget is not installed or outdated. This may prevent Win11Debloat from removing certain apps." Write-Output "" Write-Output "Press any key to continue anyway..." - Read-Host | Out-Null + $null = [System.Console]::ReadKey() } } @@ -607,7 +617,7 @@ if ((-not $global:Params.Count) -or $RunDefaults -or $RunWin11Defaults -or ($SPP Write-Output "" Write-Output "Press any key to go back..." - $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") + $null = [System.Console]::ReadKey() } elseif (($Mode -eq '4')-and -not (Test-Path "$PSScriptRoot/SavedSettings")) { $Mode = $null