#Requires -RunAsAdministrator
#Requires -Version 5.1
# ------------------------------------------------------------
# Funkcje
function script:Set-Policy
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
Position = 1
)]
[string]
[ValidateSet("Computer", "User")]
$Scope,
[Parameter(
Mandatory = $true,
Position = 2
)]
[string]
$Path,
[Parameter(
Mandatory = $true,
Position = 3
)]
[string]
$Name,
[Parameter(
Mandatory = $true,
Position = 4
)]
[ValidateSet("DWORD", "SZ", "EXSZ", "CLEAR")]
[string]
$Type,
[Parameter(
Mandatory = $false,
Position = 5
)]
$Value
)
if (-not (Test-Path -Path "$env:SystemRoot\System32\gpedit.msc"))
{
return
}
switch ($Type)
{
"CLEAR"
{
$Policy = @"
$Scope
$($Path)
$($Name)
$($Type)`n
"@
}
default
{
$Policy = @"
$Scope
$($Path)
$($Name)
$($Type):$($Value)`n
"@
}
}
if ($Scope -eq "Computer")
{
$Path = "$env:TEMP\Computer.txt"
}
else
{
$Path = "$env:TEMP\User.txt"
}
# Save in UTF8 without BOM
Add-Content -Path $Path -Value $Policy -Encoding Default -Force
}
function script:Show-Menu
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[array]
$Menu,
[Parameter(Mandatory = $true)]
[int]
$Default,
[Parameter(Mandatory = $false)]
[switch]
$AddSkip
)
Write-Information -MessageData "" -InformationAction Continue
# Add "Please use the arrow keys 🠕 and 🠗 on your keyboard to select your answer" to menu
$Menu += "Użyj klawiszy strzałek {0} i {1} na klawiaturze, aby wybrać odpowiedź" -f [System.Char]::ConvertFromUtf32(0x2191), [System.Char]::ConvertFromUtf32(0x2193)
if ($AddSkip)
{
# Extract the localized "Skip" string from shell32.dll
$Menu += "Skip"
}
# Checking whether current terminal is Windows Terminal
if ($env:WT_SESSION)
{
# https://github.com/microsoft/terminal/issues/14992
[System.Console]::BufferHeight += $Menu.Count
}
$minY = [Console]::CursorTop
$y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0)
do
{
[Console]::CursorTop = $minY
[Console]::CursorLeft = 0
$i = 0
foreach ($item in $Menu)
{
if ($i -ne $y)
{
Write-Information -MessageData (' {1} ' -f ($i+1), $item) -InformationAction Continue
}
else
{
Write-Information -MessageData ('[ {1} ]' -f ($i+1), $item) -InformationAction Continue
}
$i++
}
$k = [Console]::ReadKey()
switch ($k.Key)
{
"UpArrow"
{
if ($y -gt 0)
{
$y--
}
}
"DownArrow"
{
if ($y -lt ($Menu.Count - 1))
{
$y++
}
}
"Enter"
{
return $Menu[$y]
}
}
}
while ($k.Key -notin ([ConsoleKey]::Escape, [ConsoleKey]::Enter))
}
# Extract the localized "Browse" string from shell32.dll
$Script:Browse = "Browse"
# Extract the localized "&No" string from shell32.dll
$Script:No = "No"
# Extract the localized "&Yes" string from shell32.dll
$Script:Yes = "Yes"
$Script:KeyboardArrows = "Użyj klawiszy strzałek {0} i {1} na klawiaturze, aby wybrać odpowiedź" -f [System.Char]::ConvertFromUtf32(0x2191), [System.Char]::ConvertFromUtf32(0x2193)
# Extract the localized "Skip" string from shell32.dll
$Script:Skip = "Skip"
Write-Information -MessageData "https://t.me/sophianews" -InformationAction Continue
Write-Information -MessageData "https://t.me/sophia_chat" -InformationAction Continue
Write-Information -MessageData "https://discord.gg/sSryhaEv79" -InformationAction Continue
# Display a warning message about whether a user has customized the preset file
if ($Warning)
{
# Get the name of a preset (e.g Sophia.ps1) regardless it was named
# $_.File has no EndsWith() method
Write-Information -MessageData "" -InformationAction Continue
[string]$PresetName = ((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}
Write-Verbose -Message ("Czy dostosowałeś funkcje w predefiniowanym pliku {0} przed uruchomieniem Sophia Script?" -f "`"$PresetName`"") -Verbose
do
{
$Choice = Show-Menu -Menu @($Yes, $No) -Default 2
switch ($Choice)
{
$Yes
{
continue
}
$No
{
Invoke-Item -Path $PresetName
Start-Sleep -Seconds 5
Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows#how-to-use" -Verbose
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
exit
}
$KeyboardArrows {}
}
}
until ($Choice -ne $KeyboardArrows)
}
# ------------------------------------------------------------
# Clear-Host
Write-Host "Start"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.8.3 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) Team Sophia, 2014$([System.Char]0x2013)2025"
# Disable the "Connected User Experiences and Telemetry" service (DiagTrack), and block the connection for the Unified Telemetry Client Outbound Traffic
function DiagTrackService
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
# Connected User Experiences and Telemetry
# Disabling the "Connected User Experiences and Telemetry" service (DiagTrack) can cause you not being able to get Xbox achievements anymore and affects Feedback Hub
Get-Service -Name DiagTrack -ErrorAction Ignore | Stop-Service -Force
Get-Service -Name DiagTrack -ErrorAction Ignore | Set-Service -StartupType Disabled
# Block connection for the Unified Telemetry Client Outbound Traffic
Get-NetFirewallRule -Group DiagTrack -ErrorAction Ignore | Set-NetFirewallRule -Enabled True -Action Block
}
"Enable"
{
# Connected User Experiences and Telemetry
Get-Service -Name DiagTrack -ErrorAction Ignore | Set-Service -StartupType Automatic
Get-Service -Name DiagTrack -ErrorAction Ignore | Start-Service
# Allow connection for the Unified Telemetry Client Outbound Traffic
Get-NetFirewallRule -Group DiagTrack -ErrorAction Ignore | Set-NetFirewallRule -Enabled True -Action Allow
}
}
}
# Disable the "Connected User Experiences and Telemetry" service (DiagTrack), and block the connection for the Unified Telemetry Client Outbound Traffic
# Disabling the "Connected User Experiences and Telemetry" service (DiagTrack) can cause you not being able to get Xbox achievements anymore and affects Feedback Hub
DiagTrackService -Disable
Write-Host "Set the diagnostic data collection to minimum"
function DiagnosticDataLevel
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Minimal"
)]
[switch]
$Minimal,
[Parameter(
Mandatory = $true,
ParameterSetName = "Default"
)]
[switch]
$Default
)
if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection))
{
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Force
}
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Force
}
switch ($PSCmdlet.ParameterSetName)
{
"Minimal"
{
$EditionID = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").EditionID
if (($EditionID -match "Enterprise") -or ($EditionID -match "Education"))
{
# Diagnostic data off
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 0 -Force
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Type DWORD -Value 0
}
else
{
# Send required diagnostic data
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 1 -Force
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Type DWORD -Value 1
}
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 1 -Force
}
"Default"
{
# Optional diagnostic data
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 3 -Force
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 3 -Force
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Type CLEAR
}
}
}
Write-Host "Set the diagnostic data collection to minimum"
DiagnosticDataLevel -Minimal
# Turn off the Windows Error Reporting
function ErrorReporting
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Error Reporting", "HKCU:\Software\Policies\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Type CLEAR
Set-Policy -Scope User -Path "Software\Policies\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
Get-ScheduledTask -TaskName QueueReporting -ErrorAction Ignore | Disable-ScheduledTask
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Windows Error Reporting" -Name Disabled -PropertyType DWord -Value 1 -Force
Get-Service -Name WerSvc | Stop-Service -Force
Get-Service -Name WerSvc | Set-Service -StartupType Disabled
}
"Enable"
{
Get-ScheduledTask -TaskName QueueReporting -ErrorAction Ignore | Enable-ScheduledTask
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Force -ErrorAction Ignore
Get-Service -Name WerSvc | Set-Service -StartupType Manual
Get-Service -Name WerSvc | Start-Service
}
}
}
Write-Host "Turn off the Windows Error Reporting"
ErrorReporting -Disable
# Change the feedback frequency to "Never"
function FeedbackFrequency
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Never"
)]
[switch]
$Never,
[Parameter(
Mandatory = $true,
ParameterSetName = "Automatically"
)]
[switch]
$Automatically
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DoNotShowFeedbackNotifications -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DoNotShowFeedbackNotifications -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Never"
{
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Siuf\Rules))
{
New-Item -Path HKCU:\Software\Microsoft\Siuf\Rules -Force
}
New-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name NumberOfSIUFInPeriod -PropertyType DWord -Value 0 -Force
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name PeriodInNanoSeconds -Force -ErrorAction Ignore
}
"Automatically"
{
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name PeriodInNanoSeconds, NumberOfSIUFInPeriod -Force -ErrorAction Ignore
}
}
}
# Change the feedback frequency to "Never"
FeedbackFrequency -Never
function FeedbackFrequency
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Never"
)]
[switch]
$Never,
[Parameter(
Mandatory = $true,
ParameterSetName = "Automatically"
)]
[switch]
$Automatically
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DoNotShowFeedbackNotifications -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DoNotShowFeedbackNotifications -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Never"
{
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Siuf\Rules))
{
New-Item -Path HKCU:\Software\Microsoft\Siuf\Rules -Force
}
New-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name NumberOfSIUFInPeriod -PropertyType DWord -Value 0 -Force
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name PeriodInNanoSeconds -Force -ErrorAction Ignore
}
"Automatically"
{
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name PeriodInNanoSeconds, NumberOfSIUFInPeriod -Force -ErrorAction Ignore
}
}
}
# Turn off the diagnostics tracking scheduled tasks
function ScheduledTasks
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
Add-Type -AssemblyName PresentationCore, PresentationFramework
#region Variables
# Initialize an array list to store the selected scheduled tasks
$SelectedTasks = New-Object -TypeName System.Collections.ArrayList($null)
# The following tasks will have their checkboxes checked
[string[]]$CheckedScheduledTasks = @(
# Collects program telemetry information if opted-in to the Microsoft Customer Experience Improvement Program
"MareBackup",
# Collects program telemetry information if opted-in to the Microsoft Customer Experience Improvement Program
"Microsoft Compatibility Appraiser",
# Updates compatibility database
"StartupAppTask",
# This task collects and uploads autochk SQM data if opted-in to the Microsoft Customer Experience Improvement Program
"Proxy",
# If the user has consented to participate in the Windows Customer Experience Improvement Program, this job collects and sends usage data to Microsoft
"Consolidator",
# The USB CEIP (Customer Experience Improvement Program) task collects Universal Serial Bus related statistics and information about your machine and sends it to the Windows Device Connectivity engineering group at Microsoft
"UsbCeip",
# The Windows Disk Diagnostic reports general disk and system information to Microsoft for users participating in the Customer Experience Program
"Microsoft-Windows-DiskDiagnosticDataCollector",
# This task shows various Map related toasts
"MapsToastTask",
# This task checks for updates to maps which you have downloaded for offline use
"MapsUpdateTask",
# Initializes Family Safety monitoring and enforcement
"FamilySafetyMonitor",
# Synchronizes the latest settings with the Microsoft family features service
"FamilySafetyRefreshTask",
# XblGameSave Standby Task
"XblGameSaveTask"
)
#endregion Variables
#region XAML Markup
# The section defines the design of the upcoming dialog box
[xml]$XAML = @"
"@
#endregion XAML Markup
$Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML))
$XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process {
Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)
}
#region Functions
function Get-CheckboxClicked
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateNotNull()]
$CheckBox
)
$Task = $Tasks | Where-Object -FilterScript {$_.TaskName -eq $CheckBox.Parent.Children[1].Text}
if ($CheckBox.IsChecked)
{
[void]$SelectedTasks.Add($Task)
}
else
{
[void]$SelectedTasks.Remove($Task)
}
if ($SelectedTasks.Count -gt 0)
{
$Button.IsEnabled = $true
}
else
{
$Button.IsEnabled = $false
}
}
function DisableButton
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Please wait..." -Verbose
[void]$Window.Close()
$SelectedTasks | ForEach-Object -Process {Write-Verbose -Message $_.TaskName -Verbose}
$SelectedTasks | Disable-ScheduledTask
}
function EnableButton
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Please wait..." -Verbose
[void]$Window.Close()
$SelectedTasks | ForEach-Object -Process {Write-Verbose -Message $_.TaskName -Verbose}
$SelectedTasks | Enable-ScheduledTask
}
function Add-TaskControl
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateNotNull()]
$Task
)
process
{
$CheckBox = New-Object -TypeName System.Windows.Controls.CheckBox
$CheckBox.Add_Click({Get-CheckboxClicked -CheckBox $_.Source})
$TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock
$TextBlock.Text = $Task.TaskName
$StackPanel = New-Object -TypeName System.Windows.Controls.StackPanel
[void]$StackPanel.Children.Add($CheckBox)
[void]$StackPanel.Children.Add($TextBlock)
[void]$PanelContainer.Children.Add($StackPanel)
# If task checked add to the array list
if ($CheckedScheduledTasks | Where-Object -FilterScript {$Task.TaskName -match $_})
{
[void]$SelectedTasks.Add($Task)
}
else
{
$CheckBox.IsChecked = $false
}
}
}
#endregion Functions
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
$State = "Disabled"
# Extract the localized "Enable" string from shell32.dll
$ButtonContent = "Enable"
$ButtonAdd_Click = {EnableButton}
}
"Disable"
{
$State = "Ready"
$ButtonContent = "Wylaczyc"
$ButtonAdd_Click = {DisableButton}
}
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Please wait..." -Verbose
# Getting list of all scheduled tasks according to the conditions
$Tasks = Get-ScheduledTask | Where-Object -FilterScript {($_.State -eq $State) -and ($_.TaskName -in $CheckedScheduledTasks)}
if (-not $Tasks)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Nic do wyświetlenia." -Verbose
return
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Wyświetlanie okna dialogowego..." -Verbose
#region Sendkey function
# Emulate the Backspace key sending to prevent the console window to freeze
Start-Sleep -Milliseconds 500
Add-Type -AssemblyName System.Windows.Forms
# We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID
Get-Process -Name powershell, WindowsTerminal -ErrorAction Ignore | Where-Object -FilterScript {$_.MainWindowTitle -match "Sophia Script for Windows 11"} | ForEach-Object -Process {
# Show window, if minimized
# [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
Start-Sleep -Seconds 1
# Force move the console window to the foreground
# [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle)
# Start-Sleep -Seconds 1
# Emulate the Backspace key sending
# [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
}
#endregion Sendkey function
$Window.Add_Loaded({$Tasks | Add-TaskControl})
$Button.Content = $ButtonContent
$Button.Add_Click({& $ButtonAdd_Click})
$Window.Title = "Zaplanowane zadania"
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
# Turn off the diagnostics tracking scheduled tasks
ScheduledTasks -Disable
# Do not use sign-in info to automatically finish setting up device after an update
function SigninInfo
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name DisableAutomaticRestartSignOn -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name DisableAutomaticRestartSignOn -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
$SID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\$SID"))
{
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\$SID" -Force
}
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\$SID" -Name OptOut -PropertyType DWord -Value 1 -Force
}
"Enable"
{
$SID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\$SID" -Name OptOut -Force -ErrorAction Ignore
}
}
}
# Do not use sign-in info to automatically finish setting up device after an update
function SigninInfo
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name DisableAutomaticRestartSignOn -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name DisableAutomaticRestartSignOn -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
$SID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\$SID"))
{
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\$SID" -Force
}
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\$SID" -Name OptOut -PropertyType DWord -Value 1 -Force
}
"Enable"
{
$SID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserARSO\$SID" -Name OptOut -Force -ErrorAction Ignore
}
}
}
# Do not use sign-in info to automatically finish setting up device after an update
SigninInfo -Disable
# Do not let websites provide locally relevant content by accessing language list
function LanguageListAccess
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path "HKCU:\Control Panel\International\User Profile" -Name HttpAcceptLanguageOptOut -PropertyType DWord -Value 1 -Force
}
"Enable"
{
Remove-ItemProperty -Path "HKCU:\Control Panel\International\User Profile" -Name HttpAcceptLanguageOptOut -Force -ErrorAction Ignore
}
}
}
# Do not let websites provide locally relevant content by accessing language list
LanguageListAccess -Disable
# Do not let apps show me personalized ads by using my advertising ID
function AdvertisingID
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\AdvertisingInfo -Name DisabledByGroupPolicy -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DisabledByGroupPolicy -Type CLEAR
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\AdvertisingInfo))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Force
}
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Name Enabled -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Name Enabled -PropertyType DWord -Value 1 -Force
}
}
}
# Do not let apps show me personalized ads by using my advertising ID
AdvertisingID -Disable
# Hide the Windows welcome experiences after updates and occasionally when I sign in to highlight what's new and suggested
function WindowsWelcomeExperience
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show,
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide
)
switch ($PSCmdlet.ParameterSetName)
{
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-310093Enabled -PropertyType DWord -Value 1 -Force
}
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-310093Enabled -PropertyType DWord -Value 0 -Force
}
}
}
# Hide the Windows welcome experiences after updates and occasionally when I sign in to highlight what's new and suggested
WindowsWelcomeExperience -Hide
# Do not get tips and suggestions when I use Windows
function WindowsTips
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent -Name DisableSoftLanding -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\CloudContent -Name DisableSoftLanding -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-338389Enabled -PropertyType DWord -Value 1 -Force
}
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-338389Enabled -PropertyType DWord -Value 0 -Force
}
}
}
# Do not get tips and suggestions when I use Windows
WindowsTips -Disable
# Hide from me suggested content in the Settings app
function SettingsSuggestedContent
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-338393Enabled -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-353694Enabled -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-353696Enabled -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-338393Enabled -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-353694Enabled -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-353696Enabled -PropertyType DWord -Value 1 -Force
}
}
}
# Hide from me suggested content in the Settings app
SettingsSuggestedContent -Hide
# Turn off automatic installing suggested apps
function AppsSilentInstalling
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent -Name DisableWindowsConsumerFeatures -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\CloudContent -Name DisableWindowsConsumerFeatures -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SilentInstalledAppsEnabled -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SilentInstalledAppsEnabled -PropertyType DWord -Value 1 -Force
}
}
}
# Turn off automatic installing suggested apps
AppsSilentInstalling -Disable
# Do not suggest ways to get the most out of Windows and finish setting up this device
function WhatsNewInWindows
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\UserProfileEngagement))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\UserProfileEngagement -Force
}
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\UserProfileEngagement -Name ScoobeSystemSettingEnabled -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\UserProfileEngagement -Name ScoobeSystemSettingEnabled -PropertyType DWord -Value 1 -Force
}
}
}
# Do not suggest ways to get the most out of Windows and finish setting up this device
WhatsNewInWindows -Disable
# Don't let Microsoft use your diagnostic data for personalized tips, ads, and recommendations
function TailoredExperiences
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\CloudContent -Name DisableTailoredExperiencesWithDiagnosticData -Force -ErrorAction Ignore
Set-Policy -Scope User -Path Software\Policies\Microsoft\Windows\CloudContent -Name DisableTailoredExperiencesWithDiagnosticData -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Privacy -Name TailoredExperiencesWithDiagnosticDataEnabled -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Privacy -Name TailoredExperiencesWithDiagnosticDataEnabled -PropertyType DWord -Value 1 -Force
}
}
}
# Don't let Microsoft use your diagnostic data for personalized tips, ads, and recommendations
TailoredExperiences -Disable
# Disable Bing search in Start Menu
function BingSearch
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if (-not (Test-Path -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer))
{
New-Item -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Force
}
New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name DisableSearchBoxSuggestions -PropertyType DWord -Value 1 -Force
Set-Policy -Scope User -Path Software\Policies\Microsoft\Windows\Explorer -Name DisableSearchBoxSuggestions -Type DWORD -Value 1
}
"Enable"
{
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name DisableSearchBoxSuggestions -Force -ErrorAction Ignore
Set-Policy -Scope User -Path Software\Policies\Microsoft\Windows\Explorer -Name DisableSearchBoxSuggestions -Type CLEAR
}
}
}
# Disable Bing search in Start Menu
BingSearch -Disable
# Do not show recommendations for tips, shortcuts, new apps, and more in Start menu
function StartRecommendationsTips
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Start_IrisRecommendations -PropertyType DWord -Value 0 -Force
}
"Show"
{
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Start_IrisRecommendations -Force -ErrorAction Ignore
}
}
}
# Do not show recommendations for tips, shortcuts, new apps, and more in Start menu
StartRecommendationsTips -Hide
# Do not show Microsoft account-related notifications on Start Menu in Start menu
function StartAccountNotifications
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Start_AccountNotifications -PropertyType DWord -Value 0 -Force
}
"Show"
{
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Start_AccountNotifications -Force -ErrorAction Ignore
}
}
}
# Do not show Microsoft account-related notifications on Start Menu in Start menu
StartAccountNotifications -Hide
# Show the "This PC" icon on Desktop
function ThisPC
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show,
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide
)
switch ($PSCmdlet.ParameterSetName)
{
"Show"
{
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel -Force
}
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel -Name "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" -PropertyType DWord -Value 0 -Force
}
"Hide"
{
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel -Name "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" -Force -ErrorAction Ignore
}
}
}
# Show the "This PC" icon on Desktop
ThisPC -Show
# Do not use item check boxes
function CheckBoxes
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name AutoCheckSelect -PropertyType DWord -Value 1 -Force
}
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name AutoCheckSelect -PropertyType DWord -Value 0 -Force
}
}
}
# Do not use item check boxes
CheckBoxes -Disable
# Show hidden files, folders, and drives
function HiddenItems
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -PropertyType DWord -Value 1 -Force
}
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -PropertyType DWord -Value 2 -Force
}
}
}
# Show hidden files, folders, and drives
HiddenItems -Enable
# Show file name extensions
function FileExtensions
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show,
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide
)
switch ($PSCmdlet.ParameterSetName)
{
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideFileExt -PropertyType DWord -Value 0 -Force
}
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideFileExt -PropertyType DWord -Value 1 -Force
}
}
}
# Show file name extensions
FileExtensions -Show
# Show folder merge conflicts
function MergeConflicts
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show,
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide
)
switch ($PSCmdlet.ParameterSetName)
{
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideMergeConflicts -PropertyType DWord -Value 0 -Force
}
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideMergeConflicts -PropertyType DWord -Value 1 -Force
}
}
}
# Show folder merge conflicts
MergeConflicts -Show
# Open File Explorer to "This PC"
function OpenFileExplorerTo
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "ThisPC"
)]
[switch]
$ThisPC,
[Parameter(
Mandatory = $true,
ParameterSetName = "QuickAccess"
)]
[switch]
$QuickAccess
)
switch ($PSCmdlet.ParameterSetName)
{
"ThisPC"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name LaunchTo -PropertyType DWord -Value 1 -Force
}
"QuickAccess"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name LaunchTo -PropertyType DWord -Value 2 -Force
}
}
}
# Open File Explorer to "This PC"
OpenFileExplorerTo -ThisPC
# Do not show sync provider notification within File Explorer
function OneDriveFileExplorerAd
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowSyncProviderNotifications -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowSyncProviderNotifications -PropertyType DWord -Value 1 -Force
}
}
}
# Do not show sync provider notification within File Explorer
OneDriveFileExplorerAd -Hide
# Show the file transfer dialog box in the detailed mode
function FileTransferDialog
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Detailed"
)]
[switch]
$Detailed,
[Parameter(
Mandatory = $true,
ParameterSetName = "Compact"
)]
[switch]
$Compact
)
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager -Force
}
switch ($PSCmdlet.ParameterSetName)
{
"Detailed"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager -Name EnthusiastMode -PropertyType DWord -Value 1 -Force
}
"Compact"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager -Name EnthusiastMode -PropertyType DWord -Value 0 -Force
}
}
}
# Show the file transfer dialog box in the detailed mode
FileTransferDialog -Detailed
# Hide recently used files in Quick access
function QuickAccessRecentFiles
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer, HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name NoRecentDocsHistory -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoRecentDocsHistory -Type CLEAR
Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoRecentDocsHistory -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer -Name ShowRecent -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer -Name ShowRecent -PropertyType DWord -Value 1 -Force
}
}
}
# Hide recently used files in Quick access
QuickAccessRecentFiles -Hide
# Hide frequently used folders in Quick access
function QuickAccessFrequentFolders
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer -Name ShowFrequent -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer -Name ShowFrequent -PropertyType DWord -Value 1 -Force
}
}
}
# Hide frequently used folders in Quick access
QuickAccessFrequentFolders -Hide
# Set the taskbar alignment to the left
function TaskbarAlignment
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Left"
)]
[switch]
$Left,
[Parameter(
Mandatory = $true,
ParameterSetName = "Center"
)]
[switch]
$Center
)
switch ($PSCmdlet.ParameterSetName)
{
"Center"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarAl -PropertyType DWord -Value 1 -Force
}
"Left"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarAl -PropertyType DWord -Value 0 -Force
}
}
}
# Set the taskbar alignment to the left
TaskbarAlignment -Left
# Hide the widgets icon on the taskbar
function TaskbarWidgets
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
if (-not (Get-AppxPackage -Name MicrosoftWindows.Client.WebExperience))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\default\NewsAndInterests\AllowNewsAndInterests -Name value -Force -ErrorAction Ignore
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Dsh -Name AllowNewsAndInterests -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Dsh -Name AllowNewsAndInterests -Type CLEAR
# We cannot set a value to TaskbarDa, having called any of APIs, except of copying powershell.exe (or any other tricks) with a different name, due to a UCPD driver tracks all executables to block the access to the registry
Copy-Item -Path "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" -Destination "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Force
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
& "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Command {New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarDa -PropertyType DWord -Value 0 -Force}
}
"Show"
{
& "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Command {New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarDa -PropertyType DWord -Value 1 -Force}
}
}
Remove-Item -Path "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Force
}
# Hide the widgets icon on the taskbar
TaskbarWidgets -Hide
# Hide the search on the taskbar
function TaskbarSearch
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "SearchIcon"
)]
[switch]
$SearchIcon,
[Parameter(
Mandatory = $true,
ParameterSetName = "SearchIconLabel"
)]
[switch]
$SearchIconLabel,
[Parameter(
Mandatory = $true,
ParameterSetName = "SearchBox"
)]
[switch]
$SearchBox
)
# Remove all policies in order to make changes visible in UI only if it's possible
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\default\Search\DisableSearch -Name value -PropertyType DWord -Value 0 -Force
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name DisableSearch, SearchOnTaskbarMode -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name DisableSearch -Type CLEAR
Set-Policy -Scope Computer -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name SearchOnTaskbarMode -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -PropertyType DWord -Value 0 -Force
}
"SearchIcon"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -PropertyType DWord -Value 1 -Force
}
"SearchIconLabel"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -PropertyType DWord -Value 3 -Force
}
"SearchBox"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -PropertyType DWord -Value 2 -Force
}
}
}
# Hide the search on the taskbar
TaskbarSearch -Hide
# Hide search highlights
function SearchHighlights
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name EnableDynamicContentInWSB -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name EnableDynamicContentInWSB -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
# Checking whether "Ask Copilot" and "Find results in Web" were disabled. They also disable Search Highlights automatically
# We have to use GetValue() due to "Set-StrictMode -Version Latest"
$BingSearchEnabled = ([Microsoft.Win32.Registry]::GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search", "BingSearchEnabled", $null))
$DisableSearchBoxSuggestions = ([Microsoft.Win32.Registry]::GetValue("HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Explorer", "DisableSearchBoxSuggestions", $null))
if (($BingSearchEnabled -eq 1) -or ($DisableSearchBoxSuggestions -eq 1))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
else
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\SearchSettings -Name IsDynamicSearchBoxEnabled -PropertyType DWord -Value 0 -Force
}
}
"Show"
{
# Enable "Ask Copilot" and "Find results in Web" icons in Windows Search in order to enable Search Highlights
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name BingSearchEnabled -Force -ErrorAction Ignore
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name DisableSearchBoxSuggestions -Force -ErrorAction Ignore
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\SearchSettings -Name IsDynamicSearchBoxEnabled -PropertyType DWord -Value 1 -Force
}
}
}
# Hide search highlights
SearchHighlights -Hide
# Hide the Task view button from the taskbar
function TaskViewButton
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer, HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideTaskViewButton -Force -ErrorAction Ignore
Set-Policy -Scope User -Path Software\Policies\Microsoft\Windows\Explorer -Name HideTaskViewButton -Type CLEAR
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideTaskViewButton -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -PropertyType DWord -Value 1 -Force
}
}
}
# Hide the Task view button from the taskbar
TaskViewButton -Hide
# Unpin Microsoft Edge, Microsoft Store, and Outlook shortcuts from the taskbar
function UnpinTaskbarShortcuts
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet("Edge", "Store", "Outlook")]
[string[]]
$Shortcuts
)
$LocalizedString = "Unpin from taskbar"
foreach ($Shortcut in $Shortcuts)
{
switch ($Shortcut)
{
Edge
{
if (Test-Path -Path "$env:AppData\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Edge.lnk")
{
# Call the shortcut context menu item
$Shell = (New-Object -ComObject Shell.Application).NameSpace("$env:AppData\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar")
$Shortcut = $Shell.ParseName("Microsoft Edge.lnk")
# Extract the localized "Unpin from taskbar" string from shell32.dll
$Shortcut.Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()}
}
}
Store
{
if ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript {$_.Name -eq "Microsoft Store"})
{
# Extract the localized "Unpin from taskbar" string from shell32.dll
((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript {
$_.Name -eq "Microsoft Store"
}).Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()}
}
}
Outlook
{
if ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript {$_.Name -match "Outlook"})
{
# Extract the localized "Unpin from taskbar" string from shell32.dll
((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript {
$_.Name -match "Outlook"
}).Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()}
}
}
}
}
}
# Unpin Microsoft Edge, Microsoft Store, and Outlook shortcuts from the taskbar
UnpinTaskbarShortcuts -Shortcuts Edge, Store, Outlook
# Enable end task in taskbar by right click
function TaskbarEndTask
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDeveloperSettings))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDeveloperSettings -Force
}
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDeveloperSettings -Name TaskbarEndTask -PropertyType DWord -Value 1 -Force
}
"Disable"
{
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDeveloperSettings -Name TaskbarEndTask -Force -ErrorAction Ignore
}
}
}
Write-Host "Enable end task in taskbar by right click"
TaskbarEndTask -Enable
# View the Control Panel icons by large icons
function ControlPanelView
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Category"
)]
[switch]
$Category,
[Parameter(
Mandatory = $true,
ParameterSetName = "LargeIcons"
)]
[switch]
$LargeIcons,
[Parameter(
Mandatory = $true,
ParameterSetName = "SmallIcons"
)]
[switch]
$SmallIcons
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name ForceClassicControlPanel -Force -ErrorAction Ignore
Set-Policy -Scope User -Path Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name ForceClassicControlPanel -Type CLEAR
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Force
}
switch ($PSCmdlet.ParameterSetName)
{
"Category"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Name AllItemsIconView -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Name StartupPage -PropertyType DWord -Value 0 -Force
}
"LargeIcons"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Name AllItemsIconView -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Name StartupPage -PropertyType DWord -Value 1 -Force
}
"SmallIcons"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Name AllItemsIconView -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Name StartupPage -PropertyType DWord -Value 1 -Force
}
}
}
Write-Host "View the Control Panel icons by large icons"
ControlPanelView -LargeIcons
# Set the default Windows mode to dark
function WindowsColorMode
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Dark"
)]
[switch]
$Dark,
[Parameter(
Mandatory = $true,
ParameterSetName = "Light"
)]
[switch]
$Light
)
switch ($PSCmdlet.ParameterSetName)
{
"Dark"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -PropertyType DWord -Value 0 -Force
}
"Light"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -PropertyType DWord -Value 1 -Force
}
}
}
Write-Host "Set the default Windows mode to dark"
WindowsColorMode -Dark
# Set the default app mode to light (default value)
function AppColorMode
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Dark"
)]
[switch]
$Dark,
[Parameter(
Mandatory = $true,
ParameterSetName = "Light"
)]
[switch]
$Light
)
switch ($PSCmdlet.ParameterSetName)
{
"Dark"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -PropertyType DWord -Value 0 -Force
}
"Light"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -PropertyType DWord -Value 1 -Force
}
}
}
Write-Host "Hide first sign-in animation after the upgrade"
function FirstLogonAnimation
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableFirstLogonAnimation -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableFirstLogonAnimation -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name EnableFirstLogonAnimation -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name EnableFirstLogonAnimation -PropertyType DWord -Value 1 -Force
}
}
}
Write-Host "Hide first sign-in animation after the upgrade"
FirstLogonAnimation -Disable
# Do not add the "- Shortcut" suffix to the file name of created shortcuts
function ShortcutsSuffix
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer -Name link -Force -ErrorAction Ignore
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\NamingTemplates))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\NamingTemplates -Force
}
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\NamingTemplates -Name ShortcutNameTemplate -PropertyType String -Value "%s.lnk" -Force
}
"Enable"
{
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\NamingTemplates -Name ShortcutNameTemplate -Force -ErrorAction Ignore
}
}
}
# Do not add the "- Shortcut" suffix to the file name of created shortcuts
Write-Host "ShortcutsSuffix"
ShortcutsSuffix -Disable
# Do not group files and folder in the Downloads folder
function FolderGroupBy
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "None"
)]
[switch]
$None,
[Parameter(
Mandatory = $true,
ParameterSetName = "Default"
)]
[switch]
$Default
)
switch ($PSCmdlet.ParameterSetName)
{
"None"
{
# Clear any Common Dialog views
Get-ChildItem -Path "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\*\Shell" -Recurse | Where-Object -FilterScript {$_.PSChildName -eq "{885A186E-A440-4ADA-812B-DB871B942259}"} | Remove-Item -Force
# https://learn.microsoft.com/en-us/windows/win32/properties/props-system-null
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000}"))
{
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000}" -Force
}
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000}" -Name ColumnList -PropertyType String -Value "System.Null" -Force
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000}" -Name GroupBy -PropertyType String -Value "System.Null" -Force
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000}" -Name LogicalViewMode -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000}" -Name Name -PropertyType String -Value NoName -Force
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000}" -Name Order -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000}" -Name PrimaryProperty -PropertyType String -Value "System.ItemNameDisplay" -Force
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000}" -Name SortByList -PropertyType String -Value "prop:System.ItemNameDisplay" -Force
}
"Default"
{
Remove-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}" -Recurse -Force -ErrorAction Ignore
}
}
}
Write-Host "Do not group files and folder in the Downloads folder"
FolderGroupBy -None
# Expand to open folder on navigation pane
function NavigationPaneExpand
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name NavPaneExpandToCurrentFolder -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name NavPaneExpandToCurrentFolder -PropertyType DWord -Value 1 -Force
}
}
}
Write-Host "Expand to open folder on navigation pane"
NavigationPaneExpand -Enable
# Remove Recommended section in Start Menu. Not applicable to Home edition
function StartRecommendedSection
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
# Windows 11 Home not supported
$EditionID = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").EditionID
if ($EditionID -match "Home" -or ($EditionID -match "Core"))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-Path -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer))
{
New-Item -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Force
}
if (-not (Test-Path -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education))
{
New-Item -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Force
}
New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -PropertyType DWord -Value 1 -Force
Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type DWORD -Value 1
}
"Show"
{
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -Force -ErrorAction Ignore
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start -Name HideRecommendedSection -Force -ErrorAction Ignore
Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type CLEAR
}
}
}
# Remove Recommended section in Start Menu. Not applicable to Home edition
StartRecommendedSection -Hide
# Uninstall OneDrive. The OneDrive user folder won't be removed
function OneDrive
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Uninstall"
)]
[switch]
$Uninstall,
[Parameter(
Mandatory = $true,
ParameterSetName = "Install"
)]
[switch]
$Install,
[switch]
$AllUsers
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\Policies\Microsoft\Windows\OneDrive -Name DisableFileSyncNGSC -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\OneDrive -Name DisableFileSyncNGSC -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Uninstall"
{
[string]$UninstallString = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -ErrorAction Ignore | ForEach-Object -Process {$_.Meta.Attributes["UninstallString"]}
if (-not $UninstallString)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
# Checking whether user is logged into OneDrive (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($UserEmail)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Odinstalowywanie OneDrive..." -Verbose
Stop-Process -Name OneDrive, OneDriveSetup, FileCoAuth -Force -ErrorAction Ignore
# Getting link to the OneDriveSetup.exe and its argument(s)
[string[]]$OneDriveSetup = ($UninstallString -replace("\s*/", ",/")).Split(",").Trim()
if ($OneDriveSetup.Count -eq 2)
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..1] -Wait
}
else
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..2] -Wait
}
# Get the OneDrive user folder path and remove it if it doesn't contain any user files
if (Test-Path -Path $env:OneDrive)
{
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -eq 0)
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Ignore
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa
# The system does not move the file until the operating system is restarted
# The system moves the file immediately after AUTOCHK is executed, but before creating any paging files
$Script:Signature = @{
Namespace = "WinAPI"
Name = "DeleteFiles"
Language = "CSharp"
CompilerParameters = $CompilerParameters
MemberDefinition = @"
public enum MoveFileFlags
{
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004
}
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags dwFlags);
public static bool MarkFileDelete (string sourcefile)
{
return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
}
"@
}
# If there are some files or folders left in %OneDrive%
if ((Get-ChildItem -Path $env:OneDrive -Force -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
try
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Stop
}
catch
{
# If files are in use remove them at the next boot
Get-ChildItem -Path $env:OneDrive -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
}
else
{
Start-Process -FilePath explorer -ArgumentList $env:OneDrive
}
}
Remove-ItemProperty -Path HKCU:\Environment -Name OneDrive, OneDriveConsumer -Force -ErrorAction Ignore
$Path = @(
"HKCU:\Software\Microsoft\OneDrive",
"$env:ProgramData\Microsoft OneDrive",
"$env:SystemDrive\OneDriveTemp"
)
Remove-Item -Path $Path -Recurse -Force -ErrorAction Ignore
Unregister-ScheduledTask -TaskName *OneDrive* -Confirm:$false -ErrorAction Ignore
# Getting the OneDrive folder path and replacing quotes if exist
$OneDriveFolder = (Split-Path -Path (Split-Path -Path $OneDriveSetup[0] -Parent)) -replace '"', ""
# Do not restart File Explorer process automatically if it stops in order to unload libraries
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 0 -Force
# Kill all explorer instances in case "launch folder windows in a separate process" enabled
Get-Process -Name explorer | Stop-Process -Force
Start-Sleep -Seconds 3
# Restart File Explorer process automatically if it stops in order to unload libraries
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 1 -Force
# Attempt to unregister FileSyncShell64.dll and remove
$FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\FileSyncShell64.dll" -Force
foreach ($FileSyncShell64dll in $FileSyncShell64dlls.FullName)
{
Start-Process -FilePath regsvr32.exe -ArgumentList "/u /s $FileSyncShell64dll" -Wait
Remove-Item -Path $FileSyncShell64dll -Force -ErrorAction Ignore
if (Test-Path -Path $FileSyncShell64dll)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
# If files are in use remove them at the next boot
Get-ChildItem -Path $FileSyncShell64dll -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
# We need to wait for a few seconds to let explore launch unless it will fail to do so
Start-Process -FilePath explorer
Start-Sleep -Seconds 3
$Path = @(
$OneDriveFolder,
"$env:LOCALAPPDATA\OneDrive",
"$env:LOCALAPPDATA\Microsoft\OneDrive",
"$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
)
Remove-Item -Path $Path -Recurse -Force -ErrorAction Ignore
}
"Install"
{
$OneDrive = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if ($OneDrive)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
if (Test-Path -Path $env:SystemRoot\System32\OneDriveSetup.exe)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Instalowanie OneDrive..." -Verbose
if ($AllUsers)
{
# Install OneDrive for all users
Start-Process -FilePath $env:SystemRoot\System32\OneDriveSetup.exe -ArgumentList "/allusers"
}
else
{
Start-Process -FilePath $env:SystemRoot\System32\OneDriveSetup.exe
}
}
else
{
try
{
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Pobieranie OneDrive..." -Verbose
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
$OneDriveURL = $OneDriveXML.root.update.amd64binary.url | Select-Object -Index 1
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$DownloadsFolder\OneDriveSetup.exe"
UseBasicParsing = $true
Verbose = $true
}
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest @Parameters
if ($AllUsers)
{
# Install OneDrive for all users to %ProgramFiles%
Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe -ArgumentList "/allusers"
}
else
{
Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe
}
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message ("Nie można nawiązać połączenia z {0}" -f "https://oneclient.sfx.ms")
Write-Error -Message ("Nie można nawiązać połączenia z {0}" -f "https://oneclient.sfx.ms") -ErrorAction SilentlyContinue
Write-Error -Message ("Uruchom ponownie funkcję {0}" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
# Save screenshots by pressing Win+PrtScr in the Pictures folder
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction Ignore
Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask
}
}
}
# Uninstall OneDrive. The OneDrive user folder won't be removed
OneDrive -Uninstall
# Turn on Storage Sense
function StorageSense
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\StorageSense -Name AllowStorageSenseGlobal -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\StorageSense -Name AllowStorageSenseGlobal -Type CLEAR
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -ItemType Directory -Force
}
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
# Turn on Storage Sense
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01 -PropertyType DWord -Value 1 -Force
# Turn on automatic cleaning up temporary system and app files
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 04 -PropertyType DWord -Value 1 -Force
# Run Storage Sense every month
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 2048 -PropertyType DWord -Value 30 -Force
}
"Disable"
{
# Turn off Storage Sense
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01 -PropertyType DWord -Value 0 -Force
# Turn off automatic cleaning up temporary system and app files
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 04 -PropertyType DWord -Value 0 -Force
# Run Storage Sense during low free disk space
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 2048 -PropertyType DWord -Value 0 -Force
}
}
}
# Turn on Storage Sense
StorageSense -Enable
# Disable hibernation. It isn't recommended to turn off for laptops
function Hibernation
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
POWERCFG /HIBERNATE OFF
}
"Enable"
{
POWERCFG /HIBERNATE ON
}
}
}
# Disable hibernation. It isn't recommended to turn off for laptops
Hibernation -Disable
# Disable the Windows 260 characters path limit
function Win32LongPathLimit
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -PropertyType DWord -Value 1 -Force
}
"Enable"
{
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -PropertyType DWord -Value 0 -Force
}
}
}
# Disable the Windows 260 characters path limit
Win32LongPathLimit -Disable
# Display Stop error code when BSoD occurs
function BSoDStopError
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl -Name DisplayParameters -PropertyType DWord -Value 1 -Force
}
"Disable"
{
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl -Name DisplayParameters -PropertyType DWord -Value 0 -Force
}
}
}
# Display Stop error code when BSoD occurs
BSoDStopError -Enable
# Turn off Delivery Optimization
function DeliveryOptimization
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DeliveryOptimization -Name DODownloadMode -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DeliveryOptimization -Name DODownloadMode -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path Registry::HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings -Name DownloadMode -PropertyType DWord -Value 0 -Force
Delete-DeliveryOptimizationCache -Force
}
"Enable"
{
New-ItemProperty -Path Registry::HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings -Name DownloadMode -PropertyType DWord -Value 1 -Force
}
}
}
# Turn off Delivery Optimization
DeliveryOptimization -Disable
<#
Disable the Windows features using the pop-up dialog box
If you want to leave "Multimedia settings" element in the advanced settings of Power Options do not disable the "Media Features" feature
#>
function WindowsFeatures
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
Add-Type -AssemblyName PresentationCore, PresentationFramework
#region Variables
# Initialize an array list to store the selected Windows features
$SelectedFeatures = New-Object -TypeName System.Collections.ArrayList($null)
# The following Windows features will have their checkboxes checked
[string[]]$CheckedFeatures = @(
# Legacy Components
"LegacyComponents",
# PowerShell 2.0
"MicrosoftWindowsPowerShellV2",
"MicrosoftWindowsPowershellV2Root",
# Microsoft XPS Document Writer
"Printing-XPSServices-Features",
# Recall
"Recall"
# Work Folders Client
"WorkFolders-Client"
)
# The following Windows features will have their checkboxes unchecked
[string[]]$UncheckedFeatures = @(
# Media Features
# If you want to leave "Multimedia settings" in the advanced settings of Power Options do not disable this feature
"MediaPlayback"
)
#endregion Variables
#region XAML Markup
# The section defines the design of the upcoming dialog box
[xml]$XAML = @"
"@
#endregion XAML Markup
$Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML))
$XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process {
Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)
}
#region Functions
function Get-CheckboxClicked
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateNotNull()]
$CheckBox
)
$Feature = $Features | Where-Object -FilterScript {$_.DisplayName -eq $CheckBox.Parent.Children[1].Text}
if ($CheckBox.IsChecked)
{
[void]$SelectedFeatures.Add($Feature)
}
else
{
[void]$SelectedFeatures.Remove($Feature)
}
if ($SelectedFeatures.Count -gt 0)
{
$Button.IsEnabled = $true
}
else
{
$Button.IsEnabled = $false
}
}
function DisableButton
{
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
[void]$Window.Close()
$SelectedFeatures | ForEach-Object -Process {Write-Verbose -Message $_.DisplayName -Verbose}
$SelectedFeatures | Disable-WindowsOptionalFeature -Online -NoRestart
}
function EnableButton
{
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
[void]$Window.Close()
$SelectedFeatures | ForEach-Object -Process {Write-Verbose -Message $_.DisplayName -Verbose}
$SelectedFeatures | Enable-WindowsOptionalFeature -Online -NoRestart
}
function Add-FeatureControl
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateNotNull()]
$Feature
)
process
{
$CheckBox = New-Object -TypeName System.Windows.Controls.CheckBox
$CheckBox.Add_Click({Get-CheckboxClicked -CheckBox $_.Source})
$CheckBox.ToolTip = $Feature.Description
$TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock
$TextBlock.Text = $Feature.DisplayName
$TextBlock.ToolTip = $Feature.Description
$StackPanel = New-Object -TypeName System.Windows.Controls.StackPanel
[void]$StackPanel.Children.Add($CheckBox)
[void]$StackPanel.Children.Add($TextBlock)
[void]$PanelContainer.Children.Add($StackPanel)
$CheckBox.IsChecked = $true
# If feature checked add to the array list
if ($UnCheckedFeatures | Where-Object -FilterScript {$Feature.FeatureName -like $_})
{
$CheckBox.IsChecked = $false
# Exit function if item is not checked
return
}
# If feature checked add to the array list
[void]$SelectedFeatures.Add($Feature)
}
}
#endregion Functions
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
$State = @("Disabled", "DisablePending")
$ButtonContent = "Wlaczac"
$ButtonAdd_Click = {EnableButton}
}
"Disable"
{
$State = @("Enabled", "EnablePending")
$ButtonContent = "Wylaczyc"
$ButtonAdd_Click = {DisableButton}
}
}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
# Getting list of all optional features according to the conditions
$OFS = "|"
$Features = Get-WindowsOptionalFeature -Online | Where-Object -FilterScript {
($_.State -in $State) -and (($_.FeatureName -match $UncheckedFeatures) -or ($_.FeatureName -match $CheckedFeatures))
} | ForEach-Object -Process {Get-WindowsOptionalFeature -FeatureName $_.FeatureName -Online}
$OFS = " "
if (-not $Features)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Nic do wyświetlenia." -Verbose
return
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Wyświetlanie okna dialogowego..." -Verbose
#region Sendkey function
# Emulate the Backspace key sending to prevent the console window to freeze
Start-Sleep -Milliseconds 500
Add-Type -AssemblyName System.Windows.Forms
# We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID
Get-Process -Name powershell, WindowsTerminal -ErrorAction Ignore | Where-Object -FilterScript {$_.MainWindowTitle -match "Sophia Script for Windows 11"} | ForEach-Object -Process {
# Show window, if minimized
# [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
# Start-Sleep -Seconds 1
# Force move the console window to the foreground
# [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle)
Start-Sleep -Seconds 1
# Emulate the Backspace key sending
# [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
}
#endregion Sendkey function
$Window.Add_Loaded({$Features | Add-FeatureControl})
$Button.Content = $ButtonContent
$Button.Add_Click({& $ButtonAdd_Click})
$Window.Title = "Funkcje Windows"
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
WindowsFeatures -Disable
<#
Uninstall optional features using the pop-up dialog box
If you want to leave "Multimedia settings" element in the advanced settings of Power Options do not uninstall the "Media Features" feature
#>
function WindowsCapabilities
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Uninstall"
)]
[switch]
$Uninstall,
[Parameter(
Mandatory = $true,
ParameterSetName = "Install"
)]
[switch]
$Install
)
Add-Type -AssemblyName PresentationCore, PresentationFramework
#region Variables
# Initialize an array list to store the selected optional features
$SelectedCapabilities = New-Object -TypeName System.Collections.ArrayList($null)
# The following optional features will have their checkboxes checked
[string[]]$CheckedCapabilities = @(
# Steps Recorder
"App.StepsRecorder*"
)
# The following optional features will have their checkboxes unchecked
[string[]]$UncheckedCapabilities = @(
# Internet Explorer mode
"Browser.InternetExplorer*",
# Windows Media Player
# If you want to leave "Multimedia settings" element in the advanced settings of Power Options do not uninstall this feature
"Media.WindowsMediaPlayer*"
)
# The following optional features will be excluded from the display
[string[]]$ExcludedCapabilities = @(
# The DirectX Database to configure and optimize apps when multiple Graphics Adapters are present
"DirectX.Configuration.Database*",
# Language components
"Language.*",
# Notepad
"Microsoft.Windows.Notepad*",
# Mail, contacts, and calendar sync component
"OneCoreUAP.OneSync*",
# Windows PowerShell Intergrated Scripting Enviroment
"Microsoft.Windows.PowerShell.ISE*",
# Management of printers, printer drivers, and printer servers
"Print.Management.Console*",
# Features critical to Windows functionality
"Windows.Client.ShellComponents*"
)
#endregion Variables
#region XAML Markup
# The section defines the design of the upcoming dialog box
[xml]$XAML = @"
"@
#endregion XAML Markup
$Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML))
$XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process {
Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)
}
#region Functions
function Get-CheckboxClicked
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateNotNull()]
$CheckBox
)
$Capability = $Capabilities | Where-Object -FilterScript {$_.DisplayName -eq $CheckBox.Parent.Children[1].Text}
if ($CheckBox.IsChecked)
{
[void]$SelectedCapabilities.Add($Capability)
}
else
{
[void]$SelectedCapabilities.Remove($Capability)
}
if ($SelectedCapabilities.Count -gt 0)
{
$Button.IsEnabled = $true
}
else
{
$Button.IsEnabled = $false
}
}
function UninstallButton
{
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
[void]$Window.Close()
$SelectedCapabilities | ForEach-Object -Process {Write-Verbose -Message $_.DisplayName -Verbose}
$SelectedCapabilities | Where-Object -FilterScript {$_.Name -in (Get-WindowsCapability -Online).Name} | Remove-WindowsCapability -Online
if ([string]$SelectedCapabilities.Name -match "Browser.InternetExplorer")
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message "Pamiętaj o ponownym uruchomieniu komputera."
}
}
function InstallButton
{
try
{
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
[void]$Window.Close()
$SelectedCapabilities | ForEach-Object -Process {Write-Verbose -Message $_.DisplayName -Verbose}
$SelectedCapabilities | Where-Object -FilterScript {$_.Name -in ((Get-WindowsCapability -Online).Name)} | Add-WindowsCapability -Online
if ([string]$SelectedCapabilities.Name -match "Browser.InternetExplorer")
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message "Pamiętaj o ponownym uruchomieniu komputera."
}
}
catch [System.Runtime.InteropServices.COMException]
{
Write-Warning -Message ("Nie można nawiązać połączenia z {0}" -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ("Nie można nawiązać połączenia z {0}" -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ("Uruchom ponownie funkcję {0}" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
function Add-CapabilityControl
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateNotNull()]
$Capability
)
process
{
$CheckBox = New-Object -TypeName System.Windows.Controls.CheckBox
$CheckBox.Add_Click({Get-CheckboxClicked -CheckBox $_.Source})
$CheckBox.ToolTip = $Capability.Description
$TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock
$TextBlock.Text = $Capability.DisplayName
$TextBlock.ToolTip = $Capability.Description
$StackPanel = New-Object -TypeName System.Windows.Controls.StackPanel
[void]$StackPanel.Children.Add($CheckBox)
[void]$StackPanel.Children.Add($TextBlock)
[void]$PanelContainer.Children.Add($StackPanel)
# If capability checked add to the array list
if ($UnCheckedCapabilities | Where-Object -FilterScript {$Capability.Name -like $_})
{
$CheckBox.IsChecked = $false
# Exit function if item is not checked
return
}
# If capability checked add to the array list
[void]$SelectedCapabilities.Add($Capability)
}
}
#endregion Functions
switch ($PSCmdlet.ParameterSetName)
{
"Install"
{
try
{
$State = "NotPresent"
$ButtonContent = "Zainstalluj"
$ButtonAdd_Click = {InstallButton}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message ("Nie można nawiązać połączenia z {0}" -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ("Nie można nawiązać połączenia z {0}" -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ("Uruchom ponownie funkcję {0}" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Uninstall"
{
$State = "Installed"
$ButtonContent = "Odinstaluj"
$ButtonAdd_Click = {UninstallButton}
}
}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
# Getting list of all capabilities according to the conditions
$OFS = "|"
$Capabilities = Get-WindowsCapability -Online | Where-Object -FilterScript {
($_.State -eq $State) -and (($_.Name -match $UncheckedCapabilities) -or ($_.Name -match $CheckedCapabilities) -and ($_.Name -notmatch $ExcludedCapabilities))
} | ForEach-Object -Process {Get-WindowsCapability -Name $_.Name -Online}
$OFS = " "
if (-not $Capabilities)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Nic do wyświetlenia." -Verbose
return
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Wyświetlanie okna dialogowego..." -Verbose
#region Sendkey function
# Emulate the Backspace key sending to prevent the console window to freeze
Start-Sleep -Milliseconds 500
Add-Type -AssemblyName System.Windows.Forms
# We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID
Get-Process -Name powershell, WindowsTerminal -ErrorAction Ignore | Where-Object -FilterScript {$_.MainWindowTitle -match "Sophia Script for Windows 11"} | ForEach-Object -Process {
# Show window, if minimized
# [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
# Start-Sleep -Seconds 1
# Force move the console window to the foreground
# [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle)
Start-Sleep -Seconds 1
# Emulate the Backspace key sending
# [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
}
#endregion Sendkey function
$Window.Add_Loaded({$Capabilities | Add-CapabilityControl})
$Button.Content = $ButtonContent
$Button.Add_Click({& $ButtonAdd_Click})
$Window.Title = "Funkcje opcjonalne"
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
WindowsCapabilities -Uninstall
# Receive updates for other Microsoft products
function UpdateMicrosoftProducts
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AllowMUUpdateService -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AllowMUUpdateService -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name AllowMUUpdateService -PropertyType DWord -Value 1 -Force
}
"Disable"
{
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name AllowMUUpdateService -Force -ErrorAction Ignore
}
}
}
# Receive updates for other Microsoft products
UpdateMicrosoftProducts -Enable
#
# ???????????
# Notify me when a restart is required to finish updating
function RestartNotification
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show,
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name SetAutoRestartNotificationDisable -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name SetAutoRestartNotificationDisable -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Show"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name RestartNotificationsAllowed2 -PropertyType DWord -Value 1 -Force
}
"Hide"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name RestartNotificationsAllowed2 -PropertyType DWord -Value 0 -Force
}
}
}
# Notify me when a restart is required to finish updating
# RestartNotification -Show
#
# ???????????
# Restart as soon as possible to finish updating
function RestartDeviceAfterUpdate
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name ActiveHoursEnd, ActiveHoursStart, SetActiveHours -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name ActiveHoursEnd -Type CLEAR
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name ActiveHoursStart -Type CLEAR
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name SetActiveHours -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name IsExpedited -PropertyType DWord -Value 1 -Force
}
"Disable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name IsExpedited -PropertyType DWord -Value 0 -Force
}
}
}
# Restart as soon as possible to finish updating
# RestartDeviceAfterUpdate -Enable
# Set power plan on "High performance". It isn't recommended to turn on for laptops
function PowerPlan
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "High"
)]
[switch]
$High,
[Parameter(
Mandatory = $true,
ParameterSetName = "Balanced"
)]
[switch]
$Balanced
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Power\PowerSettings -Name ActivePowerScheme -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Power\PowerSettings -Name ActivePowerScheme -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"High"
{
POWERCFG /SETACTIVE SCHEME_MIN
}
"Balanced"
{
POWERCFG /SETACTIVE SCHEME_BALANCED
}
}
}
# Set power plan on "High performance". It isn't recommended to turn on for laptops
PowerPlan -High
# Do not allow the computer to turn off the network adapters to save power. It isn't recommended to turn off for laptops
function NetworkAdaptersSavePower
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
# Checking whether there's an adapter that has AllowComputerToTurnOffDevice property to manage
# We need also check for adapter status per some laptops have many equal adapters records in adapters list
$Adapters = Get-NetAdapter -Physical | Where-Object -FilterScript {$_.MacAddress -and ($_.Status -eq "Up")} | Get-NetAdapterPowerManagement | Where-Object -FilterScript {$_.AllowComputerToTurnOffDevice -ne "Unsupported"}
if (-not $Adapters)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
$PhysicalAdaptersStatusUp = @(Get-NetAdapter -Physical | Where-Object -FilterScript {($_.Status -eq "Up") -and $_.MacAddress})
# Checking whether PC is currently connected to a Wi-Fi network
# NetConnectionStatus 2 is Wi-Fi
$InterfaceIndex = (Get-CimInstance -ClassName Win32_NetworkAdapter -Namespace root/CIMV2 | Where-Object -FilterScript {$_.NetConnectionStatus -eq 2}).InterfaceIndex
if (Get-NetAdapter -Physical | Where-Object -FilterScript {($_.Status -eq "Up") -and ($_.PhysicalMediaType -eq "Native 802.11") -and ($_.InterfaceIndex -eq $InterfaceIndex)})
{
# Get currently connected Wi-Fi network SSID
$SSID = (Get-NetConnectionProfile).Name
}
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
foreach ($Adapter in $Adapters)
{
$Adapter.AllowComputerToTurnOffDevice = "Disabled"
$Adapter | Set-NetAdapterPowerManagement
}
}
"Enable"
{
foreach ($Adapter in $Adapters)
{
$Adapter.AllowComputerToTurnOffDevice = "Enabled"
$Adapter | Set-NetAdapterPowerManagement
}
}
}
# All network adapters are turned into "Disconnected" for few seconds, so we need to wait a bit to let them up
# Otherwise functions below will indicate that there is no the Internet connection
if ($PhysicalAdaptersStatusUp)
{
# If Wi-Fi network was used
if ($SSID)
{
Write-Verbose -Message $SSID -Verbose
# Connect to it
netsh wlan connect name=$SSID
}
while
(
Get-NetAdapter -Physical -Name $PhysicalAdaptersStatusUp.Name | Where-Object -FilterScript {($_.Status -eq "Disconnected") -and $_.MacAddress}
)
{
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
Start-Sleep -Seconds 2
}
}
}
# Do not allow the computer to turn off the network adapters to save power. It isn't recommended to turn off for laptops
NetworkAdaptersSavePower -Disable
# Launch folder windows in a separate process
function FoldersLaunchSeparateProcess
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name SeparateProcess -PropertyType DWord -Value 1 -Force
}
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name SeparateProcess -PropertyType DWord -Value 0 -Force
}
}
}
# Launch folder windows in a separate process
FoldersLaunchSeparateProcess -Enable
# Disable help lookup via F1
function F1HelpPage
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if (-not (Test-Path -Path "HKCU:\Software\Classes\Typelib\{8cec5860-07a1-11d9-b15e-000d56bfe6ee}\1.0\0\win64"))
{
New-Item -Path "HKCU:\Software\Classes\Typelib\{8cec5860-07a1-11d9-b15e-000d56bfe6ee}\1.0\0\win64" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\Typelib\{8cec5860-07a1-11d9-b15e-000d56bfe6ee}\1.0\0\win64" -Name "(default)" -PropertyType String -Value "" -Force
}
"Enable"
{
Remove-Item -Path "HKCU:\Software\Classes\Typelib\{8cec5860-07a1-11d9-b15e-000d56bfe6ee}" -Recurse -Force -ErrorAction Ignore
}
}
}
# Disable help lookup via F1
F1HelpPage -Disable
# Enable Num Lock at startup
function NumLock
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path "Registry::HKEY_USERS\.DEFAULT\Control Panel\Keyboard" -Name InitialKeyboardIndicators -PropertyType String -Value 2147483650 -Force
}
"Disable"
{
New-ItemProperty -Path "Registry::HKEY_USERS\.DEFAULT\Control Panel\Keyboard" -Name InitialKeyboardIndicators -PropertyType String -Value 2147483648 -Force
}
}
}
# Enable Num Lock at startup
NumLock -Enable
# Turn off pressing the Shift key 5 times to turn Sticky keys
function StickyShift
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path "HKCU:\Control Panel\Accessibility\StickyKeys" -Name Flags -PropertyType String -Value 506 -Force
}
"Enable"
{
New-ItemProperty -Path "HKCU:\Control Panel\Accessibility\StickyKeys" -Name Flags -PropertyType String -Value 510 -Force
}
}
}
# Turn off pressing the Shift key 5 times to turn Sticky keys
StickyShift -Disable
# Don't use AutoPlay for all media and devices
function Autoplay
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer, HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name NoDriveTypeAutoRun -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name NoDriveTypeAutoRun -Type CLEAR
Set-Policy -Scope User -Path Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name NoDriveTypeAutoRun -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers -Name DisableAutoplay -PropertyType DWord -Value 1 -Force
}
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers -Name DisableAutoplay -PropertyType DWord -Value 0 -Force
}
}
}
# Don't use AutoPlay for all media and devices
Autoplay -Disable
# Install the latest Microsoft Visual C++ Redistributable Packages 2015–2022 (x86/x64)
function Install-VCRedist
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Redistributables"
)]
[ValidateSet("2015_2022_x86", "2015_2022_x64")]
[string[]]
$Redistributables
)
# Get latest build version
# https://github.com/ScoopInstaller/Extras/blob/master/bucket/vcredist2022.json
try
{
$Parameters = @{
Uri = "https://raw.githubusercontent.com/ScoopInstaller/Extras/refs/heads/master/bucket/vcredist2022.json"
UseBasicParsing = $true
Verbose = $true
}
$LatestVCRedistVersion = (Invoke-RestMethod @Parameters).version
}
catch [System.Net.WebException]
{
$LatestVCRedistVersion = "0.0"
}
# Checking whether VC_redist builds installed
if (Test-Path -Path "$env:ProgramData\Package Cache\{e7802eac-3305-4da0-9378-e55d1ed05518}\VC_redist.x86.exe")
{
$VCredistx86Version = (Get-Item -Path "$env:ProgramData\Package Cache\{e7802eac-3305-4da0-9378-e55d1ed05518}\VC_redist.x86.exe").VersionInfo.FileVersion
}
else
{
$VCredistx86Version = "0.0"
}
if (Test-Path -Path "$env:ProgramData\Package Cache\{804e7d66-ccc2-4c12-84ba-476da31d103d}\VC_redist.x64.exe")
{
$VCredistx64Version = (Get-Item -Path "$env:ProgramData\Package Cache\{804e7d66-ccc2-4c12-84ba-476da31d103d}\VC_redist.x64.exe").VersionInfo.FileVersion
}
else
{
$VCredistx64Version = "0.0"
}
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
foreach ($Redistributable in $Redistributables)
{
switch ($Redistributable)
{
2015_2022_x86
{
# Proceed if currently installed build is lower than available from Microsoft or json file is unreachable, or redistributable is not installed
if (([System.Version]$LatestVCRedistVersion -gt [System.Version]$VCredistx86Version) -or (($LatestVCRedistVersion -eq "0.0") -or ($VCredistx86Version -eq "0.0")))
{
try
{
$Parameters = @{
Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe"
OutFile = "$DownloadsFolder\VC_redist.x86.exe"
UseBasicParsing = $true
Verbose = $true
}
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest @Parameters
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Visual C++ Redistributable x86" -Verbose
Write-Information -MessageData "" -InformationAction Continue
Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
$Paths = @(
"$DownloadsFolder\VC_redist.x86.exe",
"$env:TEMP\dd_vcredist_x86_*.log"
)
Get-ChildItem -Path $Paths -Force | Remove-Item -Force -ErrorAction Ignore
}
catch [System.Net.WebException]
{
Write-Warning -Message ("Nie można nawiązać połączenia z {0}" -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ("Nie można nawiązać połączenia z {0}" -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ("Uruchom ponownie funkcję {0}" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
else
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f ("{0} -{1} {2}" -f $MyInvocation.MyCommand.Name, $MyInvocation.BoundParameters.Keys.Trim(), $_)) -Verbose
Write-Error -Message ("Pominięto" -f ("{0} -{1} {2}" -f $MyInvocation.MyCommand.Name, $MyInvocation.BoundParameters.Keys.Trim(), $_)) -ErrorAction SilentlyContinue
}
}
2015_2022_x64
{
# Proceed if currently installed build is lower than available from Microsoft or json file is unreachable, or redistributable is not installed
if (([System.Version]$LatestVCRedistVersion -gt [System.Version]$VCredistx64Version) -or (($LatestVCRedistVersion -eq "0.0") -or ($VCredistx64Version -eq "0.0")))
{
try
{
$Parameters = @{
Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe"
OutFile = "$DownloadsFolder\VC_redist.x64.exe"
UseBasicParsing = $true
Verbose = $true
}
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ("Nie można nawiązać połączenia z {0}" -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ("Nie można nawiązać połączenia z {0}" -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ("Uruchom ponownie funkcję {0}" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Visual C++ Redistributable x64" -Verbose
Write-Information -MessageData "" -InformationAction Continue
Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
$Paths = @(
"$DownloadsFolder\VC_redist.x64.exe",
"$env:TEMP\dd_vcredist_amd64_*.log"
)
Get-ChildItem -Path $Paths -Force | Remove-Item -Force -ErrorAction Ignore
}
else
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f ("{0} -{1} {2}" -f $MyInvocation.MyCommand.Name, $MyInvocation.BoundParameters.Keys.Trim(), $_)) -Verbose
Write-Error -Message ("Pominięto" -f ("{0} -{1} {2}" -f $MyInvocation.MyCommand.Name, $MyInvocation.BoundParameters.Keys.Trim(), $_)) -ErrorAction SilentlyContinue
}
}
}
}
}
write-Host "Install the latest Microsoft Visual C++ Redistributable Packages 2015–2022 (x86/x64)"
Install-VCRedist -Redistributables 2015_2022_x86, 2015_2022_x64
Write-Host "List Microsoft Edge channels to prevent desktop shortcut creation upon its update"
function PreventEdgeShortcutCreation
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $false,
ParameterSetName = "Channels"
)]
[ValidateSet("Stable", "Beta", "Dev", "Canary")]
[string[]]
$Channels,
[Parameter(
Mandatory = $false,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
if (-not (Get-Package -Name "Microsoft Edge" -ProviderName Programs -ErrorAction Ignore))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\EdgeUpdate))
{
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\EdgeUpdate -Force
}
foreach ($Channel in $Channels)
{
switch ($Channel)
{
Stable
{
if (Get-Package -Name "Microsoft Edge" -ProviderName Programs -ErrorAction Ignore)
{
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}" -PropertyType DWord -Value 0 -Force
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}" -Type DWORD -Value 3
}
}
Beta
{
if (Get-Package -Name "Microsoft Edge Beta" -ProviderName Programs -ErrorAction Ignore)
{
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{2CD8A007-E189-409D-A2C8-9AF4EF3C72AA}" -PropertyType DWord -Value 0 -Force
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}" -Type DWORD -Value 3
}
}
Dev
{
if (Get-Package -Name "Microsoft Edge Dev" -ProviderName Programs -ErrorAction Ignore)
{
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{0D50BFEC-CD6A-4F9A-964C-C7416E3ACB10}" -PropertyType DWord -Value 0 -Force
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}" -Type DWORD -Value 3
}
}
Canary
{
if (Get-Package -Name "Microsoft Edge Canary" -ProviderName Programs -ErrorAction Ignore)
{
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{65C35B14-6C1D-4122-AC46-7148CC9D6497}" -PropertyType DWord -Value 0 -Force
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}" -Type DWORD -Value 3
}
}
}
}
if ($Disable)
{
$Names = @(
"CreateDesktopShortcut{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}",
"CreateDesktopShortcut{2CD8A007-E189-409D-A2C8-9AF4EF3C72AA}",
"CreateDesktopShortcut{0D50BFEC-CD6A-4F9A-964C-C7416E3ACB10}",
"CreateDesktopShortcut{65C35B14-6C1D-4122-AC46-7148CC9D6497}"
)
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\EdgeUpdate -Name $Names -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}" -Type CLEAR
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{2CD8A007-E189-409D-A2C8-9AF4EF3C72AA}" -Type CLEAR
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{0D50BFEC-CD6A-4F9A-964C-C7416E3ACB10}" -Type CLEAR
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\EdgeUpdate -Name "CreateDesktopShortcut{65C35B14-6C1D-4122-AC46-7148CC9D6497}" -Type CLEAR
}
}
Write-Host "List Microsoft Edge channels to prevent desktop shortcut creation upon its update"
PreventEdgeShortcutCreation -Channels Stable, Beta, Dev, Canary
# Uninstall UWP apps using the pop-up dialog box
function UninstallUWPApps
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $false)]
[switch]
$ForAllUsers
)
Add-Type -AssemblyName PresentationCore, PresentationFramework
#region Variables
# The following UWP apps will have their checkboxes unchecked
$UncheckedAppxPackages = @(
# Dolby Access
"DolbyLaboratories.DolbyAccess",
# Windows Media Player
"Microsoft.ZuneMusic",
# Screen Sketch
"Microsoft.ScreenSketch",
# Photos (and Video Editor)
"Microsoft.Windows.Photos",
"Microsoft.Photos.MediaEngineDLC",
# Calculator
"Microsoft.WindowsCalculator",
# Windows Camera
"Microsoft.WindowsCamera",
# Xbox Identity Provider
"Microsoft.XboxIdentityProvider",
# Xbox Console Companion
"Microsoft.XboxApp",
# Xbox
"Microsoft.GamingApp",
"Microsoft.GamingServices",
# Paint
"Microsoft.Paint",
# Xbox TCUI
"Microsoft.Xbox.TCUI",
# Xbox Speech To Text Overlay
"Microsoft.XboxSpeechToTextOverlay",
# Xbox Game Bar
"Microsoft.XboxGamingOverlay",
# Xbox Game Bar Plugin
"Microsoft.XboxGameOverlay"
)
# The following UWP apps will be excluded from the display
$ExcludedAppxPackages = @(
# AMD Radeon Software
"AdvancedMicroDevicesInc-2.AMDRadeonSoftware",
# Intel Graphics Control Center
"AppUp.IntelGraphicsControlPanel",
"AppUp.IntelGraphicsExperience",
# ELAN Touchpad
"ELANMicroelectronicsCorpo.ELANTouchpadforThinkpad",
"ELANMicroelectronicsCorpo.ELANTrackPointforThinkpa",
# Microsoft Application Compatibility Enhancements
"Microsoft.ApplicationCompatibilityEnhancements",
# AVC Encoder Video Extension
"Microsoft.AVCEncoderVideoExtension",
# Microsoft Desktop App Installer
"Microsoft.DesktopAppInstaller",
"Microsoft.WindowsCalculator",
# Store Experience Host
"Microsoft.StorePurchaseApp",
# Cross Device Experience Host
"MicrosoftWindows.CrossDevice",
# Notepad
"Microsoft.WindowsNotepad",
# Microsoft Store
"Microsoft.WindowsStore",
# Windows Terminal
"Microsoft.WindowsTerminal",
"Microsoft.WindowsTerminalPreview",
# Web Media Extensions
"Microsoft.WebMediaExtensions",
# AV1 Video Extension
"Microsoft.AV1VideoExtension",
# Windows Subsystem for Linux
"MicrosoftCorporationII.WindowsSubsystemForLinux",
# HEVC Video Extensions from Device Manufacturer
"Microsoft.HEVCVideoExtension",
"Microsoft.HEVCVideoExtensions",
# Raw Image Extension
"Microsoft.RawImageExtension",
# HEIF Image Extensions
"Microsoft.HEIFImageExtension",
# MPEG-2 Video Extension
"Microsoft.MPEG2VideoExtension",
# VP9 Video Extensions
"Microsoft.VP9VideoExtensions",
# Webp Image Extensions
"Microsoft.WebpImageExtension",
# PowerShell
"Microsoft.PowerShell",
# NVIDIA Control Panel
"NVIDIACorp.NVIDIAControlPanel",
# Realtek Audio Console
"RealtekSemiconductorCorp.RealtekAudioControl",
# Synaptics
"SynapticsIncorporated.SynapticsControlPanel",
"SynapticsIncorporated.24916F58D6E7"
)
#region Variables
#region XAML Markup
# The section defines the design of the upcoming dialog box
[xml]$XAML = @"
"@
#endregion XAML Markup
$Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML))
$XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process {
Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)
}
$Window.Title = "Aplikacje UWP"
$ButtonUninstall.Content = "Odinstaluj"
$TextBlockRemoveForAll.Text = "Odinstaluj dla wszystkich"
# Extract the localized "Select all" string from shell32.dll
$TextBlockSelectAll.Text = "Zaznacz wszystkie"
$ButtonUninstall.Add_Click({ButtonUninstallClick})
$CheckBoxForAllUsers.Add_Click({CheckBoxForAllUsersClick})
$CheckBoxSelectAll.Add_Click({CheckBoxSelectAllClick})
#endregion Variables
#region Functions
function Get-AppxBundle
{
[CmdletBinding()]
param
(
[string[]]
$Exclude,
[switch]
$AllUsers
)
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
$AppxPackages = @(Get-AppxPackage -PackageTypeFilter Bundle -AllUsers:$AllUsers | Where-Object -FilterScript {$_.Name -notin $ExcludedAppxPackages})
# The -PackageTypeFilter Bundle doesn't contain these packages, and we need to add manually
$Packages = @(
# Outlook
"Microsoft.OutlookForWindows",
# Microsoft Teams
"MSTeams"
)
foreach ($Package in $Packages)
{
if (Get-AppxPackage -Name $Package -AllUsers:$AllUsers)
{
$AppxPackages += Get-AppxPackage -Name $Package -AllUsers:$AllUsers
}
}
$PackagesIds = [Windows.Management.Deployment.PackageManager, Windows.Web, ContentType = WindowsRuntime]::new().FindPackages() | Select-Object -Property DisplayName -ExpandProperty Id | Select-Object -Property Name, DisplayName
foreach ($AppxPackage in $AppxPackages)
{
$PackageId = $PackagesIds | Where-Object -FilterScript {$_.Name -eq $AppxPackage.Name}
if (-not $PackageId)
{
continue
}
[PSCustomObject]@{
Name = $AppxPackage.Name
PackageFullName = $AppxPackage.PackageFullName
# Sometimes there's more than one package presented in Windows with the same package name like {Microsoft Teams, Microsoft Teams} and we need to display the first one
DisplayName = $PackageId.DisplayName | Select-Object -First 1
}
}
}
function Add-Control
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateNotNull()]
[PSCustomObject[]]
$Packages
)
process
{
foreach ($Package in $Packages)
{
$CheckBox = New-Object -TypeName System.Windows.Controls.CheckBox
$CheckBox.Tag = $Package.PackageFullName
$TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock
if ($Package.DisplayName)
{
$TextBlock.Text = $Package.DisplayName
}
else
{
$TextBlock.Text = $Package.Name
}
$StackPanel = New-Object -TypeName System.Windows.Controls.StackPanel
$StackPanel.Children.Add($CheckBox) | Out-Null
$StackPanel.Children.Add($TextBlock) | Out-Null
$PanelContainer.Children.Add($StackPanel) | Out-Null
if ($UncheckedAppxPackages.Contains($Package.Name))
{
$CheckBox.IsChecked = $false
}
else
{
$CheckBox.IsChecked = $true
$PackagesToRemove.Add($Package.PackageFullName)
}
$CheckBox.Add_Click({CheckBoxClick})
}
}
}
function CheckBoxForAllUsersClick
{
$PanelContainer.Children.RemoveRange(0, $PanelContainer.Children.Count)
$PackagesToRemove.Clear()
$AppXPackages = Get-AppxBundle -Exclude $ExcludedAppxPackages -AllUsers:$CheckBoxForAllUsers.IsChecked
$AppXPackages | Add-Control
ButtonUninstallSetIsEnabled
}
function ButtonUninstallClick
{
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message "Please wait..." -Verbose
$Window.Close() | Out-Null
# If MSTeams is selected to uninstall, delete quietly "Microsoft Teams Meeting Add-in for Microsoft Office" too
# & "$env:SystemRoot\System32\msiexec.exe" --% /x {A7AB73A3-CB10-4AA5-9D38-6AEFFBDE4C91} /qn
if ($PackagesToRemove -match "MSTeams")
{
Start-Process -FilePath "$env:SystemRoot\System32\msiexec.exe" -ArgumentList "/x {A7AB73A3-CB10-4AA5-9D38-6AEFFBDE4C91} /qn" -Wait
}
$PackagesToRemove | Remove-AppxPackage -AllUsers:$CheckBoxForAllUsers.IsChecked -Verbose
}
function CheckBoxClick
{
$CheckBox = $_.Source
if ($CheckBox.IsChecked)
{
$PackagesToRemove.Add($CheckBox.Tag) | Out-Null
}
else
{
$PackagesToRemove.Remove($CheckBox.Tag)
}
ButtonUninstallSetIsEnabled
}
function CheckBoxSelectAllClick
{
$CheckBox = $_.Source
if ($CheckBox.IsChecked)
{
$PackagesToRemove.Clear()
foreach ($Item in $PanelContainer.Children.Children)
{
if ($Item -is [System.Windows.Controls.CheckBox])
{
$Item.IsChecked = $true
$PackagesToRemove.Add($Item.Tag)
}
}
}
else
{
$PackagesToRemove.Clear()
foreach ($Item in $PanelContainer.Children.Children)
{
if ($Item -is [System.Windows.Controls.CheckBox])
{
$Item.IsChecked = $false
}
}
}
ButtonUninstallSetIsEnabled
}
function ButtonUninstallSetIsEnabled
{
if ($PackagesToRemove.Count -gt 0)
{
$ButtonUninstall.IsEnabled = $true
}
else
{
$ButtonUninstall.IsEnabled = $false
}
}
#endregion Functions
# Check "For all users" checkbox to uninstall packages from all accounts
if ($ForAllUsers)
{
$CheckBoxForAllUsers.IsChecked = $true
}
$PackagesToRemove = [Collections.Generic.List[string]]::new()
$AppXPackages = Get-AppxBundle -Exclude $ExcludedAppxPackages -AllUsers:$ForAllUsers
$AppXPackages | Add-Control
if ($AppxPackages.Count -eq 0)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Nic do wyświetlenia." -Verbose
}
else
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Wyświetlanie okna dialogowego..." -Verbose
#region Sendkey function
# Emulate the Backspace key sending to prevent the console window to freeze
Start-Sleep -Milliseconds 500
Add-Type -AssemblyName System.Windows.Forms
# We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID
Get-Process -Name powershell, WindowsTerminal -ErrorAction Ignore | Where-Object -FilterScript {$_.MainWindowTitle -match "Sophia Script for Windows 11"} | ForEach-Object -Process {
# Show window, if minimized
# [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
# Start-Sleep -Seconds 1
# Force move the console window to the foreground
# [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle)
Start-Sleep -Seconds 1
# Emulate the Backspace key sending to prevent the console window to freeze
# [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
}
#endregion Sendkey function
if ($PackagesToRemove.Count -gt 0)
{
$ButtonUninstall.IsEnabled = $true
}
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
}
# Uninstall UWP apps using the pop-up dialog box
UninstallUWPApps
<#
Uninstall UWP apps for all users using the pop-up dialog box
If the "For All Users" is checked apps packages will not be installed for new users
#>
UninstallUWPApps -ForAllUsers
# Disable Cortana autostarting
function CortanaAutostart
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
if (-not (Get-AppxPackage -Name Microsoft.549981C3F5F10))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
if (-not (Test-Path -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\Microsoft.549981C3F5F10_8wekyb3d8bbwe\CortanaStartupId"))
{
New-Item -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\Microsoft.549981C3F5F10_8wekyb3d8bbwe\CortanaStartupId" -Force
}
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\Microsoft.549981C3F5F10_8wekyb3d8bbwe\CortanaStartupId" -Name State -PropertyType DWord -Value 1 -Force
}
"Enable"
{
New-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\Microsoft.549981C3F5F10_8wekyb3d8bbwe\CortanaStartupId" -Name State -PropertyType DWord -Value 2 -Force
}
}
}
# Disable Cortana autostarting
CortanaAutostart -Disable
<#
Disable Xbox Game Bar
To prevent popping up the "You'll need a new app to open this ms-gamingoverlay" warning, you need to disable the Xbox Game Bar app, even if you uninstalled it before
#>
function XboxGameBar
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\GameDVR -Name AppCaptureEnabled -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path HKCU:\System\GameConfigStore -Name GameDVR_Enabled -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\GameDVR -Name AppCaptureEnabled -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKCU:\System\GameConfigStore -Name GameDVR_Enabled -PropertyType DWord -Value 1 -Force
}
}
}
XboxGameBar -Disable
# Disable Xbox Game Bar tips
function XboxGameTips
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
if (-not (Get-AppxPackage -Name Microsoft.GamingApp))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\GameBar -Name ShowStartupPanel -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\GameBar -Name ShowStartupPanel -PropertyType DWord -Value 1 -Force
}
}
}
# Disable Xbox Game Bar tips
XboxGameTips -Disable
# Choose an app and set the "High performance" graphics performance for it. Only if you have a dedicated GPU
function Set-AppGraphicsPerformance
{
if (Get-CimInstance -ClassName Win32_VideoController | Where-Object -FilterScript {($_.AdapterDACType -ne "Internal") -and ($null -ne $_.AdapterDACType)})
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Czy chcesz ustawić wydajność grafiki wybranej aplikacji na Wysoka wydajność?" -Verbose
do
{
$Choice = Show-Menu -Menu $Browse -Default 1 -AddSkip
switch ($Choice)
{
$Browse
{
Add-Type -AssemblyName System.Windows.Forms
$OpenFileDialog = New-Object -TypeName System.Windows.Forms.OpenFileDialog
$OpenFileDialog.Filter = "*.exe|*.exe|{0} (*.*)|*.*" -f "Wszystkie pliki"
$OpenFileDialog.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
$OpenFileDialog.Multiselect = $false
# Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$OpenFileDialog.ShowDialog($Focus)
if ($OpenFileDialog.FileName)
{
if (-not (Test-Path -Path HKCU:\Software\Microsoft\DirectX\UserGpuPreferences))
{
New-Item -Path HKCU:\Software\Microsoft\DirectX\UserGpuPreferences -Force
}
New-ItemProperty -Path HKCU:\Software\Microsoft\DirectX\UserGpuPreferences -Name $OpenFileDialog.FileName -PropertyType String -Value "GpuPreference=2;" -Force
}
}
$Skip
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
$KeyboardArrows {}
}
}
until ($Choice -ne $KeyboardArrows)
}
}
# Choose an app and set the "High performance" graphics performance for it. Only if you have a dedicated GPU
# Set-AppGraphicsPerformance
<#
Turn on hardware-accelerated GPU scheduling. Restart needed
Only if you have a dedicated GPU and WDDM verion is 2.7 or higher
#>
function GPUScheduling
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
# Determining whether PC has an external graphics card
$AdapterDACType = Get-CimInstance -ClassName CIM_VideoController | Where-Object -FilterScript {($_.AdapterDACType -ne "Internal") -and ($null -ne $_.AdapterDACType)}
# Determining whether an OS is not installed on a virtual machine
$ComputerSystemModel = (Get-CimInstance -ClassName CIM_ComputerSystem).Model -notmatch "Virtual"
# Checking whether a WDDM verion is 2.7 or higher
$WddmVersion_Min = [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\FeatureSetUsage", "WddmVersion_Min", $null)
if ($AdapterDACType -and ($ComputerSystemModel -notmatch "Virtual") -and ($WddmVersion_Min -ge 2700))
{
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers -Name HwSchMode -PropertyType DWord -Value 2 -Force
}
}
"Disable"
{
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers -Name HwSchMode -PropertyType DWord -Value 1 -Force
}
}
}
GPUScheduling -Enable
# Enable Microsoft Defender Exploit Guard network protection
function NetworkProtection
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
if ((-not $Script:DefenderEnabled) -or $Script:DefenderMpPreferenceBroken)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
Set-MpPreference -EnableNetworkProtection Enabled
}
"Disable"
{
Set-MpPreference -EnableNetworkProtection Disabled
}
}
}
# Enable Microsoft Defender Exploit Guard network protection
NetworkProtection -Enable
# Enable detection for potentially unwanted applications and block them
function PUAppsDetection
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
if ((-not $Script:DefenderEnabled) -or $Script:DefenderMpPreferenceBroken)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
Set-MpPreference -PUAProtection Enabled
}
"Disable"
{
Set-MpPreference -PUAProtection Disabled
}
}
}
# Enable detection for potentially unwanted applications and block them
PUAppsDetection -Enable
# Enable sandboxing for Microsoft Defender
function DefenderSandbox
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
if (-not $Script:DefenderEnabled)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
& "$env:SystemRoot\System32\setx.exe" /M MP_FORCE_USE_SANDBOX 1
}
"Disable"
{
& "$env:SystemRoot\System32\setx.exe" /M MP_FORCE_USE_SANDBOX 0
}
}
}
# Enable sandboxing for Microsoft Defender
DefenderSandbox -Enable
# Dismiss Microsoft Defender offer in the Windows Security about signing in Microsoft account
function DismissMSAccount
{
if (-not $Script:DefenderEnabled)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows Security Health\State" -Name AccountProtection_MicrosoftAccount_Disconnected -PropertyType DWord -Value 1 -Force
}
# Dismiss Microsoft Defender offer in the Windows Security about signing in Microsoft account
DismissMSAccount
# Create the "Process Creation" сustom view in the Event Viewer to log executed processes and their arguments
function EventViewerCustomView
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
# Enable events auditing generated when a process is created (starts)
auditpol /set /subcategory:"{0CCE922B-69AE-11D9-BED3-505054503030}" /success:enable /failure:enable
# Include command line in process creation events
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit -Name ProcessCreationIncludeCmdLine_Enabled -PropertyType DWord -Value 1 -Force
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit -Name ProcessCreationIncludeCmdLine_Enabled -Type DWORD -Value 1
$XML = @"
Tworzenie procesu
Tworzenie procesu i zdarzeń audytu.
"@
if (-not (Test-Path -Path "$env:ProgramData\Microsoft\Event Viewer\Views"))
{
New-Item -Path "$env:ProgramData\Microsoft\Event Viewer\Views" -ItemType Directory -Force
}
# Save ProcessCreation.xml in the UTF-8 without BOM encoding
Set-Content -Path "$env:ProgramData\Microsoft\Event Viewer\Views\ProcessCreation.xml" -Value $XML -Encoding Default -NoNewline -Force
}
"Disable"
{
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit -Name ProcessCreationIncludeCmdLine_Enabled -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit -Name ProcessCreationIncludeCmdLine_Enabled -Type CLEAR
Remove-Item -Path "$env:ProgramData\Microsoft\Event Viewer\Views\ProcessCreation.xml" -Force -ErrorAction Ignore
}
}
}
# Create the "Process Creation" сustom view in the Event Viewer to log executed processes and their arguments
EventViewerCustomView -Enable
#
# ???????????
# Microsoft Defender SmartScreen doesn't marks downloaded files from the Internet as unsafe
function AppsSmartScreen
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
if (-not $Script:DefenderEnabled)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name SmartScreenEnabled -PropertyType String -Value Off -Force
}
"Enable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name SmartScreenEnabled -PropertyType String -Value Warn -Force
}
}
}
# Microsoft Defender SmartScreen doesn't marks downloaded files from the Internet as unsafe
# AppsSmartScreen -Disable
#
# ???????????
# Disable the Attachment Manager marking files that have been downloaded from the Internet as unsafe
function SaveZoneInformation
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Attachments -Name SaveZoneInformation -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Attachments -Name SaveZoneInformation -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments -Force
}
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments -Name SaveZoneInformation -PropertyType DWord -Value 1 -Force
Set-Policy -Scope User -Path Software\Microsoft\Windows\CurrentVersion\Policies\Attachments -Name SaveZoneInformation -Type DWORD -Value 1
}
"Enable"
{
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments -Name SaveZoneInformation -Force -ErrorAction Ignore
Set-Policy -Scope User -Path Software\Microsoft\Windows\CurrentVersion\Policies\Attachments -Name SaveZoneInformation -Type CLEAR
}
}
}
# Disable the Attachment Manager marking files that have been downloaded from the Internet as unsafe
# SaveZoneInformation -Disable
# Disable Windows Script Host. Blocks WSH from executing .js and .vbs files
function WindowsScriptHost
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
# Checking whether any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" -ErrorAction Ignore | ForEach-Object -Process {
# Skip if a scheduled task exists
if ($_.State -eq "Ready")
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ("Pominięto" -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
break
}
}
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings"))
{
New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force
}
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Name Enabled -PropertyType DWord -Value 0 -Force
}
"Enable"
{
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Name Enabled -Force -ErrorAction Ignore
}
}
}
# Disable Windows Script Host. Blocks WSH from executing .js and .vbs files
WindowsScriptHost -Disable
# Hide the "Look for an app in the Microsoft Store" item in the "Open with" dialog
function UseStoreOpenWith
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-Path -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer))
{
New-Item -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Force
}
New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -PropertyType DWord -Value 1 -Force
Set-Policy -Scope User -Path Software\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -Type DWORD -Value 1
}
"Show"
{
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -Force -ErrorAction Ignore
Set-Policy -Scope User -Path Software\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -Type CLEAR
}
}
}
# Hide the "Look for an app in the Microsoft Store" item in the "Open with" dialog
UseStoreOpenWith -Hide
# ------------------------------------------------------------
Write-Host "Troche moich poprawek"
# ------------------------------------------------------------
### Disable Location tracking ###
### When Location Tracking is turned on, Windows and its apps are allowed to detect the current location of your computer or device. ###
### This can be used to pinpoint your exact location, e.g. Map traces the location of PC and helps you in exploring nearby restaurants.
If (!(Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location")) {
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -Force | Out-Null
}
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -Name "Value" -Type String -Value "Deny" -Force
### Disable Wi-Fi Sense ###
### Wi-Fi Sense is a feature in Windows 10 that allows you to connect to your friends shared Wi-Fi connections. That is, you and your friends may opt to share your or their Wi-Fi connections. If your computer is logged into a Microsoft account, by default it will share your Wi-Fi password with your Skype, Outlook and Facebook friends, which means your Wi-Fi password will be sent to Microsoft. ###
### You should at least stop your PC from sending your Wi-Fi password.
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WcmSvc\wifinetworkmanager\config" -Name "AutoConnectAllowedOEM" -Type DWord -Value 0 -Force
### Disable Windows Hello Biometrics ###
### Windows Hello biometrics lets you sign in to your devices, apps, online services, and networks using your face, iris, or fingerprint. With this Policy you can disable the Windows Hello Biometrics.
If (!(Test-Path "HKLM:\Software\Policies\Microsoft\Biometrics")) {
New-Item -Path "HKLM:\Software\Policies\Microsoft\Biometrics" -Force | Out-Null
}
New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Biometrics" -Name "Enabled" -Type DWord -Value 0 -Force
### Turn off help Microsoft improve typing and writing ###
### When the Getting to know you privacy setting is turned on for inking & typing personalization in Windows 10, you can use your typing history and handwriting patterns to create a local user dictionary for you that is used to make better typing suggestions and improve handwriting recognition for each of the languages you use.
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\InputPersonalization" -Name "AllowInputPersonalization" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\InputPersonalization" -Name "RestrictImplicitInkCollection" -Type DWord -Value 1 -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\InputPersonalization" -Name "RestrictImplicitTextCollection" -Type DWord -Value 1 -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\HandwritingErrorReports" -Name "PreventHandwritingErrorReports" -Type DWord -Value 1 -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\TabletPC" -Name "PreventHandwritingDataSharing" -Type DWord -Value 1 -Force
### Block suggestions and automatic Installation of apps ###
### Microsoft flushes various apps into the system without being asked, especially games such as Candy Crush Saga. Users have to uninstall these manually if they don't want them on their computer. ###
### To prevent these downloads from starting in the first place, a small intervention in the registry helps. Suggested apps pinned to Start are basically just advertising. This script will also disable suggested apps (ex: Candy Crush Soda Saga) for all accounts.
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "ContentDeliveryAllowed" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "OemPreInstalledAppsEnabled" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "PreInstalledAppsEnabled" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "PreInstalledAppsEverEnabled" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "SilentInstalledAppsEnabled" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "SubscribedContent-338387Enabled" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "SubscribedContent-338388Enabled" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "SubscribedContent-338389Enabled" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "SubscribedContent-353698Enabled" -Type DWord -Value 0 -Force
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Name "SystemPaneSuggestionsEnabled" -Type DWord -Value 0 -Force
If (!(Test-Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent")) {
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Force | Out-Null}
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" -Name "DisableWindowsConsumerFeatures" -Type DWord -Value 1 -Force
### Turn off distributing updates to other computers ###
### Windows 10 lets you download updates from several sources to speed up the process of updating the operating system. ###
### If you don't want your files to be shared by others and exposing your IP address to random computers, you can apply this policy and turn this feature off. ###
### Acceptable selections include:
### Bypass (100)
### Group (2)
### HTTP only (0) Enabled by SharpApp!
### LAN (1)
### Simple (99)
If (!(Test-Path "HKLM:\Software\Policies\Microsoft\Windows\DeliveryOptimization")) {
New-Item -Path "HKLM:\Software\Policies\Microsoft\Windows\DeliveryOptimization" -Force | Out-Null
}
New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\DeliveryOptimization" -Name "DODownloadMode" -Type DWord -Value 0 -Force
# Description:
# This script removes unwanted Apps that come with Windows. If you do not want
# to remove certain Apps comment out the corresponding lines below.
Write-Output "Uninstalling default apps"
$apps = @(
# default Windows 10 apps
"Microsoft.3DBuilder"
"Microsoft.Appconnector"
"Microsoft.BingFinance"
"Microsoft.BingNews"
"Microsoft.BingSports"
"Microsoft.BingTranslator"
"Microsoft.GamingServices"
"Microsoft.MicrosoftPowerBIForWindows"
"Microsoft.MinecraftUWP"
"Microsoft.NetworkSpeedTest"
"Microsoft.Print3D"
#"Microsoft.Windows.Photos"
"Microsoft.WindowsPhone"
"Microsoft.CommsPhone"
"Microsoft.ConnectivityStore"
"Microsoft.Messaging"
"Microsoft.Office.Sway"
"Microsoft.OneConnect"
"Microsoft.BingFoodAndDrink"
"Microsoft.BingHealthAndFitness"
"Microsoft.BingTravel"
"Microsoft.WindowsReadingList"
# non-Microsoft
"2FE3CB00.PicsArt-PhotoStudio"
"46928bounde.EclipseManager"
"4DF9E0F8.Netflix"
"613EBCEA.PolarrPhotoEditorAcademicEdition"
"6Wunderkinder.Wunderlist"
"7EE7776C.LinkedInforWindows"
"89006A2E.AutodeskSketchBook"
"9E2F88E3.Twitter"
"A278AB0D.DisneyMagicKingdoms"
"A278AB0D.MarchofEmpires"
"ActiproSoftwareLLC.562882FEEB491" # next one is for the Code Writer from Actipro Software LLC
"CAF9E577.Plex"
"ClearChannelRadioDigital.iHeartRadio"
"D52A8D61.FarmVille2CountryEscape"
"D5EA27B7.Duolingo-LearnLanguagesforFree"
"DB6EA5DB.CyberLinkMediaSuiteEssentials"
"DolbyLaboratories.DolbyAccess"
"DolbyLaboratories.DolbyAccess"
"Drawboard.DrawboardPDF"
"Facebook.Facebook"
"Fitbit.FitbitCoach"
"Flipboard.Flipboard"
"GAMELOFTSA.Asphalt8Airborne"
"KeeperSecurityInc.Keeper"
"NORDCURRENT.COOKINGFEVER"
"PandoraMediaInc.29680B314EFC2"
"Playtika.CaesarsSlotsFreeCasino"
"ShazamEntertainmentLtd.Shazam"
"SlingTVLLC.SlingTV"
"SpotifyAB.SpotifyMusic"
"TheNewYorkTimes.NYTCrossword"
"ThumbmunkeysLtd.PhototasticCollage"
"TuneIn.TuneInRadio"
"WinZipComputing.WinZipUniversal"
"XINGAG.XING"
"flaregamesGmbH.RoyalRevolt2"
"king.com.*"
"king.com.BubbleWitch3Saga"
"king.com.CandyCrushSaga"
"king.com.CandyCrushSodaSaga"
"2FE3CB00.PicsArt-PhotoStudio"
"828B5831.HiddenCityMysteryofShadows"
"A278AB0D.MarchofEmpires"
"AdobeSystemsIncorporated.AdobePhotoshopExpress"
"AmazonVideo.PrimeVideo"
"Microsoft.Todos"
"Nordcurrent.CookingFever"
"PLRWorldwideSales.FishdomPlayrix"
"SpotifyAB.SpotifyMusic"
"ROBLOXCorporation.ROBLOX"
"Microsoft.Microsoft3DViewer"
#"Microsoft.WindowsCalculator"
#"Microsoft.WindowsStore" # can't be re-installed
"Microsoft.MSPaint"
"Microsoft.MicrosoftOfficeHub"
"Microsoft.MicrosoftSolitaireCollection"
"Microsoft.MicrosoftStickyNotes"
"Microsoft.Office.OneNote"
"Microsoft.People"
"Microsoft.SkypeApp"
"Microsoft.WindowsAlarms"
"Microsoft.WindowsCamera"
"microsoft.windowscommunicationsapps"
"Microsoft.WindowsMaps"
"Microsoft.WindowsSoundRecorder"
"Microsoft.Xbox.TCUI"
"Microsoft.XboxApp"
"Microsoft.XboxGameOverlay"
"Microsoft.XboxSpeechToTextOverlay"
"Microsoft.ZuneMusic"
"Microsoft.ZuneVideo"
"Microsoft.GetHelp"
"Microsoft.Getstarted"
"Microsoft.WindowsFeedbackHub"
"Microsoft.MixedReality.Portal"
"Microsoft.ScreenSketch"
"Microsoft.Wallet"
"Microsoft.Microsoft3DViewer"
"Microsoft.XboxGamingOverlay"
"Microsoft.YourPhone"
"Microsoft.BingWeather"
# apps which cannot be removed using Remove-AppxPackage
#"Microsoft.BioEnrollment"
#"Microsoft.MicrosoftEdge"
#"Microsoft.Windows.Cortana"
#"Microsoft.WindowsFeedback"
#"Microsoft.XboxGameCallableUI"
#"Microsoft.XboxIdentityProvider"
#"Windows.ContactSupport"
# apps which other apps depend on
"Microsoft.Advertising.Xaml"
)
foreach ($app in $apps) {
Write-Output "Trying to remove $app"
Get-AppXProvisionedPackage -Online |
Where-Object DisplayName -EQ $app |
Remove-AppxProvisionedPackage -Online
Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage -AllUsers
Get-AppxPackage $app | Remove-AppxPackage -AllUsers
}
# Prevents Apps from re-installing
$cdm = @(
"ContentDeliveryAllowed"
"FeatureManagementEnabled"
"OemPreInstalledAppsEnabled"
"PreInstalledAppsEnabled"
"PreInstalledAppsEverEnabled"
"SilentInstalledAppsEnabled"
"SubscribedContent-314559Enabled"
"SubscribedContent-338387Enabled"
"SubscribedContent-338388Enabled"
"SubscribedContent-338389Enabled"
"SubscribedContent-338393Enabled"
"SubscribedContentEnabled"
"SystemPaneSuggestionsEnabled"
)
foreach ($key in $cdm) {
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" $key 0
}
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\WindowsStore" "AutoDownload" 2
# Prevents "Suggested Applications" returning
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" "DisableWindowsConsumerFeatures" 1
# Description:
# This script disables unwanted Windows services. If you do not want to disable
# certain services comment out the corresponding lines below.
$services = @(
"diagnosticshub.standardcollector.service" # Microsoft (R) Diagnostics Hub Standard Collector Service
"DiagTrack" # Diagnostics Tracking Service
"dmwappushservice" # WAP Push Message Routing Service (see known issues)
"lfsvc" # Geolocation Service
"MapsBroker" # Downloaded Maps Manager
"NetTcpPortSharing" # Net.Tcp Port Sharing Service
"RemoteAccess" # Routing and Remote Access
"RemoteRegistry" # Remote Registry
"SharedAccess" # Internet Connection Sharing (ICS)
"TrkWks" # Distributed Link Tracking Client
"WbioSrvc" # Windows Biometric Service (required for Fingerprint reader / facial detection)
# "WlanSvc" # WLAN AutoConfig
"WMPNetworkSvc" # Windows Media Player Network Sharing Service
#"wscsvc" # Windows Security Center Service
"WSearch" # Windows Search
"XblAuthManager" # Xbox Live Auth Manager
"XblGameSave" # Xbox Live Game Save Service
"XboxNetApiSvc" # Xbox Live Networking Service
"ndu" # Windows Network Data Usage Monitor
# Services which cannot be disabled
#"WdNisSvc"
)
foreach ($service in $services) {
Write-Output "Trying to disable $service"
Get-Service -Name $service | Set-Service -StartupType Disabled
}
# Dogrywki dla Windows 10
function CortanaButton
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name AllowCortana -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name AllowCortana -Type CLEAR
if (-not (Get-AppxPackage -Name Microsoft.549981C3F5F10))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowCortanaButton -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowCortanaButton -PropertyType DWord -Value 1 -Force
}
}
}
CortanaButton -Hide
function TaskViewButton
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -PropertyType DWord -Value 1 -Force
}
}
}
TaskViewButton -Hide
function NewsInterests
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds" -Name EnableFeeds -Force -ErrorAction Ignore
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\PolicyManager\default\NewsAndInterests\AllowNewsAndInterests" -Name value -Force -ErrorAction Ignore
if (-not (Get-Package -Name "Microsoft Edge" -ProviderName Programs -ErrorAction Ignore))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
# We have to use GetValue() due to "Set-StrictMode -Version Latest"
$MachineId = [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SQMClient", "MachineId", $null)
if (-not $MachineId)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose
Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
# https://forums.mydigitallife.net/threads/taskbarda-widgets-registry-change-is-now-blocked.88547/#post-1849006
$Signature = @{
Namespace = "WinAPI"
Name = "Signature"
Language = "CSharp"
CompilerParameters = $CompilerParameters
MemberDefinition = @"
[DllImport("Shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = false)]
public static extern int HashData(byte[] pbData, int cbData, byte[] piet, int outputLen);
"@
}
if (-not ("WinAPI.Signature" -as [type]))
{
Add-Type @Signature
}
# We cannot set a value to EnShellFeedsTaskbarViewMode, having called any of APIs, except of copying powershell.exe (or any other tricks) with a different name, due to a UCPD driver tracks all executables to block the access to the registry
Copy-Item -Path "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" -Destination "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Force
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
# Combine variables into a string
$Combined = $MachineId + '_' + 2
# Reverse the whole string
$CharArray = $Combined.ToCharArray()
[array]::Reverse($CharArray)
$Reverse = -join $CharArray
$bytesIn = [System.Text.Encoding]::Unicode.GetBytes($Reverse)
$bytesOut = [byte[]]::new(4)
[WinAPI.Signature]::HashData($bytesIn, 0x53, $bytesOut, $bytesOut.Count)
# Get value to save in EnShellFeedsTaskbarViewMode key
$DWordData = [System.BitConverter]::ToUInt32($bytesOut,0)
& "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Command {New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Feeds -Name ShellFeedsTaskbarViewMode -PropertyType DWord -Value 2 -Force}
# We need to use here an approach with "-Command & {}" as there's a variable inside
& "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Command "& {New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Feeds -Name EnShellFeedsTaskbarViewMode -PropertyType DWord -Value $DWordData -Force}"
}
"Enable"
{
# Combine variables into a string
$Combined = $MachineId + '_' + 0
# Reverse the whole string
$CharArray = $Combined.ToCharArray()
[array]::Reverse($CharArray)
$Reverse = -join $CharArray
$bytesIn = [System.Text.Encoding]::Unicode.GetBytes($Reverse)
$bytesOut = [byte[]]::new(4)
[WinAPI.Signature]::HashData($bytesIn, 0x53, $bytesOut, $bytesOut.Count)
# Get value to save in EnShellFeedsTaskbarViewMode key
$DWordData = [System.BitConverter]::ToUInt32($bytesOut,0)
& "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Command {New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Feeds -Name ShellFeedsTaskbarViewMode -PropertyType DWord -Value 0 -Force}
# We need to use here an approach with "-Command & {}" as there's a variable inside
& "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Command "& {New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Feeds -Name EnShellFeedsTaskbarViewMode -PropertyType DWord -Value $DWordData -Force}"
}
}
Remove-Item -Path "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Force
}
NewsInterests -Disable
function PeopleTaskbar
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer, HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HidePeopleBar -Force -ErrorAction Ignore
Set-Policy -Scope User -Path Software\Policies\Microsoft\Windows\Explorer -Name HidePeopleBar -Type CLEAR
Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HidePeopleBar -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People -Force
}
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People -Name PeopleBand -PropertyType DWord -Value 0 -Force
}
"Show"
{
if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People -Force
}
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People -Name PeopleBand -PropertyType DWord -Value 1 -Force
}
}
}
PeopleTaskbar -Hide
function MeetNow
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name HideSCAMeetNow -Force -ErrorAction Ignore
Set-Policy -Scope User -Path Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name HideSCAMeetNow -Type CLEAR
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name HideSCAMeetNow -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
$Script:MeetNow = $false
$Settings = Get-ItemPropertyValue -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 -Name Settings -ErrorAction Ignore
$Settings[9] = 128
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 -Name Settings -PropertyType Binary -Value $Settings -Force
}
"Show"
{
$Script:MeetNow = $true
$Settings = Get-ItemPropertyValue -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 -Name Settings -ErrorAction Ignore
$Settings[9] = 0
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 -Name Settings -PropertyType Binary -Value $Settings -Force
}
}
}
MeetNow -Hide
function WindowsInkWorkspace
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\WindowsInkWorkspace -Name AllowWindowsInkWorkspace -Force -ErrorAction Ignore
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name HideSCAMeetNow -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\PenWorkspace -Name PenWorkspaceButtonDesiredVisibility -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\PenWorkspace -Name PenWorkspaceButtonDesiredVisibility -PropertyType DWord -Value 1 -Force
}
}
}
WindowsInkWorkspace -Hide
function NotificationAreaIcons
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show,
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide
)
# Remove all policies in order to make changes visible in UI only if it's possible
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name NoAutoTrayNotify -Force -ErrorAction Ignore
Set-Policy -Scope User -Path Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name NoAutoTrayNotify -Type CLEAR
Set-Policy -Scope Computer -Path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name NoAutoTrayNotify -Type CLEAR
switch ($PSCmdlet.ParameterSetName)
{
"Show"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer -Name EnableAutoTray -PropertyType DWord -Value 0 -Force
}
"Hide"
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer -Name EnableAutoTray -PropertyType DWord -Value 1 -Force
}
}
}
NotificationAreaIcons -Show
Write-Host "Usuniecie galerii"
REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{e88865ea-0e1c-4e20-9aa6-edcd0212c87c}" /f
REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{f874310e-b6b7-47dc-bc84-b9e6b38f5903}" /f
REG ADD "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /f /v "LaunchTo" /t REG_DWORD /d "1"
Write-Host "Usunięcie wszystkich przypietych skrotyow"
Remove-Item -Path "$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*" -Force -Recurse -ErrorAction SilentlyContinue
# Remove the Taskband Registry Key to delete taskbar data for recent apps
Remove-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item -Path "HKCU:\Software\Classes\CLSID\{e88865ea-0e1c-4e20-9aa6-edcd0212c87c}" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "HKCU:\Software\Classes\CLSID\{031E4825-7B94-4DC3-B131-E946B44C8DD5}" -Force -ErrorAction SilentlyContinue
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Feeds" /v EnableFeeds /t REG_DWORD /d 0 /f
# Usunięcie wszystkich przypiętych kafelków dla bieżącego użytkownika
Remove-Item "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\*" -Recurse -Force
# Usunięcie kafelków dla wszystkich użytkowników
Remove-Item "C:\Users\*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\*" -Recurse -Force
# Wyłącz rekomendacje w menu Start
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Start_IrisRecommendations /t REG_DWORD /d 0 /f
# Usuń przypięte aplikacje w menu Start (Windows 11)
$startLayout = @"
{
"pinnedList": []
}
"@
# Zapisz pusty układ Start
$startLayout | Set-Content -Path "$env:LOCALAPPDATA\Microsoft\Windows\Shell\Layouts\layoutModification.json"
# Wyłącz uśpienie na zasilaniu sieciowym
powercfg /change standby-timeout-ac 0
# Wyłącz uśpienie na baterii (dla laptopów)
powercfg /change standby-timeout-dc 0
# Wyłącz wygaszanie ekranu na zasilaniu sieciowym
powercfg /change monitor-timeout-ac 0
# Wyłącz wygaszanie ekranu na baterii (dla laptopów)
powercfg /change monitor-timeout-dc 0
Stop-Process -ProcessName explorer -Force
Start-Process explorer