mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2025-11-17 11:06:18 +00:00
Added option to run Win11Debloat as another user (#208)
This commit is contained in:
1
Get.ps1
1
Get.ps1
@@ -2,6 +2,7 @@ param (
|
|||||||
[switch]$Silent,
|
[switch]$Silent,
|
||||||
[switch]$Verbose,
|
[switch]$Verbose,
|
||||||
[switch]$Sysprep,
|
[switch]$Sysprep,
|
||||||
|
[string]$User,
|
||||||
[switch]$RunAppConfigurator,
|
[switch]$RunAppConfigurator,
|
||||||
[switch]$RunDefaults, [switch]$RunWin11Defaults,
|
[switch]$RunDefaults, [switch]$RunWin11Defaults,
|
||||||
[switch]$RunSavedSettings,
|
[switch]$RunSavedSettings,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Win11Debloat is a simple, easy to use and lightweight PowerShell script that can remove pre-installed Windows bloatware apps, disable telemetry and declutter the experience by disabling or removing intrusive interface elements, ads and more. No need to painstakingly go through all the settings yourself or remove apps one by one. Win11Debloat makes the process quick and easy!
|
Win11Debloat is a simple, easy to use and lightweight PowerShell script that can remove pre-installed Windows bloatware apps, disable telemetry and declutter the experience by disabling or removing intrusive interface elements, ads and more. No need to painstakingly go through all the settings yourself or remove apps one by one. Win11Debloat makes the process quick and easy!
|
||||||
|
|
||||||
The script also includes many features that system administrators will enjoy. Such as support for Windows Audit mode and the ability to run the script without requiring user input during runtime.
|
The script also includes many features that system administrators will enjoy. Such as support for Windows Audit mode, the option to make changes to other Windows users and the ability to run the script without requiring user input during runtime.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -59,6 +59,7 @@ The script also includes many features that system administrators will enjoy. Su
|
|||||||
|
|
||||||
- Disable Xbox game/screen recording, this also stops gaming overlay popups.
|
- Disable Xbox game/screen recording, this also stops gaming overlay popups.
|
||||||
- Turn off Enhance Pointer Precision, also known as mouse acceleration.
|
- Turn off Enhance Pointer Precision, also known as mouse acceleration.
|
||||||
|
- Option to apply changes to a different user, instead of the currently logged in user.
|
||||||
- Sysprep mode to apply changes to the Windows Default user profile. Afterwards, all new users will have the changes automatically applied to them.
|
- Sysprep mode to apply changes to the Windows Default user profile. Afterwards, all new users will have the changes automatically applied to them.
|
||||||
|
|
||||||
### Default Settings
|
### Default Settings
|
||||||
@@ -299,6 +300,7 @@ The quick and advanced usage methods support switch parameters. A table of all t
|
|||||||
| :-------: | ----------- |
|
| :-------: | ----------- |
|
||||||
| -Silent | Suppresses all interactive prompts, so the script will run without requiring any user input. |
|
| -Silent | Suppresses all interactive prompts, so the script will run without requiring any user input. |
|
||||||
| -Sysprep | Run the script in Sysprep mode. All changes will be applied to the Windows default user profile and will only affect new user accounts. |
|
| -Sysprep | Run the script in Sysprep mode. All changes will be applied to the Windows default user profile and will only affect new user accounts. |
|
||||||
|
| -User `<USERNAME>` | Run the script for the specified user, instead of the currently logged in user. This user must have logged on atleast once, and cannot be logged in at the time the script is run. |
|
||||||
| -RunDefaults | Run the script with the default settings. |
|
| -RunDefaults | Run the script with the default settings. |
|
||||||
| -RunSavedSettings | Run the script with the saved custom settings from last time. These settings are saved to and read from the `SavedSettings` file in the root folder of the script. |
|
| -RunSavedSettings | Run the script with the saved custom settings from last time. These settings are saved to and read from the `SavedSettings` file in the root folder of the script. |
|
||||||
| -RemoveApps | Remove the default selection of bloatware apps. |
|
| -RemoveApps | Remove the default selection of bloatware apps. |
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
param (
|
param (
|
||||||
[switch]$Silent,
|
[switch]$Silent,
|
||||||
[switch]$Sysprep,
|
[switch]$Sysprep,
|
||||||
|
[string]$User,
|
||||||
[switch]$RunAppConfigurator,
|
[switch]$RunAppConfigurator,
|
||||||
[switch]$RunDefaults, [switch]$RunWin11Defaults,
|
[switch]$RunDefaults, [switch]$RunWin11Defaults,
|
||||||
[switch]$RunSavedSettings,
|
[switch]$RunSavedSettings,
|
||||||
@@ -526,17 +527,24 @@ function RegImport {
|
|||||||
|
|
||||||
Write-Output $message
|
Write-Output $message
|
||||||
|
|
||||||
|
if ($global:Params.ContainsKey("Sysprep")) {
|
||||||
if (!$global:Params.ContainsKey("Sysprep")) {
|
|
||||||
reg import "$PSScriptRoot\Regfiles\$path"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$defaultUserPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\NTUSER.DAT'
|
$defaultUserPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\NTUSER.DAT'
|
||||||
|
|
||||||
reg load "HKU\Default" $defaultUserPath | Out-Null
|
reg load "HKU\Default" $defaultUserPath | Out-Null
|
||||||
reg import "$PSScriptRoot\Regfiles\Sysprep\$path"
|
reg import "$PSScriptRoot\Regfiles\Sysprep\$path"
|
||||||
reg unload "HKU\Default" | Out-Null
|
reg unload "HKU\Default" | Out-Null
|
||||||
}
|
}
|
||||||
|
elseif ($global:Params.ContainsKey("User")) {
|
||||||
|
$userPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$($global:Params.Item("User"))\NTUSER.DAT"
|
||||||
|
|
||||||
|
reg load "HKU\Default" $userPath | Out-Null
|
||||||
|
reg import "$PSScriptRoot\Regfiles\Sysprep\$path"
|
||||||
|
reg unload "HKU\Default" | Out-Null
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reg import "$PSScriptRoot\Regfiles\$path"
|
||||||
|
}
|
||||||
|
|
||||||
Write-Output ""
|
Write-Output ""
|
||||||
}
|
}
|
||||||
@@ -544,7 +552,7 @@ function RegImport {
|
|||||||
|
|
||||||
# Restart the Windows Explorer process
|
# Restart the Windows Explorer process
|
||||||
function RestartExplorer {
|
function RestartExplorer {
|
||||||
if ($global:Params.ContainsKey("Sysprep")) {
|
if ($global:Params.ContainsKey("Sysprep") -or $global:Params.ContainsKey("User")) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,7 +622,10 @@ function ReplaceStartMenu {
|
|||||||
$startMenuTemplate = "$PSScriptRoot/Start/start2.bin"
|
$startMenuTemplate = "$PSScriptRoot/Start/start2.bin"
|
||||||
)
|
)
|
||||||
|
|
||||||
$userName = $env:USERNAME
|
# Change path to correct user if a user was specified
|
||||||
|
if ($global:Params.ContainsKey("User")) {
|
||||||
|
$startMenuBinFile = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$(GetUserName)\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState\start2.bin"
|
||||||
|
}
|
||||||
|
|
||||||
# Check if template bin file exists, return early if it doesn't
|
# Check if template bin file exists, return early if it doesn't
|
||||||
if (-not (Test-Path $startMenuTemplate)) {
|
if (-not (Test-Path $startMenuTemplate)) {
|
||||||
@@ -624,7 +635,7 @@ function ReplaceStartMenu {
|
|||||||
|
|
||||||
# Check if bin file exists, return early if it doesn't
|
# Check if bin file exists, return early if it doesn't
|
||||||
if (-not (Test-Path $startMenuBinFile)) {
|
if (-not (Test-Path $startMenuBinFile)) {
|
||||||
Write-Host "Error: Unable to clear start menu for user $userName, start2.bin file could not found" -ForegroundColor Red
|
Write-Host "Error: Unable to clear start menu for user $(GetUserName), start2.bin file could not found" -ForegroundColor Red
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -636,7 +647,7 @@ function ReplaceStartMenu {
|
|||||||
# Copy template file
|
# Copy template file
|
||||||
Copy-Item -Path $startMenuTemplate -Destination $startMenuBinFile -Force
|
Copy-Item -Path $startMenuTemplate -Destination $startMenuBinFile -Force
|
||||||
|
|
||||||
Write-Output "Replaced start menu for user $userName"
|
Write-Output "Replaced start menu for user $(GetUserName)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -678,6 +689,9 @@ function PrintHeader {
|
|||||||
if ($global:Params.ContainsKey("Sysprep")) {
|
if ($global:Params.ContainsKey("Sysprep")) {
|
||||||
$fullTitle = "$fullTitle (Sysprep mode)"
|
$fullTitle = "$fullTitle (Sysprep mode)"
|
||||||
}
|
}
|
||||||
|
elseif ($global:Params.ContainsKey("User")) {
|
||||||
|
$fullTitle = "$fullTitle (User: $($global:Params.Item("User")))"
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
$fullTitle = "$fullTitle (User: $Env:UserName)"
|
$fullTitle = "$fullTitle (User: $Env:UserName)"
|
||||||
}
|
}
|
||||||
@@ -713,6 +727,16 @@ function AwaitKeyToExit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function GetUserName {
|
||||||
|
if ($global:Params.ContainsKey("User")) {
|
||||||
|
return $global:Params.Item("User")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $env:USERNAME
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function DisplayCustomModeOptions {
|
function DisplayCustomModeOptions {
|
||||||
# Get current Windows build version to compare against features
|
# Get current Windows build version to compare against features
|
||||||
$WinVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' CurrentBuild
|
$WinVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' CurrentBuild
|
||||||
@@ -862,7 +886,7 @@ function DisplayCustomModeOptions {
|
|||||||
Do {
|
Do {
|
||||||
Write-Host " Options:" -ForegroundColor Yellow
|
Write-Host " Options:" -ForegroundColor Yellow
|
||||||
Write-Host " (n) Don't remove any pinned apps from the start menu" -ForegroundColor Yellow
|
Write-Host " (n) Don't remove any pinned apps from the start menu" -ForegroundColor Yellow
|
||||||
Write-Host " (1) Remove all pinned apps from the start menu for this user only ($env:USERNAME)" -ForegroundColor Yellow
|
Write-Host " (1) Remove all pinned apps from the start menu for this user only ($(GetUserName))" -ForegroundColor Yellow
|
||||||
Write-Host " (2) Remove all pinned apps from the start menu for all existing and new users" -ForegroundColor Yellow
|
Write-Host " (2) Remove all pinned apps from the start menu for all existing and new users" -ForegroundColor Yellow
|
||||||
$ClearStartInput = Read-Host " Remove all pinned apps from the start menu? (n/1/2)"
|
$ClearStartInput = Read-Host " Remove all pinned apps from the start menu? (n/1/2)"
|
||||||
}
|
}
|
||||||
@@ -1084,7 +1108,7 @@ $WinVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\Current
|
|||||||
|
|
||||||
$global:Params = $PSBoundParameters
|
$global:Params = $PSBoundParameters
|
||||||
$global:FirstSelection = $true
|
$global:FirstSelection = $true
|
||||||
$SPParams = 'WhatIf', 'Confirm', 'Verbose', 'Silent', 'Sysprep', 'Debug'
|
$SPParams = 'WhatIf', 'Confirm', 'Verbose', 'Silent', 'Sysprep', 'Debug', 'User'
|
||||||
$SPParamCount = 0
|
$SPParamCount = 0
|
||||||
|
|
||||||
# Count how many SPParams exist within Params
|
# Count how many SPParams exist within Params
|
||||||
@@ -1104,6 +1128,7 @@ else {
|
|||||||
$ProgressPreference = 'Continue'
|
$ProgressPreference = 'Continue'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Make sure all requirements for Sysprep are met, if Sysprep is enabled
|
||||||
if ($global:Params.ContainsKey("Sysprep")) {
|
if ($global:Params.ContainsKey("Sysprep")) {
|
||||||
$defaultUserPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\NTUSER.DAT'
|
$defaultUserPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\NTUSER.DAT'
|
||||||
|
|
||||||
@@ -1121,6 +1146,18 @@ if ($global:Params.ContainsKey("Sysprep")) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Make sure all requirements for User mode are met, if User is specified
|
||||||
|
if ($global:Params.ContainsKey("User")) {
|
||||||
|
$userPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\$($global:Params.Item("User"))\NTUSER.DAT"
|
||||||
|
|
||||||
|
# Exit script if user directory or NTUSER.DAT file cannot be found
|
||||||
|
if (-not (Test-Path "$userPath")) {
|
||||||
|
Write-Host "Error: Unable to run Win11Debloat for user $($global:Params.Item("User")), cannot find user data at '$userPath'" -ForegroundColor Red
|
||||||
|
AwaitKeyToExit
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Remove SavedSettings file if it exists and is empty
|
# Remove SavedSettings file if it exists and is empty
|
||||||
if ((Test-Path "$PSScriptRoot/SavedSettings") -and ([String]::IsNullOrWhiteSpace((Get-content "$PSScriptRoot/SavedSettings")))) {
|
if ((Test-Path "$PSScriptRoot/SavedSettings") -and ([String]::IsNullOrWhiteSpace((Get-content "$PSScriptRoot/SavedSettings")))) {
|
||||||
Remove-Item -Path "$PSScriptRoot/SavedSettings" -recurse
|
Remove-Item -Path "$PSScriptRoot/SavedSettings" -recurse
|
||||||
@@ -1416,7 +1453,7 @@ else {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
'ClearStart' {
|
'ClearStart' {
|
||||||
Write-Output "> Removing all pinned apps from the start menu for user $env:USERNAME..."
|
Write-Output "> Removing all pinned apps from the start menu for user $(GetUserName)..."
|
||||||
ReplaceStartMenu
|
ReplaceStartMenu
|
||||||
Write-Output ""
|
Write-Output ""
|
||||||
continue
|
continue
|
||||||
@@ -1431,7 +1468,6 @@ else {
|
|||||||
}
|
}
|
||||||
'TaskbarAlignLeft' {
|
'TaskbarAlignLeft' {
|
||||||
RegImport "> Aligning taskbar buttons to the left..." "Align_Taskbar_Left.reg"
|
RegImport "> Aligning taskbar buttons to the left..." "Align_Taskbar_Left.reg"
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
'HideSearchTb' {
|
'HideSearchTb' {
|
||||||
@@ -1529,7 +1565,7 @@ else {
|
|||||||
Write-Output ""
|
Write-Output ""
|
||||||
Write-Output ""
|
Write-Output ""
|
||||||
Write-Output ""
|
Write-Output ""
|
||||||
Write-Output "Script completed successfully!"
|
Write-Output "Script completed! Please check above for any errors."
|
||||||
|
|
||||||
AwaitKeyToExit
|
AwaitKeyToExit
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user