Script to setup Windows 10 1903
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

8546 lines
210 KiB

<#
.SYNOPSIS
"Windows 10 Sophia Script" (LTSC version) is a PowerShell module for Windows 10 fine-tuning and automating the routine tasks
Version: v5.0.4
Date: 20.02.2021
Copyright (c) 2015–2021 farag & oZ-Zo
https://github.com/farag2
https://github.com/oz-zo
Thanks to all https://forum.ru-board.com members involved
.DESCRIPTION
Running the script is best done on a fresh install because running it on wrong tweaked system may result in errors occurring
.NOTES
https://forum.ru-board.com/topic.cgi?forum=62&topic=30617#15
https://habr.com/post/521202/
https://forums.mydigitallife.net/threads/powershell-windows-10-sophia-script.81675/
https://www.reddit.com/r/PowerShell/comments/go2n5v/powershell_script_setup_windows_10/
.NOTES
Supported Windows 10
Version: 1809
Build: 17763
Edition: Enterprise LTSC
Architecture: x64
.NOTES
Set execution policy to be able to run scripts only in the current PowerShell session:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
.LINK
https://github.com/farag2/Windows-10-Sophia-Script
#>
#region Checkings
function Checkings
{
Set-StrictMode -Version Latest
# Сlear the $Error variable
$Global:Error.Clear()
# Detect the OS bitness
switch ([System.Environment]::Is64BitOperatingSystem)
{
$false
{
Write-Warning -Message $Localization.UnsupportedOSBitness
exit
}
}
# Detect the OS build version
switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber -eq 17763)
{
$false
{
Write-Warning -Message $Localization.UnsupportedOSBuild
exit
}
}
# Checking whether the current module version is the latest
try
{
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/farag2/Windows-10-Sophia-Script/master/Sophia/LTSC/Sophia.psd1" -OutFile $DownloadsFolder\Manifest.psd1 -UseBasicParsing
$LatestRelease = (Import-PowerShellDataFile -Path $DownloadsFolder\Manifest.psd1).ModuleVersion
$CurrentRelease = (Get-Module -Name Sophia).Version.ToString()
Remove-Item -Path $DownloadsFolder\Manifest.psd1 -Force
switch ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease)
{
$true
{
Write-Warning -Message $Localization.UnsupportedRelease
Start-Sleep -Seconds 5
Start-Process -FilePath "https://github.com/farag2/Windows-10-Sophia-Script/releases/latest"
exit
}
}
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
# Unblock all files in the folder by removing the Zone.Identifier alternate data stream with a value of "3"
Get-ChildItem -Path $PSScriptRoot -Recurse -Force | Unblock-File -Confirm:$false
# Turn off Controlled folder access to let the script proceed
switch ((Get-MpPreference).EnableControlledFolderAccess)
{
"1"
{
Write-Warning -Message $Localization.ControlledFolderAccessDisabled
$Script:ControlledFolderAccess = $true
Set-MpPreference -EnableControlledFolderAccess Disabled
# Open "Ransomware protection" page
Start-Process -FilePath windowsdefender://RansomwareProtection
}
"0"
{
$Script:ControlledFolderAccess = $false
}
}
}
#endregion Checkings
# Enable script logging. The log will be being recorded into the script folder
# To stop logging just close the console or type "Stop-Transcript"
function Logging
{
$TrascriptFilename = "Log-$((Get-Date).ToString("dd.MM.yyyy-HH-mm"))"
Start-Transcript -Path $PSScriptRoot\$TrascriptFilename.txt -Force
}
# Create a restore point for the system drive
function CreateRestorePoint
{
$SystemDriveUniqueID = (Get-Volume | Where-Object {$_.DriveLetter -eq "$($env:SystemDrive[0])"}).UniqueID
$SystemProtection = ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SPP\Clients")."{09F7EDC5-294E-4180-AF6A-FB0E6A0E9513}") | Where-Object -FilterScript {$_ -match [regex]::Escape($SystemDriveUniqueID)}
$ComputerRestorePoint = $false
switch ($null -eq $SystemProtection)
{
$true
{
$ComputerRestorePoint = $true
Enable-ComputerRestore -Drive $env:SystemDrive
}
}
# Never skip creating a restore point
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -PropertyType DWord -Value 0 -Force
Checkpoint-Computer -Description "Windows 10 Sophia Script" -RestorePointType MODIFY_SETTINGS
# Revert the System Restore checkpoint creation frequency to 1440 minutes
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -PropertyType DWord -Value 1440 -Force
# Turn off System Protection for the system drive if it was turned off without deleting existing restore points
if ($ComputerRestorePoint)
{
Disable-ComputerRestore -Drive $env:SystemDrive
}
}
#region Privacy & Telemetry
<#
.SYNOPSIS
Configure the DiagTrack service, firewall rule for Unified Telemetry Client Outbound Traffic and block connection
.PARAMETER Disable
Disable the DiagTrack service, firewall rule for Unified Telemetry Client Outbound Traffic and block connection
.PARAMETER Enable
Enable the DiagTrack service, firewall rule for Unified Telemetry Client Outbound Traffic and allow connection
.EXAMPLE
DiagTrackService -Disable
.EXAMPLE
DiagTrackService -Enable
.NOTES
Current user
#>
function DiagTrackService
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
Get-Service -Name DiagTrack | Set-Service -StartupType Automatic
Get-Service -Name DiagTrack | Start-Service
# Enable firewall rule for Unified Telemetry Client Outbound Traffic and allow connection
Get-NetFirewallRule -Group DiagTrack | Set-NetFirewallRule -Enabled True -Action Allow
}
"Disable"
{
Get-Service -Name DiagTrack | Stop-Service -Force
Get-Service -Name DiagTrack | Set-Service -StartupType Disabled
# Disable firewall rule for Unified Telemetry Client Outbound Traffic and block connection
Get-NetFirewallRule -Group DiagTrack | Set-NetFirewallRule -Enabled False -Action Block
}
}
}
<#
.SYNOPSIS
Configure the OS level of diagnostic data gathering
.PARAMETER Minimal
Set the OS level of diagnostic data gathering to minimum
.PARAMETER Default
Set the OS level of diagnostic data gathering to minimum
.EXAMPLE
DiagnosticDataLevel -Minimal
.EXAMPLE
DiagnosticDataLevel -Default
.NOTES
Machine-wide
#>
function DiagnosticDataLevel
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Minimal"
)]
[switch]
$Minimal,
[Parameter(
Mandatory = $true,
ParameterSetName = "Default"
)]
[switch]
$Default
)
switch ($PSCmdlet.ParameterSetName)
{
"Minimal"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 0 -Force
}
"Default"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 3 -Force
}
}
}
<#
.SYNOPSIS
Configure the Windows Error Reporting
.PARAMETER Disable
Turn off Windows Error Reporting
.PARAMETER Enable
Turn on Windows Error Reporting
.EXAMPLE
ErrorReporting -Disable
.EXAMPLE
ErrorReporting -Enable
.NOTES
Current user
#>
function ErrorReporting
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if ((Get-WindowsEdition -Online).Edition -notmatch "Core*")
{
Get-ScheduledTask -TaskName QueueReporting | Disable-ScheduledTask
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name Disabled -PropertyType DWord -Value 1 -Force
}
}
"Enable"
{
Get-ScheduledTask -TaskName QueueReporting | Enable-ScheduledTask
Remove-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the Windows feedback frequency
.PARAMETER Disable
Change Windows feedback frequency to "Never"
.PARAMETER Enable
Change Windows feedback frequency to "Automatically"
.EXAMPLE
WindowsFeedback -Disable
.EXAMPLE
WindowsFeedback -Enable
.NOTES
Current user
#>
function WindowsFeedback
{
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\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
}
"Enable"
{
Remove-Item -Path HKCU:\SOFTWARE\Microsoft\Siuf\Rules -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the diagnostics tracking scheduled tasks
.PARAMETER Disable
Turn off the diagnostics tracking scheduled tasks
.PARAMETER Enable
Turn on the diagnostics tracking scheduled tasks
.EXAMPLE
ScheduledTasks -Disable
.EXAMPLE
ScheduledTasks -Enable
.NOTES
A pop-up dialog box enables the user to select tasks
Current user
#>
function ScheduledTasks
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
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
# Сбор телеметрических данных программы при участии в программе улучшения качества ПО
"ProgramDataUpdater",
# This task collects and uploads autochk SQM data if opted-in to the Microsoft Customer Experience Improvement Program
# Эта задача собирает и загружает данные SQM при участии в программе улучшения качества программного обеспечения
"Proxy",
# If the user has consented to participate in the Windows Customer Experience Improvement Program, this job collects and sends usage data to Microsoft
# Если пользователь изъявил желание участвовать в программе по улучшению качества программного обеспечения Windows, эта задача будет собирать и отправлять сведения о работе программного обеспечения в Майкрософт
"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
# При выполнении задачи программы улучшения качества ПО шины USB (USB CEIP) осуществляется сбор статистических данных об использовании универсальной последовательной шины USB и с ведений о компьютере, которые направляются инженерной группе Майкрософт по вопросам подключения устройств в Windows
"UsbCeip",
# The Windows Disk Diagnostic reports general disk and system information to Microsoft for users participating in the Customer Experience Program
# Для пользователей, участвующих в программе контроля качества программного обеспечения, служба диагностики дисков Windows предоставляет общие сведения о дисках и системе в корпорацию Майкрософт
"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"
)
# Check if device has a camera
$DeviceHasCamera = Get-CimInstance -ClassName Win32_PnPEntity | Where-Object -FilterScript {($_.PNPClass -eq "Camera") -or ($_.PNPClass -eq "Image")}
if (-not $DeviceHasCamera)
{
# Windows Hello
$CheckedScheduledTasks += "FODCleanupTask"
}
#endregion Variables
#region XAML Markup
# The section defines the design of the upcoming dialog box
[xml]$XAML = '
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="Window"
MinHeight="450" MinWidth="400"
SizeToContent="Width" WindowStartupLocation="CenterScreen"
TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True"
FontFamily="Segoe UI" FontSize="12" ShowInTaskbar="False">
<Window.Resources>
<Style TargetType="StackPanel">
<Setter Property="Orientation" Value="Horizontal"/>
</Style>
<Style TargetType="CheckBox">
<Setter Property="Margin" Value="10, 10, 5, 10"/>
<Setter Property="IsChecked" Value="True"/>
</Style>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="5, 10, 10, 10"/>
</Style>
<Style TargetType="Button">
<Setter Property="Margin" Value="20"/>
<Setter Property="Padding" Value="10"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollViewer Name="Scroll" Grid.Row="0"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<StackPanel Name="PanelContainer" Orientation="Vertical"/>
</ScrollViewer>
<Button Name="Button" Grid.Row="1"/>
</Grid>
</Window>
'
#endregion XAML Markup
$Reader = (New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)
$Form = [Windows.Markup.XamlReader]::Load($Reader)
$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-Verbose -Message $Localization.Patient -Verbose
[void]$Window.Close()
$SelectedTasks | ForEach-Object -Process {Write-Verbose $_.TaskName -Verbose}
$SelectedTasks | Disable-ScheduledTask
}
function EnableButton
{
Write-Verbose -Message $Localization.Patient -Verbose
[void]$Window.Close()
$SelectedTasks | ForEach-Object -Process {Write-Verbose $_.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"
$ButtonContent = $Localization.Enable
$ButtonAdd_Click = {EnableButton}
}
"Disable"
{
$State = "Ready"
$ButtonContent = $Localization.Disable
$ButtonAdd_Click = {DisableButton}
}
}
Write-Verbose -Message $Localization.Patient -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-Verbose -Message $Localization.NoData -Verbose
return
}
Write-Verbose -Message $Localization.DialogBoxOpening -Verbose
$Window.Add_Loaded({$Tasks | Add-TaskControl})
$Button.Content = $ButtonContent
$Button.Add_Click({& $ButtonAdd_Click})
$Window.Title = $Localization.ScheduledTasks
$Form.ShowDialog() | Out-Null
}
<#
.SYNOPSIS
Configure the sign-in info to automatically finish setting up device and reopen apps after an update or restart
.PARAMETER Disable
Do not use sign-in info to automatically finish setting up device and reopen apps after an update or restart
.PARAMETER Enable
Use sign-in info to automatically finish setting up device and reopen apps after an update or restart
.EXAMPLE
SigninInfo -Disable
.EXAMPLE
SigninInfo -Enable
.NOTES
Current user
#>
function SigninInfo
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
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 SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the provision to websites of locally relevant content by accessing language list
.PARAMETER Disable
Do not let websites provide locally relevant content by accessing language list
.PARAMETER Enable
Let websites provide locally relevant content by accessing language list
.EXAMPLE
LanguageListAccess -Disable
.EXAMPLE
LanguageListAccess -Enable
.NOTES
Current user
#>
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 SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the permission for apps to use advertising ID
.PARAMETER Disable
Do not allow apps to use advertising ID
.PARAMETER Enable
Do not allow apps to use advertising ID
.EXAMPLE
AdvertisingID -Disable
.EXAMPLE
AdvertisingID -Enable
.NOTES
Current user
#>
function AdvertisingID
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if (-not (Test-Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo))
{
New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Force
}
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
}
}
}
<#
.SYNOPSIS
Configure the permission for apps on other devices open and message apps on this device, and vice versa
.PARAMETER Disable
Do not let apps on other devices open and message apps on this device, and vice versa
.PARAMETER Enable
Let apps on other devices open and message apps on this device, and vice versa
.EXAMPLE
ShareAcrossDevices -Disable
.EXAMPLE
ShareAcrossDevices -Enable
.NOTES
Current user
#>
function ShareAcrossDevices
{
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\CDP -Name RomeSdkChannelUserAuthzPolicy -PropertyType DWord -Value 1 -Force
}
"Disable"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\CDP -Name RomeSdkChannelUserAuthzPolicy -PropertyType DWord -Value 0 -Force
}
}
}
#endregion Privacy & Telemetry
#region UI & Personalization
<#
.SYNOPSIS
Configure the "This PC" icon on Desktop
.PARAMETER Hide
Show the "This PC" icon on Desktop
.PARAMETER Show
Hide the "This PC" icon on Desktop
.EXAMPLE
ThisPC -Hide
.EXAMPLE
ThisPC -Show
.NOTES
Current user
#>
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 SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure check boxes to select items
.PARAMETER Disable
Do not use check boxes to select items
.PARAMETER Enable
Use check boxes to select items
.EXAMPLE
CheckBoxes -Disable
.EXAMPLE
CheckBoxes -Enable
.NOTES
Current user
#>
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
}
}
}
<#
.SYNOPSIS
Configure the display of hidden files, folders, and drives
.PARAMETER Enable
Show hidden files, folders, and drives
.PARAMETER Disable
Do not show hidden files, folders, and drives
.EXAMPLE
HiddenItems -Enable
.EXAMPLE
HiddenItems -Disable
.NOTES
Current user
#>
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
}
}
}
<#
.SYNOPSIS
Configure the display of file name extensions
.PARAMETER Show
Show file name extensions
.PARAMETER Hide
Hide file name extensions
.EXAMPLE
FileExtensions -Show
.EXAMPLE
FileExtensions -Hide
.NOTES
Current user
#>
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
}
}
}
<#
.SYNOPSIS
Configure folder merge conflicts
.PARAMETER Show
Show folder merge conflicts
.PARAMETER Hide
Hide folder merge conflicts
.EXAMPLE
MergeConflicts -Show
.EXAMPLE
MergeConflicts -Hide
.NOTES
Current user
#>
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 1 -Force
}
"Hide"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideMergeConflicts -PropertyType DWord -Value 0 -Force
}
}
}
<#
.SYNOPSIS
Configure how to open File Explorer
.PARAMETER ThisPC
Open File Explorer to "This PC"
.PARAMETER QuickAccess
Open File Explorer to "Quick access"
.EXAMPLE
OpenFileExplorerTo -ThisPC
.EXAMPLE
OpenFileExplorerTo -QuickAccess
.NOTES
Current user
#>
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
}
}
}
<#
.SYNOPSIS
Hide Task View button on the taskbar
.PARAMETER Hide
Show Task View button on the taskbar
.PARAMETER Show
Do not show Task View button on the taskbar
.EXAMPLE
TaskViewButton -Hide
.EXAMPLE
TaskViewButton -Show
.NOTES
Current user
#>
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
}
}
}
<#
.SYNOPSIS
Configure People button on the taskbar
.PARAMETER Hide
Hide People button on the taskbar
.PARAMETER Show
Show People button on the taskbar
.EXAMPLE
PeopleTaskbar -Hide
.EXAMPLE
PeopleTaskbar -Show
.NOTES
Current user
#>
function PeopleTaskbar
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-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 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
}
}
}
<#
.SYNOPSIS
Configure seconds on the taskbar clock
.PARAMETER Hide
Hide seconds on the taskbar clock
.PARAMETER Show
Show seconds on the taskbar clock
.EXAMPLE
SecondsInSystemClock -Hide
.EXAMPLE
SecondsInSystemClock -Show
.NOTES
Current user
#>
function SecondsInSystemClock
{
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 ShowSecondsInSystemClock -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowSecondsInSystemClock -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure windows snapping
.PARAMETER Disable
When I snap a window, do not show what I can snap next to it
.PARAMETER Enable
When I snap a window, show what I can snap next to it
.EXAMPLE
SnapAssist -Disable
.EXAMPLE
SnapAssist -Enable
.NOTES
Current user
#>
function SnapAssist
{
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 SnapAssist -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name SnapAssist -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure the file transfer dialog box
.PARAMETER Detailed
Always open the file transfer dialog box in the detailed mode
.PARAMETER Compact
Always open the file transfer dialog box in the compact mode
.EXAMPLE
FileTransferDialog -Detailed
.EXAMPLE
FileTransferDialog -Compact
.NOTES
Current user
#>
function FileTransferDialog
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Detailed"
)]
[switch]
$Detailed,
[Parameter(
Mandatory = $true,
ParameterSetName = "Compact"
)]
[switch]
$Compact
)
switch ($PSCmdlet.ParameterSetName)
{
"Detailed"
{
if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager))
{
New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager -Force
}
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager -Name EnthusiastMode -PropertyType DWord -Value 1 -Force
}
"Compact"
{
if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager))
{
New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager -Force
}
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager -Name EnthusiastMode -PropertyType DWord -Value 0 -Force
}
}
}
<#
.SYNOPSIS
Configure the File Explorer ribbon
.PARAMETER Expanded
Expand the File Explorer ribbon
.PARAMETER Minimized
Minimize the File Explorer ribbon
.EXAMPLE
FileExplorerRibbon -Expanded
.EXAMPLE
FileExplorerRibbon -Minimized
.NOTES
Current user
#>
function FileExplorerRibbon
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Expanded"
)]
[switch]
$Expanded,
[Parameter(
Mandatory = $true,
ParameterSetName = "Minimized"
)]
[switch]
$Minimized
)
switch ($PSCmdlet.ParameterSetName)
{
"Expanded"
{
if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Ribbon))
{
New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Ribbon -Force
}
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Ribbon -Name MinimizedStateTabletModeOff -PropertyType DWord -Value 0 -Force
}
"Minimized"
{
if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Ribbon))
{
New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Ribbon -Force
}
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Ribbon -Name MinimizedStateTabletModeOff -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure the recycle bin files delete confirmation
.PARAMETER Disable
Display/do not display the recycle bin files delete confirmation
.PARAMETER Enable
Display/do not display the recycle bin files delete confirmation
.EXAMPLE
RecycleBinDeleteConfirmation -Disable
.EXAMPLE
RecycleBinDeleteConfirmation -Enable
.NOTES
Current user
#>
function RecycleBinDeleteConfirmation
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
$UpdateDesktop = @{
Namespace = "WinAPI"
Name = "UpdateDesktop"
Language = "CSharp"
MemberDefinition = @"
private static readonly IntPtr hWnd = new IntPtr(65535);
private const int Msg = 273;
// Virtual key ID of the F5 in File Explorer
private static readonly UIntPtr UIntPtr = new UIntPtr(41504);
[DllImport("user32.dll", SetLastError=true)]
public static extern int PostMessageW(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
public static void PostMessage()
{
// F5 pressing simulation to refresh the desktop
PostMessageW(hWnd, Msg, UIntPtr, IntPtr.Zero);
}
"@
}
if (-not ("WinAPI.UpdateDesktop" -as [type]))
{
Add-Type @UpdateDesktop
}
$ShellState = Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name ShellState
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
$ShellState[4] = 55
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name ShellState -PropertyType Binary -Value $ShellState -Force
}
"Enable"
{
$ShellState[4] = 51
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name ShellState -PropertyType Binary -Value $ShellState -Force
}
}
# Send F5 pressing simulation to refresh the desktop
[WinAPI.UpdateDesktop]::PostMessage()
}
<#
.SYNOPSIS
Configure the "3D Objects" folder in "This PC" and "Quick access"
.PARAMETER Show
Show the "3D Objects" folder in "This PC" and "Quick access"
.PARAMETER Hide
Hide the "3D Objects" folder in "This PC" and "Quick access"
.EXAMPLE
3DObjects -Show
.EXAMPLE
3DObjects -Hide
.NOTES
Current user
#>
function 3DObjects
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show,
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{31C0DD25-9439-4F12-BF41-7FF4EDA38722}\PropertyBag"))
{
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{31C0DD25-9439-4F12-BF41-7FF4EDA38722}\PropertyBag" -Force
}
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{31C0DD25-9439-4F12-BF41-7FF4EDA38722}\PropertyBag" -Name ThisPCPolicy -PropertyType String -Value Hide -Force
}
"Show"
{
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{31C0DD25-9439-4F12-BF41-7FF4EDA38722}\PropertyBag" -Name ThisPCPolicy -Force -ErrorAction SilentlyContinue
}
}
# Save all opened folders in order to restore them after File Explorer restart
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke()
# In order for the changes to take effect the File Explorer process has to be restarted
Stop-Process -Name explorer -Force
# Restoring closed folders
foreach ($OpenedFolder in $OpenedFolders)
{
if (Test-Path -Path $OpenedFolder)
{
Invoke-Item -Path $OpenedFolder
}
}
}
<#
.SYNOPSIS
Configure frequently used folders in "Quick access"
.PARAMETER Show
Show frequently used folders in "Quick access"
.PARAMETER Hide
Hide frequently used folders in "Quick access"
.EXAMPLE
QuickAccessFrequentFolders -Show
.EXAMPLE
QuickAccessFrequentFolders -Hide
.NOTES
Current user
#>
function QuickAccessFrequentFolders
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show,
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide
)
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
}
}
}
<#
.SYNOPSIS
Configure recently used files in Quick access
.PARAMETER Show
Show recently used files in Quick access
.PARAMETER Hide
Hide recently used files in Quick access
.EXAMPLE
QuickAccessRecentFiles -Show
.EXAMPLE
QuickAccessRecentFiles -Hide
.NOTES
Current user
#>
function QuickAccessRecentFiles
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show,
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide
)
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
}
}
}
<#
.SYNOPSIS
Configure search on the taskbar
.PARAMETER SearchBox
Show the search box on the taskbar
.PARAMETER SearchIcon
Show the search icon on the taskbar
.PARAMETER Hide
Hide the search on the taskbar
.EXAMPLE
TaskbarSearch -SearchBox
.EXAMPLE
TaskbarSearch -SearchIcon
.EXAMPLE
TaskbarSearch -Hide
.NOTES
Current user
#>
function TaskbarSearch
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "ShowIcon"
)]
[switch]
$SearchIcon,
[Parameter(
Mandatory = $true,
ParameterSetName = "SearchBox"
)]
[switch]
$SearchBox
)
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
}
"SearchBox"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -PropertyType DWord -Value 2 -Force
}
}
}
<#
.SYNOPSIS
Configure icons in the notification area
.PARAMETER Show
Always show all icons in the notification area
.PARAMETER Hide
Hide all icons in the notification area
.EXAMPLE
TrayIcons -Show
.EXAMPLE
TrayIcons -Hide
.NOTES
Current user
#>
function TrayIcons
{
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 EnableAutoTray -PropertyType DWord -Value 1 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name EnableAutoTray -PropertyType DWord -Value 0 -Force
}
}
}
<#
.SYNOPSIS
Configure the Control Panel icons view
.PARAMETER Category
View the Control Panel icons by: category
.PARAMETER LargeIcons
View the Control Panel icons by: large icons
.PARAMETER SmallIcons
View the Control Panel icons by: Small icons
.EXAMPLE
ControlPanelView -Category
.EXAMPLE
ControlPanelView -LargeIcons
.EXAMPLE
ControlPanelView -SmallIcons
.NOTES
Current user
#>
function ControlPanelView
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Category"
)]
[switch]
$Category,
[Parameter(
Mandatory = $true,
ParameterSetName = "LargeIcons"
)]
[switch]
$LargeIcons,
[Parameter(
Mandatory = $true,
ParameterSetName = "SmallIcons"
)]
[switch]
$SmallIcons
)
switch ($PSCmdlet.ParameterSetName)
{
"Category"
{
if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel))
{
New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Force
}
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"
{
if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel))
{
New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Force
}
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"
{
if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel))
{
New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel -Force
}
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
}
}
}
<#
.SYNOPSIS
Configure the Windows mode color scheme
.PARAMETER Light
Set the Windows mode color scheme to the light
.PARAMETER Dark
Set the Windows mode color scheme to the dark
.EXAMPLE
WindowsColorScheme -Light
.EXAMPLE
WindowsColorScheme -Dark
.NOTES
Current user
#>
function WindowsColorScheme
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Light"
)]
[switch]
$Light,
[Parameter(
Mandatory = $true,
ParameterSetName = "Dark"
)]
[switch]
$Dark
)
switch ($PSCmdlet.ParameterSetName)
{
"Light"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -PropertyType DWord -Value 1 -Force
}
"Dark"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -PropertyType DWord -Value 0 -Force
}
}
}
<#
.SYNOPSIS
Configure the default app mode color scheme
.PARAMETER Light
Set the default app mode color scheme to the light
.PARAMETER Dark
Set the default app mode color scheme to the dark
.EXAMPLE
AppMode -Light
.EXAMPLE
AppMode -Dark
.NOTES
Current user
#>
function AppMode
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Light"
)]
[switch]
$Light,
[Parameter(
Mandatory = $true,
ParameterSetName = "Dark"
)]
[switch]
$Dark
)
switch ($PSCmdlet.ParameterSetName)
{
"Light"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -PropertyType DWord -Value 1 -Force
}
"Dark"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -PropertyType DWord -Value 0 -Force
}
}
}
<#
.SYNOPSIS
Configure the "New App Installed" indicator
.PARAMETER Hide
Hide the "New App Installed" indicator
.PARAMETER Show
Show the "New App Installed" indicator
.EXAMPLE
NewAppInstalledNotification -Hide
.EXAMPLE
NewAppInstalledNotification -Show
.NOTES
Current user
#>
function NewAppInstalledNotification
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer))
{
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Force
}
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoNewAppAlert -PropertyType DWord -Value 1 -Force
}
"Show"
{
if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer))
{
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Force
}
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoNewAppAlert -PropertyType DWord -Value 0 -Force
}
}
}
<#
.SYNOPSIS
Configure first sign-in animation after the upgrade
.PARAMETER Hide
Hide first sign-in animation after the upgrade
.PARAMETER Show
Show first sign-in animation after the upgrade
.EXAMPLE
FirstLogonAnimation -Disable
.EXAMPLE
FirstLogonAnimation -Enable
.NOTES
Current user
#>
function FirstLogonAnimation
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableFirstLogonAnimation -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableFirstLogonAnimation -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure the quality factor of the JPEG desktop wallpapers
.PARAMETER Max
Set the quality factor of the JPEG desktop wallpapers to maximum
.PARAMETER Default
Set the quality factor of the JPEG desktop wallpapers to default
.EXAMPLE
JPEGWallpapersQuality -Max
.EXAMPLE
JPEGWallpapersQuality -Default
.NOTES
Current user
#>
function JPEGWallpapersQuality
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Max"
)]
[switch]
$Max,
[Parameter(
Mandatory = $true,
ParameterSetName = "Default"
)]
[switch]
$Default
)
switch ($PSCmdlet.ParameterSetName)
{
"Max"
{
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name JPEGImportQuality -PropertyType DWord -Value 100 -Force
}
"Default"
{
Remove-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name JPEGImportQuality -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the Task Manager mode
.PARAMETER Expanded
Start Task Manager in the expanded mode
.PARAMETER Compact
Start Task Manager in the compact mode
.EXAMPLE
TaskManagerWindow -Expanded
.EXAMPLE
TaskManagerWindow -Compact
.NOTES
Current user
#>
function TaskManagerWindow
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Expanded"
)]
[switch]
$Expanded,
[Parameter(
Mandatory = $true,
ParameterSetName = "Compact"
)]
[switch]
$Compact
)
$Taskmgr = Get-Process -Name Taskmgr -ErrorAction Ignore
Start-Sleep -Seconds 1
if ($Taskmgr)
{
$Taskmgr.CloseMainWindow()
}
Start-Process -FilePath Taskmgr.exe -PassThru
Start-Sleep -Seconds 3
do
{
Start-Sleep -Milliseconds 100
$Preferences = Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\TaskManager -Name Preferences
}
until ($Preferences)
Stop-Process -Name Taskmgr -ErrorAction Ignore
switch ($PSCmdlet.ParameterSetName)
{
"Expanded"
{
$Preferences[28] = 0
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\TaskManager -Name Preferences -PropertyType Binary -Value $Preferences -Force
}
"Compact"
{
$Preferences[28] = 1
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\TaskManager -Name Preferences -PropertyType Binary -Value $Preferences -Force
}
}
}
<#
.SYNOPSIS
Configure a notification when your PC requires a restart to finish updating
.PARAMETER Hide
Hide a notification when your PC requires a restart to finish updating
.PARAMETER Show
Show a notification when your PC requires a restart to finish updating
.EXAMPLE
RestartNotification -Hide
.EXAMPLE
RestartNotification -Show
.NOTES
Current user
#>
function RestartNotification
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name RestartNotificationsAllowed2 -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name RestartNotificationsAllowed2 -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure the "- Shortcut" suffix adding to the name of the created shortcuts
.PARAMETER Disable
Do not add the "- Shortcut" suffix to the file name of created shortcuts
.PARAMETER Enable
Add the "- Shortcut" suffix to the file name of created shortcuts
.EXAMPLE
ShortcutsSuffix -Disable
.EXAMPLE
ShortcutsSuffix -Enable
.NOTES
Current user
#>
function ShortcutsSuffix
{
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\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 SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the PrtScn button usage
.PARAMETER Disable
Use the PrtScn button to open screen snipping
.PARAMETER Enable
Do not use the PrtScn button to open screen snipping
.EXAMPLE
PrtScnSnippingTool -Disable
.EXAMPLE
PrtScnSnippingTool -Enable
.NOTES
Current user
#>
function PrtScnSnippingTool
{
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\Keyboard" -Name PrintScreenKeyForSnippingEnabled -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path "HKCU:\Control Panel\Keyboard" -Name PrintScreenKeyForSnippingEnabled -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure an input method for each app window
.PARAMETER Enable
Let use a different input method for each app window
.PARAMETER Disable
Do not let use a different input method for each app window
.EXAMPLE
AppsLanguageSwitch -Disable
.EXAMPLE
AppsLanguageSwitch -Enable
.NOTES
Current user
#>
function AppsLanguageSwitch
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
Set-WinLanguageBarOption -UseLegacySwitchMode
}
"Disable"
{
Set-WinLanguageBarOption
}
}
}
#endregion UI & Personalization
#region System
#region StorageSense
<#
.SYNOPSIS
Configure Storage Sense
.PARAMETER Disable
Turn off Storage Sense
.PARAMETER Enable
Turn on off Storage Sense
.EXAMPLE
StorageSense -Disable
.EXAMPLE
StorageSense -Enable
.NOTES
Current user
#>
function StorageSense
{
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\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy))
{
New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -ItemType Directory -Force
}
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01 -PropertyType DWord -Value 0 -Force
}
"Enable"
{
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
}
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01 -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure Storage Sense running
.PARAMETER Disable
Run Storage Sense every month/during low free disk space
.PARAMETER Enable
Run Storage Sense every month/during low free disk space
.EXAMPLE
StorageSenseFrequency -Month
.EXAMPLE
StorageSenseFrequency -Default
.NOTES
Current user
#>
function StorageSenseFrequency
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Month"
)]
[switch]
$Month,
[Parameter(
Mandatory = $true,
ParameterSetName = "Default"
)]
[switch]
$Default
)
switch ($PSCmdlet.ParameterSetName)
{
"Month"
{
if ((Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01) -eq "1")
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 2048 -PropertyType DWord -Value 30 -Force
}
}
"Default"
{
if ((Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01) -eq "1")
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 2048 -PropertyType DWord -Value 0 -Force
}
}
}
}
<#
.SYNOPSIS
Configure temporary files deletion
.PARAMETER Enable
Delete temporary files that apps aren't using
.PARAMETER Disable
Do not delete temporary files that apps aren't using
.EXAMPLE
StorageSenseTempFiles -Enable
.EXAMPLE
StorageSenseTempFiles -Disable
.NOTES
Current user
#>
function StorageSenseTempFiles
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
if ((Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01) -eq "1")
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 04 -PropertyType DWord -Value 1 -Force
}
}
"Disable"
{
if ((Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01) -eq "1")
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 04 -PropertyType DWord -Value 0 -Force
}
}
}
}
<#
.SYNOPSIS
Configure files in recycle bin deletion
.PARAMETER Disable
Delete files in recycle bin if they have been there for over 30 days
.PARAMETER Enable
Do not delete files in recycle bin if they have been there for over 30 days
.EXAMPLE
StorageSenseRecycleBin -Enable
.EXAMPLE
StorageSenseRecycleBin -Disable
.NOTES
Current user
#>
function StorageSenseRecycleBin
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
if ((Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01) -eq "1")
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 08 -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 256 -PropertyType DWord -Value 30 -Force
}
}
"Disable"
{
if ((Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 01) -eq "1")
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 08 -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy -Name 256 -PropertyType DWord -Value 0 -Force
}
}
}
}
#endregion StorageSense
<#
.SYNOPSIS
Configure hibernation
.PARAMETER Disable
Disable hibernation
.PARAMETER Enable
Enable hibernation
.EXAMPLE
Hibernate -Enable
.EXAMPLE
Hibernate -Disable
.NOTES
Do not recommend turning it off on laptops
Current user
#>
function Hibernate
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
POWERCFG /HIBERNATE ON
}
"Disable"
{
POWERCFG /HIBERNATE OFF
}
}
}
<#
.SYNOPSIS
Configure the %TEMP% environment variable path
.PARAMETER SystemDrive
Change the %TEMP% environment variable path to "%SystemDrive%\Temp"
.PARAMETER Default
Change the %TEMP% environment variable path to "%LOCALAPPDATA%\Temp"
.EXAMPLE
TempFolder -SystemDrive
.EXAMPLE
TempFolder -Default
.NOTES
Machine-wide
#>
function TempFolder
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "SystemDrive"
)]
[switch]
$SystemDrive,
[Parameter(
Mandatory = $true,
ParameterSetName = "Default"
)]
[switch]
$Default
)
switch ($PSCmdlet.ParameterSetName)
{
"SystemDrive"
{
# Restart the Printer Spooler service (Spooler)
Restart-Service -Name Spooler -Force
if (-not (Test-Path -Path $env:SystemDrive\Temp))
{
New-Item -Path $env:SystemDrive\Temp -ItemType Directory -Force
}
Remove-Item -Path $env:SystemRoot\Temp -Recurse -Force -ErrorAction Ignore
Get-Item -Path $env:LOCALAPPDATA\Temp -Force -ErrorAction Ignore | Where-Object -FilterScript {$_.LinkType -ne "SymbolicLink"} | Remove-Item -Recurse -Force -ErrorAction Ignore
if (Test-Path -Path $env:LOCALAPPDATA\Temp -ErrorAction Ignore)
{
if ((Get-ChildItem -Path $env:LOCALAPPDATA\Temp -Force -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
Invoke-Item -Path $env:LOCALAPPDATA\Temp
do
{
$Title = ""
$Message = $Localization.ClearFolder -f "$env:LOCALAPPDATA\Temp"
$Continue = $Localization.Continue
$Skip = $Localization.Skip
$Options = "&$Continue", "&$Skip"
$DefaultChoice = 0
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
# Create a symbolic link to the %SystemDrive%\Temp folder
try
{
Get-Item -Path $env:LOCALAPPDATA\Temp -Force | Where-Object -FilterScript {$_.LinkType -ne "SymbolicLink"} | Remove-Item -Recurse -Force -ErrorAction Ignore
New-Item -Path $env:LOCALAPPDATA\Temp -ItemType SymbolicLink -Value $env:SystemDrive\Temp -Force -ErrorAction SilentlyContinue
}
catch [System.Exception]
{
Write-Verbose -Message $Localization.FilesBlocked -Verbose
Write-Verbose -Message ((Get-ChildItem -Path $env:LOCALAPPDATA\Temp -Force).FullName | Out-String) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.SymbolicSkipped -Verbose
}
}
}
until (((Get-ChildItem -Path $env:LOCALAPPDATA\Temp -Force -ErrorAction Ignore | Measure-Object).Count -eq 0) -or ($Result -eq 1))
}
}
else
{
# Create a symbolic link to the %SystemDrive%\Temp folder
New-Item -Path $env:LOCALAPPDATA\Temp -ItemType SymbolicLink -Value $env:SystemDrive\Temp -Force
}
if (Get-Item -Path $env:LOCALAPPDATA\Temp -ErrorAction Ignore | Where-Object -FilterScript {$_.LinkType -eq "SymbolicLink"})
{
[Environment]::SetEnvironmentVariable("TMP", "$env:SystemDrive\Temp", "User")
[Environment]::SetEnvironmentVariable("TMP", "$env:SystemDrive\Temp", "Machine")
[Environment]::SetEnvironmentVariable("TMP", "$env:SystemDrive\Temp", "Process")
New-ItemProperty -Path HKCU:\Environment -Name TMP -PropertyType ExpandString -Value $env:SystemDrive\Temp -Force
[Environment]::SetEnvironmentVariable("TEMP", "$env:SystemDrive\Temp", "User")
[Environment]::SetEnvironmentVariable("TEMP", "$env:SystemDrive\Temp", "Machine")
[Environment]::SetEnvironmentVariable("TEMP", "$env:SystemDrive\Temp", "Process")
New-ItemProperty -Path HKCU:\Environment -Name TEMP -PropertyType ExpandString -Value $env:SystemDrive\Temp -Force
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name TMP -PropertyType ExpandString -Value $env:SystemDrive\Temp -Force
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name TEMP -PropertyType ExpandString -Value $env:SystemDrive\Temp -Force
}
}
"Default"
{
# Remove a symbolic link to the %SystemDrive%\Temp folder
if (Get-Item -Path $env:LOCALAPPDATA\Temp -Force -ErrorAction Ignore | Where-Object -FilterScript {$_.LinkType -eq "SymbolicLink"})
{
(Get-Item -Path $env:LOCALAPPDATA\Temp -Force).Delete()
}
if (-not (Test-Path -Path $env:SystemRoot\Temp))
{
New-Item -Path $env:SystemRoot\Temp -ItemType Directory -Force
}
if (-not (Test-Path -Path $env:LOCALAPPDATA\Temp))
{
New-Item -Path $env:LOCALAPPDATA\Temp -ItemType Directory -Force
}
# Restart the Printer Spooler service (Spooler)
Restart-Service -Name Spooler -Force
if ((Get-ChildItem -Path $env:SystemDrive\Temp -Force -ErrorAction Ignore | Measure-Object).Count -eq 0)
{
Remove-Item -Path $env:SystemDrive\Temp -Recurse -Force
}
else
{
Write-Verbose -Message ($Localization.TempNotEmpty -f $env:TEMP) -Verbose
}
[Environment]::SetEnvironmentVariable("TMP", "$env:LOCALAPPDATA\Temp", "User")
[Environment]::SetEnvironmentVariable("TMP", "$env:SystemRoot\TEMP", "Machine")
[Environment]::SetEnvironmentVariable("TMP", "$env:LOCALAPPDATA\Temp", "Process")
New-ItemProperty -Path HKCU:\Environment -Name TMP -PropertyType ExpandString -Value $env:LOCALAPPDATA\Temp -Force
[Environment]::SetEnvironmentVariable("TEMP", "$env:LOCALAPPDATA\Temp", "User")
[Environment]::SetEnvironmentVariable("TEMP", "$env:SystemRoot\TEMP", "Machine")
[Environment]::SetEnvironmentVariable("TEMP", "$env:LOCALAPPDATA\Temp", "Process")
New-ItemProperty -Path HKCU:\Environment -Name TEMP -PropertyType ExpandString -Value $env:LOCALAPPDATA\Temp -Force
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name TMP -PropertyType ExpandString -Value $env:SystemRoot\TEMP -Force
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name TEMP -PropertyType ExpandString -Value $env:SystemRoot\TEMP -Force
}
}
}
<#
.SYNOPSIS
Configure the Windows 260 character path limit
.PARAMETER Disable
Disable the Windows 260 character path limit
.PARAMETER Enable
Enable the Windows 260 character path limit
.EXAMPLE
Win32LongPathLimit -Disable
.EXAMPLE
Win32LongPathLimit -Enable
.NOTES
Machine-wide
#>
function Win32LongPathLimit
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
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
}
}
}
<#
.SYNOPSIS
Configure the Stop error information display on the BSoD
.PARAMETER Disable
Do not display the Stop error information on the BSoD
.PARAMETER Enable
Display the Stop error information on the BSoD
.EXAMPLE
BSoDStopError -Disable
.EXAMPLE
BSoDStopError -Enable
.NOTES
Machine-wide
#>
function BSoDStopError
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl -Name DisplayParameters -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl -Name DisplayParameters -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Confgure UAC
.PARAMETER Disable
Choose when to be notified about changes to your computer: never notify
.PARAMETER Enable
Choose when to be notified about changes to your computer: notify me only when apps try to make changes to my computer
.EXAMPLE
AdminApprovalMode -Disable
.EXAMPLE
AdminApprovalMode -Enable
.NOTES
Machine-wide
#>
function AdminApprovalMode
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -PropertyType DWord -Value 5 -Force
}
}
}
<#
.SYNOPSIS
Configure access to mapped drives from app running with elevated permissions with Admin Approval Mode enabled
.PARAMETER Disable
Turn off access to mapped drives from app running with elevated permissions with Admin Approval Mode enabled
.PARAMETER Enable
Turn on access to mapped drives from app running with elevated permissions with Admin Approval Mode enabled
.EXAMPLE
MappedDrivesAppElevatedAccess -Disable
.EXAMPLE
MappedDrivesAppElevatedAccess -Enable
.NOTES
Machine-wide
#>
function MappedDrivesAppElevatedAccess
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLinkedConnections -PropertyType DWord -Value 0 -Force
}
"Enable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLinkedConnections -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure Delivery Optimization
.PARAMETER Disable
Turn off Delivery Optimization
.PARAMETER Enable
Turn on Delivery Optimization
.EXAMPLE
DeliveryOptimization -Disable
.EXAMPLE
DeliveryOptimization -Enable
.NOTES
Current user
#>
function DeliveryOptimization
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
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
}
"Enable"
{
New-ItemProperty -Path Registry::HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings -Name DownloadMode -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure the Group Policy processing
.PARAMETER Disable
Never wait for the network at computer startup and logon for workgroup networks
.PARAMETER Enable
Always wait for the network at computer startup and logon for workgroup networks
.EXAMPLE
WaitNetworkStartup -Disable
.EXAMPLE
WaitNetworkStartup -Enable
.NOTES
Machine-wide
#>
function WaitNetworkStartup
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if ((Get-CimInstance -ClassName CIM_ComputerSystem).PartOfDomain -eq $true)
{
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name SyncForegroundPolicy -Force -ErrorAction SilentlyContinue
}
}
"Enable"
{
if ((Get-CimInstance -ClassName CIM_ComputerSystem).PartOfDomain -eq $true)
{
if (-not (Test-Path -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\Winlogon"))
{
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\Winlogon" -Force
}
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name SyncForegroundPolicy -PropertyType DWord -Value 1 -Force
}
}
}
}
<#
.SYNOPSIS
Configure whether Windows decide which printer should be the default one
.PARAMETER Disable
Do not let Windows decide which printer should be the default one
.PARAMETER Enable
Let Windows decide which printer should be the default one
.EXAMPLE
WindowsManageDefaultPrinter -Disable
.EXAMPLE
WindowsManageDefaultPrinter -Enable
.NOTES
Current user
#>
function WindowsManageDefaultPrinter
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" -Name LegacyDefaultPrinterMode -PropertyType DWord -Value 1 -Force
}
"Enable"
{
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" -Name LegacyDefaultPrinterMode -PropertyType DWord -Value 0 -Force
}
}
}
<#
.SYNOPSIS
Configure Windows features
.PARAMETER Disable
Disable Windows features
.PARAMETER Enable
Enable Windows features
.EXAMPLE
WindowsFeatures -Disable
.EXAMPLE
WindowsFeatures -Enable
.NOTES
A pop-up dialog box enables the user to select features
Current user
#>
function WindowsFeatures
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
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
# Средство записи XPS-документов (Microsoft)
"Printing-XPSServices-Features",
# 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 = '
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="Window"
MinHeight="450" MinWidth="400"
SizeToContent="Width" WindowStartupLocation="CenterScreen"
TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True"
FontFamily="Segoe UI" FontSize="12" ShowInTaskbar="False">
<Window.Resources>
<Style TargetType="StackPanel">
<Setter Property="Orientation" Value="Horizontal"/>
</Style>
<Style TargetType="CheckBox">
<Setter Property="Margin" Value="10, 10, 5, 10"/>
<Setter Property="IsChecked" Value="True"/>
</Style>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="5, 10, 10, 10"/>
</Style>
<Style TargetType="Button">
<Setter Property="Margin" Value="20"/>
<Setter Property="Padding" Value="10"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollViewer Name="Scroll" Grid.Row="0"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<StackPanel Name="PanelContainer" Orientation="Vertical"/>
</ScrollViewer>
<Button Name="Button" Grid.Row="1"/>
</Grid>
</Window>
'
#endregion XAML Markup
$Reader = (New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)
$Form = [Windows.Markup.XamlReader]::Load($Reader)
$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-Verbose -Message $Localization.Patient -Verbose
[void]$Window.Close()
$SelectedFeatures | ForEach-Object -Process {Write-Verbose $_.DisplayName -Verbose}
$SelectedFeatures | Disable-WindowsOptionalFeature -Online -NoRestart
}
function EnableButton
{
Write-Verbose -Message $Localization.Patient -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 = $Localization.Enable
$ButtonAdd_Click = {EnableButton}
}
"Disable"
{
$State = @("Enabled", "EnablePending")
$ButtonContent = $Localization.Disable
$ButtonAdd_Click = {DisableButton}
}
}
Write-Verbose -Message $Localization.Patient -Verbose
# Getting list of all optional features according to the conditions
$OFS = "|"
$Features = Get-WindowsOptionalFeature -Online | Where-Object -FilterScript {
($_.State -in $State) -and (($_.FeatureName -cmatch $UncheckedFeatures) -or ($_.FeatureName -cmatch $CheckedFeatures))
} | ForEach-Object -Process {Get-WindowsOptionalFeature -FeatureName $_.FeatureName -Online}
$OFS = " "
if (-not ($Features))
{
Write-Verbose -Message $Localization.NoData -Verbose
return
}
Write-Verbose -Message $Localization.DialogBoxOpening -Verbose
$Window.Add_Loaded({$Features | Add-FeatureControl})
$Button.Content = $ButtonContent
$Button.Add_Click({& $ButtonAdd_Click})
$Window.Title = $Localization.WindowsFeaturesTitle
$Form.ShowDialog() | Out-Null
}
<#
.SYNOPSIS
Configure optional features
.PARAMETER Uninstall
Uninstall optional features
.PARAMETER Install
Install optional features
.EXAMPLE
WindowsCapabilities -Uninstall
.EXAMPLE
WindowsCapabilities -Install
.NOTES
A pop-up dialog box enables the user to select features
Current user
#>
function WindowsCapabilities
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Install"
)]
[switch]
$Install,
[Parameter(
Mandatory = $true,
ParameterSetName = "Uninstall"
)]
[switch]
$Uninstall
)
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 = @(
# Microsoft Quick Assist
# Быстрая поддержка (Майкрософт)
"App.Support.QuickAssist*"
)
# The following optional features will have their checkboxes unchecked
[string[]]$UncheckedCapabilities = @(
# Internet Explorer 11
"Browser.InternetExplorer*",
# Math Recognizer
# Распознаватель математических знаков
"MathRecognizer*",
<#
Windows Media Player
Проигрыватель Windows Media
If you want to leave "Multimedia settings" element in the advanced settings of Power Options do not uninstall this feature
Если вы хотите оставить параметр "Параметры мультимедиа" в дополнительных параметрах электропитания, не удаляйте этот компонент
#>
"Media.WindowsMediaPlayer*",
# OpenSSH Client
# Клиент OpenSSH
"OpenSSH.Client*"
)
# 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 для настройки и оптимизации приложений при наличии нескольких графических адаптеров
"DirectX.Configuration.Database*",
# Language components
# Языковые компоненты
"Language.*",
# Notepad
# Блокнот
"Microsoft.Windows.Notepad*",
# Mail, contacts, and calendar sync component
# Компонент синхронизации почты, контактов и календаря
"OneCoreUAP.OneSync*"
)
#endregion Variables
#region XAML Markup
# The section defines the design of the upcoming dialog box
[xml]$XAML = '
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="Window"
MinHeight="450" MinWidth="400"
SizeToContent="Width" WindowStartupLocation="CenterScreen"
TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True"
FontFamily="Segoe UI" FontSize="12" ShowInTaskbar="False">
<Window.Resources>
<Style TargetType="StackPanel">
<Setter Property="Orientation" Value="Horizontal"/>
</Style>
<Style TargetType="CheckBox">
<Setter Property="Margin" Value="10, 10, 5, 10"/>
<Setter Property="IsChecked" Value="True"/>
</Style>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="5, 10, 10, 10"/>
</Style>
<Style TargetType="Button">
<Setter Property="Margin" Value="20"/>
<Setter Property="Padding" Value="10"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollViewer Name="Scroll" Grid.Row="0"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<StackPanel Name="PanelContainer" Orientation="Vertical"/>
</ScrollViewer>
<Button Name="Button" Grid.Row="1"/>
</Grid>
</Window>
'
#endregion XAML Markup
$Reader = (New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)
$Form = [Windows.Markup.XamlReader]::Load($Reader)
$XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process {
Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)
}
#region Functions
function InternetConnectionStatus
{
try
{
(Invoke-WebRequest -Uri https://www.google.com -UseBasicParsing -DisableKeepAlive -Method Head).StatusDescription
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
return
}
}
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-Verbose -Message $Localization.Patient -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 -cmatch "Browser.InternetExplorer*")
{
Write-Warning -Message $Localization.RestartWarning
}
}
function InstallButton
{
Write-Verbose -Message $Localization.Patient -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 -cmatch "Browser.InternetExplorer*")
{
Write-Warning -Message $Localization.RestartWarning
}
}
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"
{
InternetConnectionStatus
$State = "NotPresent"
$ButtonContent = $Localization.Install
$ButtonAdd_Click = {InstallButton}
}
"Uninstall"
{
$State = "Installed"
$ButtonContent = $Localization.Uninstall
$ButtonAdd_Click = {UninstallButton}
}
}
Write-Verbose -Message $Localization.Patient -Verbose
# Getting list of all capabilities according to the conditions
$OFS = "|"
$Capabilities = Get-WindowsCapability -Online | Where-Object -FilterScript {
($_.State -eq $State) -and (($_.Name -cmatch $UncheckedCapabilities) -or ($_.Name -cmatch $CheckedCapabilities) -and ($_.Name -cnotmatch $ExcludedCapabilities))
} | ForEach-Object -Process {Get-WindowsCapability -Name $_.Name -Online}
$OFS = " "
if (-not ($Capabilities))
{
Write-Verbose -Message $Localization.NoData -Verbose
return
}
Write-Verbose -Message $Localization.DialogBoxOpening -Verbose
$Window.Add_Loaded({$Capabilities | Add-CapabilityControl})
$Button.Content = $ButtonContent
$Button.Add_Click({& $ButtonAdd_Click})
$Window.Title = $Localization.OptionalFeaturesTitle
$Form.ShowDialog() | Out-Null
}
<#
.SYNOPSIS
Configure receiving updates for other Microsoft products when you update Windows
.PARAMETER Disable
Do not receive updates for other Microsoft products when you update Windows
.PARAMETER Enable
Receive updates for other Microsoft products when you update Windows
.EXAMPLE
UpdateMicrosoftProducts -Disable
.EXAMPLE
UpdateMicrosoftProducts -Enable
.NOTES
Current user
#>
function UpdateMicrosoftProducts
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if ((New-Object -ComObject Microsoft.Update.ServiceManager).Services | Where-Object {$_.ServiceID -eq "7971f918-a847-4430-9279-4a52d1efe18d"})
{
(New-Object -ComObject Microsoft.Update.ServiceManager).RemoveService("7971f918-a847-4430-9279-4a52d1efe18d")
}
}
"Enable"
{
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
}
}
}
<#
.SYNOPSIS
Configure the power management scheme
.PARAMETER High
Set the power management scheme on "High performance"
.PARAMETER Balanced
Set the power management scheme on "Balanced"
.EXAMPLE
PowerManagementScheme -High
.EXAMPLE
PowerManagementScheme -Balanced
.NOTES
Do not recommend turning "High performance" scheme on on laptops
Current user
#>
function PowerManagementScheme
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "High"
)]
[switch]
$High,
[Parameter(
Mandatory = $true,
ParameterSetName = "Balanced"
)]
[switch]
$Balanced
)
switch ($PSCmdlet.ParameterSetName)
{
"High"
{
POWERCFG /SETACTIVE SCHEME_MIN
}
"Balanced"
{
POWERCFG /SETACTIVE SCHEME_BALANCED
}
}
}
<#
.SYNOPSIS
Configure the latest installed .NET runtime for all apps usage
.PARAMETER Disable
Do not use latest installed .NET runtime for all apps
.PARAMETER Enable
Use use latest installed .NET runtime for all apps
.EXAMPLE
LatestInstalled.NET -Disable
.EXAMPLE
LatestInstalled.NET -Enable
.NOTES
Machine-wide
#>
function LatestInstalled.NET
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\.NETFramework -Name OnlyUseLatestCLR -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework -Name OnlyUseLatestCLR -Force -ErrorAction SilentlyContinue
}
"Enable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\.NETFramework -Name OnlyUseLatestCLR -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework -Name OnlyUseLatestCLR -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure network adapters to save power
.PARAMETER Disable
Do not allow the computer to turn off the network adapters to save power
.PARAMETER Enable
Allow the computer to turn off the network adapters to save power
.EXAMPLE
PCTurnOffDevice -Disable
.EXAMPLE
PCTurnOffDevice -Enable
.NOTES
Do not recommend turning it on on laptops
.NOTES
Current user
#>
function PCTurnOffDevice
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
$Adapters = Get-NetAdapter -Physical | Get-NetAdapterPowerManagement | Where-Object -FilterScript {$_.AllowComputerToTurnOffDevice -ne "Unsupported"}
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
}
}
}
}
<#
.SYNOPSIS
Configure override for default input method
.PARAMETER English
Override for default input method: English
.PARAMETER Default
Override for default input method: use langiage list
.EXAMPLE
SetInputMethod -English
.EXAMPLE
SetInputMethod -Default
.NOTES
Current user
#>
function SetInputMethod
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "English"
)]
[switch]
$English,
[Parameter(
Mandatory = $true,
ParameterSetName = "Default"
)]
[switch]
$Default
)
switch ($PSCmdlet.ParameterSetName)
{
"English"
{
Set-WinDefaultInputMethodOverride -InputTip "0409:00000409"
}
"Default"
{
Remove-ItemProperty -Path "HKCU:\Control Panel\International\User Profile" -Name InputMethodOverride -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure user folders location
.PARAMETER Root
Move user folders location to the root of any drive using the interactive menu
.PARAMETER Custom
Select folders for user folders location manually using a folder browser dialog
.PARAMETER Default
Change user folders location to the default values
.EXAMPLE
SetUserShellFolderLocation -Root
.EXAMPLE
SetUserShellFolderLocation -Custom
.EXAMPLE
SetUserShellFolderLocation -Default
.NOTES
User files or folders won't me moved to a new location
Current user
#>
function SetUserShellFolderLocation
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Root"
)]
[switch]
$Root,
[Parameter(
Mandatory = $true,
ParameterSetName = "Custom"
)]
[switch]
$Custom,
[Parameter(
Mandatory = $true,
ParameterSetName = "Default"
)]
[switch]
$Default
)
<#
.SYNOPSIS
Change the location of the each user folder using SHSetKnownFolderPath function
.PARAMETER RemoveDesktopINI
The RemoveDesktopINI argument removes desktop.ini in the old user shell folder
.EXAMPLE
UserShellFolder -UserFolder Desktop -FolderPath "$env:SystemDrive:\Desktop" -RemoveDesktopINI
.LINK
https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath
.NOTES
User files or folders won't me moved to a new location
#>
function UserShellFolder
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet("Desktop", "Documents", "Downloads", "Music", "Pictures", "Videos")]
[string]
$UserFolder,
[Parameter(Mandatory = $true)]
[string]
$FolderPath,
[Parameter(Mandatory = $false)]
[switch]
$RemoveDesktopINI
)
<#
.SYNOPSIS
Redirect user folders to a new location
.EXAMPLE
KnownFolderPath -KnownFolder Desktop -Path "$env:SystemDrive:\Desktop"
#>
function KnownFolderPath
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet("Desktop", "Documents", "Downloads", "Music", "Pictures", "Videos")]
[string]
$KnownFolder,
[Parameter(Mandatory = $true)]
[string]
$Path
)
$KnownFolders = @{
"Desktop" = @("B4BFCC3A-DB2C-424C-B029-7FE99A87C641");
"Documents" = @("FDD39AD0-238F-46AF-ADB4-6C85480369C7", "f42ee2d3-909f-4907-8871-4c22fc0bf756");
"Downloads" = @("374DE290-123F-4565-9164-39C4925E467B", "7d83ee9b-2244-4e70-b1f5-5393042af1e4");
"Music" = @("4BD8D571-6D19-48D3-BE97-422220080E43", "a0c69a99-21c8-4671-8703-7934162fcf1d");
"Pictures" = @("33E28130-4E1E-4676-835A-98395C3BC3BB", "0ddd015d-b06c-45d5-8c4c-f59713854639");
"Videos" = @("18989B1D-99B5-455B-841C-AB7C74E4DDFC", "35286a68-3c57-41a1-bbb1-0eae73d76c95");
}
$Signature = @{
Namespace = "WinAPI"
Name = "KnownFolders"
Language = "CSharp"
MemberDefinition = @"
[DllImport("shell32.dll")]
public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, IntPtr token, [MarshalAs(UnmanagedType.LPWStr)] string path);
"@
}
if (-not ("WinAPI.KnownFolders" -as [type]))
{
Add-Type @Signature
}
foreach ($guid in $KnownFolders[$KnownFolder])
{
[WinAPI.KnownFolders]::SHSetKnownFolderPath([ref]$guid, 0, 0, $Path)
}
(Get-Item -Path $Path -Force).Attributes = "ReadOnly"
}
$UserShellFoldersRegName = @{
"Desktop" = "Desktop"
"Documents" = "Personal"
"Downloads" = "{374DE290-123F-4565-9164-39C4925E467B}"
"Music" = "My Music"
"Pictures" = "My Pictures"
"Videos" = "My Video"
}
$UserShellFoldersGUID = @{
"Desktop" = "{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}"
"Documents" = "{F42EE2D3-909F-4907-8871-4C22FC0BF756}"
"Downloads" = "{7D83EE9B-2244-4E70-B1F5-5393042AF1E4}"
"Music" = "{A0C69A99-21C8-4671-8703-7934162FCF1D}"
"Pictures" = "{0DDD015D-B06C-45D5-8C4C-F59713854639}"
"Videos" = "{35286A68-3C57-41A1-BBB1-0EAE73D76C95}"
}
# Contents of the hidden desktop.ini file for each type of user folders
$DesktopINI = @{
"Desktop" = "",
"[.ShellClassInfo]",
"LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21769",
"IconResource=%SystemRoot%\system32\imageres.dll,-183"
"Documents" = "",
"[.ShellClassInfo]",
"LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21770",
"IconResource=%SystemRoot%\system32\imageres.dll,-112",
"IconFile=%SystemRoot%\system32\shell32.dll",
"IconIndex=-235"
"Downloads" = "",
"[.ShellClassInfo]","LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21798",
"IconResource=%SystemRoot%\system32\imageres.dll,-184"
"Music" = "",
"[.ShellClassInfo]","LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21790",
"InfoTip=@%SystemRoot%\system32\shell32.dll,-12689",
"IconResource=%SystemRoot%\system32\imageres.dll,-108",
"IconFile=%SystemRoot%\system32\shell32.dll","IconIndex=-237"
"Pictures" = "",
"[.ShellClassInfo]",
"LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21779",
"InfoTip=@%SystemRoot%\system32\shell32.dll,-12688",
"IconResource=%SystemRoot%\system32\imageres.dll,-113",
"IconFile=%SystemRoot%\system32\shell32.dll",
"IconIndex=-236"
"Videos" = "",
"[.ShellClassInfo]",
"LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21791",
"InfoTip=@%SystemRoot%\system32\shell32.dll,-12690",
"IconResource=%SystemRoot%\system32\imageres.dll,-189",
"IconFile=%SystemRoot%\system32\shell32.dll","IconIndex=-238"
}
# Determining the current user folder path
$UserShellFolderRegValue = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersRegName[$UserFolder]
if ($UserShellFolderRegValue -ne $FolderPath)
{
if ((Get-ChildItem -Path $UserShellFolderRegValue | Measure-Object).Count -ne 0)
{
Write-Error -Message ($Localization.UserShellFolderNotEmpty -f $UserShellFolderRegValue) -ErrorAction SilentlyContinue
}
# Creating a new folder if there is no one
if (-not (Test-Path -Path $FolderPath))
{
New-Item -Path $FolderPath -ItemType Directory -Force
}
# Removing old desktop.ini
if ($RemoveDesktopINI.IsPresent)
{
Remove-Item -Path "$UserShellFolderRegValue\desktop.ini" -Force
}
KnownFolderPath -KnownFolder $UserFolder -Path $FolderPath
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name $UserShellFoldersGUID[$UserFolder] -PropertyType ExpandString -Value $FolderPath -Force
Set-Content -Path "$FolderPath\desktop.ini" -Value $DesktopINI[$UserFolder] -Encoding Unicode -Force
(Get-Item -Path "$FolderPath\desktop.ini" -Force).Attributes = "Hidden", "System", "Archive"
(Get-Item -Path "$FolderPath\desktop.ini" -Force).Refresh()
}
}
<#
.SYNOPSIS
The "Show menu" function with the up/down arrow keys and enter key to make a selection
.EXAMPLE
ShowMenu -Menu $ListOfItems -Default $DefaultChoice
.LINK
https://qna.habr.com/answer?answer_id=1522379
#>
function ShowMenu
{
[CmdletBinding()]
param
(
[Parameter()]
[string]
$Title,
[Parameter(Mandatory = $true)]
[array]
$Menu,
[Parameter(Mandatory = $true)]
[int]
$Default
)
Write-Information -MessageData $Title -InformationAction Continue
$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 (' {0}. {1} ' -f ($i+1), $item) -InformationAction Continue
}
else
{
Write-Information -MessageData ('[ {0}. {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))
}
switch ($PSCmdlet.ParameterSetName)
{
"Root"
{
# Store all drives letters to use them within ShowMenu function
Write-Verbose -Message $Localization.RetrievingDrivesList -Verbose
$DriveLetters = @((Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object)
# If the number of disks is more than one, set the second drive in the list as default drive
if ($DriveLetters.Count -gt 1)
{
$Script:Default = 1
}
else
{
$Script:Default = 0
}
# Desktop
Write-Verbose -Message $Localization.DesktopDriveSelect -Verbose
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.DesktopRequest
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
$SelectedDrive = ShowMenu -Title $Localization.DesktopDriveSelect -Menu $DriveLetters -Default $Script:Default
UserShellFolder -UserFolder Desktop -FolderPath "${SelectedDrive}:\Desktop" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Documents
Write-Verbose -Message $Localization.DocumentsDriveSelect -Verbose
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.DocumentsRequest
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
$SelectedDrive = ShowMenu -Title $Localization.DocumentsDriveSelect -Menu $DriveLetters -Default $Script:Default
UserShellFolder -UserFolder Documents -FolderPath "${SelectedDrive}:\Documents" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Downloads
Write-Verbose -Message $Localization.DownloadsDriveSelect -Verbose
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.DownloadsRequest
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
$SelectedDrive = ShowMenu -Title $Localization.DownloadsDriveSelect -Menu $DriveLetters -Default $Script:Default
UserShellFolder -UserFolder Downloads -FolderPath "${SelectedDrive}:\Downloads" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Music
Write-Verbose -Message $Localization.MusicDriveSelect -Verbose
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.MusicRequest
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
$SelectedDrive = ShowMenu -Title $Localization.MusicDriveSelect -Menu $DriveLetters -Default $Script:Default
UserShellFolder -UserFolder Music -FolderPath "${SelectedDrive}:\Music" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Pictures
Write-Verbose -Message $Localization.PicturesDriveSelect -Verbose
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.PicturesRequest
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
$SelectedDrive = ShowMenu -Title $Localization.PicturesDriveSelect -Menu $DriveLetters -Default $Script:Default
UserShellFolder -UserFolder Pictures -FolderPath "${SelectedDrive}:\Pictures" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Videos
Write-Verbose -Message $Localization.VideosDriveSelect -Verbose
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.VideosRequest
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
$SelectedDrive = ShowMenu -Title $Localization.VideosDriveSelect -Menu $DriveLetters -Default $Script:Default
UserShellFolder -UserFolder Videos -FolderPath "${SelectedDrive}:\Videos" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
}
"Custom"
{
# Desktop
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.DesktopFolderSelect
$Select = $Localization.Select
$Skip = $Localization.Skip
$Options = "&$Select", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowserDialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
if ($FolderBrowserDialog.SelectedPath)
{
UserShellFolder -UserFolder Desktop -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI
Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Documents
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.DocumentsFolderSelect
$Select = $Localization.Select
$Skip = $Localization.Skip
$Options = "&$Select", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowserDialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
if ($FolderBrowserDialog.SelectedPath)
{
UserShellFolder -UserFolder Documents -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI
Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Downloads
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.DownloadsFolderSelect
$Select = $Localization.Select
$Skip = $Localization.Skip
$Options = "&$Select", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowserDialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
if ($FolderBrowserDialog.SelectedPath)
{
UserShellFolder -UserFolder Downloads -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI
Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Music
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.MusicFolderSelect
$Select = $Localization.Select
$Skip = $Localization.Skip
$Options = "&$Select", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowserDialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
if ($FolderBrowserDialog.SelectedPath)
{
UserShellFolder -UserFolder Music -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI
Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Pictures
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.PicturesFolderSelect
$Select = $Localization.Select
$Skip = $Localization.Skip
$Options = "&$Select", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowserDialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
if ($FolderBrowserDialog.SelectedPath)
{
UserShellFolder -UserFolder Pictures -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI
Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Videos
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.VideosFolderSelect
$Select = $Localization.Select
$Skip = $Localization.Skip
$Options = "&$Select", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowserDialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
if ($FolderBrowserDialog.SelectedPath)
{
UserShellFolder -UserFolder Videos -FolderPath $FolderBrowserDialog.SelectedPath -RemoveDesktopINI
Write-Verbose -Message ($Localization.NewUserFolderLocation -f $FolderBrowserDialog.SelectedPath) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
}
"Default"
{
# Desktop
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.DesktopDefaultFolder
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
UserShellFolder -UserFolder Desktop -FolderPath "$env:USERPROFILE\Desktop" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Documents
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.DocumentsDefaultFolder
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
UserShellFolder -UserFolder Documents -FolderPath "$env:USERPROFILE\Documents" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Downloads
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.DownloadsDefaultFolder
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
UserShellFolder -UserFolder Downloads -FolderPath "$env:USERPROFILE\Downloads" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Music
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.MusicDefaultFolder
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
UserShellFolder -UserFolder Music -FolderPath "$env:USERPROFILE\Music" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Pictures
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.PicturesDefaultFolder
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
UserShellFolder -UserFolder Pictures -FolderPath "$env:USERPROFILE\Pictures" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
# Videos
Write-Warning -Message $Localization.FilesWontBeMoved
$Title = ""
$Message = $Localization.VideosDefaultFolder
$Change = $Localization.Change
$Skip = $Localization.Skip
$Options = "&$Change", "&$Skip"
$DefaultChoice = 1
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
UserShellFolder -UserFolder Videos -FolderPath "$env:USERPROFILE\Videos" -RemoveDesktopINI
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
}
}
}
<#
.SYNOPSIS
Choose where to save screenshots by pressing Win+PrtScr
.PARAMETER Desktop
Save screenshots by pressing Win+PrtScr on the Desktop
.PARAMETER Default
Save screenshots by pressing Win+PrtScr in the Pictures folder
.EXAMPLE
WinPrtScrFolder -Desktop
.EXAMPLE
WinPrtScrFolder -Default
.NOTES
Current user
#>
function WinPrtScrFolder
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Desktop"
)]
[switch]
$Desktop,
[Parameter(
Mandatory = $true,
ParameterSetName = "Default"
)]
[switch]
$Default
)
switch ($PSCmdlet.ParameterSetName)
{
"Desktop"
{
$DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Type ExpandString -Value $DesktopFolder -Force
}
"Default"
{
Remove-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction SilentlyContinue
}
}
# Save all opened folders in order to restore them after File Explorer restart
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke()
# In order for the changes to take effect the File Explorer process has to be restarted
Stop-Process -Name explorer -Force
# Restoring closed folders
foreach ($OpenedFolder in $OpenedFolders)
{
if (Test-Path -Path $OpenedFolder)
{
Invoke-Item -Path $OpenedFolder
}
}
}
<#
.SYNOPSIS
Configure folder windows launching in a separate process
.PARAMETER Enable
Launch launch folder windows in a separate process
.PARAMETER Disable
Do not launch folder windows in a separate process
.EXAMPLE
FoldersLaunchSeparateProcess -Enable
.EXAMPLE
FoldersLaunchSeparateProcess -Disable
.NOTES
Current user
#>
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
}
}
}
<#
.SYNOPSIS
Configure help look up via F1
.PARAMETER Enable
Enable help lookup via F1
.PARAMETER Disable
Disable help lookup via F1
.EXAMPLE
F1HelpPage -Enable
.EXAMPLE
F1HelpPage -Disable
.NOTES
Current user
#>
function F1HelpPage
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
Remove-Item -Path "HKCU:\SOFTWARE\Classes\Typelib\{8cec5860-07a1-11d9-b15e-000d56bfe6ee}" -Recurse -Force -ErrorAction SilentlyContinue
}
"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
}
}
}
<#
.SYNOPSIS
Configure Num Lock at startup
.PARAMETER Enable
Enable Num Lock at startup
.PARAMETER Disable
Disable Num Lock at startup
.EXAMPLE
NumLock -Enable
.EXAMPLE
NumLock -Disable
.NOTES
Current user
#>
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
}
}
}
<#
.SYNOPSIS
Configure Caps Lock
.PARAMETER Enable
Enable Capsm Lock
.PARAMETER Disable
Disable Caps Lock
.EXAMPLE
CapsLock -Enable
.EXAMPLE
CapsLock -Disable
.NOTES
Machine-wide
#>
function CapsLock
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
Remove-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout" -Name "Scancode Map" -Force
}
"Disable"
{
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout" -Name "Scancode Map" -PropertyType Binary -Value ([byte[]](0,0,0,0,0,0,0,0,2,0,0,0,0,0,58,0,0,0,0,0)) -Force
}
}
}
<#
.SYNOPSIS
Configure Sticky Keys
.PARAMETER Enable
Enable Sticky Keys after tapping the Shift key 5 times
.PARAMETER Disable
Disable Sticky Keys after tapping the Shift key 5 times
.EXAMPLE
StickyShift -Enable
.EXAMPLE
StickyShift -Disable
.NOTES
Current user
#>
function StickyShift
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path "HKCU:\Control Panel\Accessibility\StickyKeys" -Name Flags -PropertyType String -Value 510 -Force
}
"Disable"
{
New-ItemProperty -Path "HKCU:\Control Panel\Accessibility\StickyKeys" -Name Flags -PropertyType String -Value 506 -Force
}
}
}
<#
.SYNOPSIS
Configure AutoPlay for all media and devices
.PARAMETER Enable
Disable/enable AutoPlay for all media and devices
.PARAMETER Disable
Disable/enable AutoPlay for all media and devices
.EXAMPLE
Autoplay -Enable
.EXAMPLE
Autoplay -Disable
.NOTES
Current user
#>
function Autoplay
{
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\AutoplayHandlers -Name DisableAutoplay -PropertyType DWord -Value 0 -Force
}
"Disable"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers -Name DisableAutoplay -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure thumbnail cache removal
.PARAMETER Enable
Enable thumbnail cache removal
.PARAMETER Disable
Disable thumbnail cache removal
.EXAMPLE
ThumbnailCacheRemoval -Enable
.EXAMPLE
ThumbnailCacheRemoval -Disable
.NOTES
Machine-wide
#>
function ThumbnailCacheRemoval
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thumbnail Cache" -Name Autorun -PropertyType DWord -Value 3 -Force
}
"Disable"
{
New-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thumbnail Cache" -Name Autorun -PropertyType DWord -Value 0 -Force
}
}
}
<#
.SYNOPSIS
Configure "Network Discovery" and "File and Printers Sharing" for workgroup networks
.PARAMETER Enable
Enable "Network Discovery" and "File and Printers Sharing" for workgroup networks
.PARAMETER Disable
Disable "Network Discovery" and "File and Printers Sharing" for workgroup networks
.EXAMPLE
NetworkDiscovery -Enable
.EXAMPLE
NetworkDiscovery -Disable
.NOTES
Current user
#>
function NetworkDiscovery
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
$FirewallRules = @(
# File and printer sharing
# Общий доступ к файлам и принтерам
"@FirewallAPI.dll,-32752",
# Network discovery
# Сетевое обнаружение
"@FirewallAPI.dll,-28502"
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
if ((Get-CimInstance -ClassName CIM_ComputerSystem).PartOfDomain -eq $false)
{
Set-NetFirewallRule -Group $FirewallRules -Profile Private -Enabled True
Set-NetFirewallRule -Profile Public, Private -Name FPS-SMB-In-TCP -Enabled True
Set-NetConnectionProfile -NetworkCategory Private
}
}
"Disable"
{
if ((Get-CimInstance -ClassName CIM_ComputerSystem).PartOfDomain -eq $false)
{
Set-NetFirewallRule -Group $FirewallRules -Profile Private -Enabled False
}
}
}
}
<#
.SYNOPSIS
Configure automatically adjusting active hours for me based on daily usage
.PARAMETER Enable
Enable automatically adjusting active hours for me based on daily usage
.PARAMETER Disable
Disable automatically adjusting active hours for me based on daily usage
.EXAMPLE
SmartActiveHours -Enable
.EXAMPLE
SmartActiveHours -Disable
.NOTES
Machine-wide
#>
function SmartActiveHours
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable
)
switch ($PSCmdlet.ParameterSetName)
{
"Enable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name SmartActiveHoursState -PropertyType DWord -Value 1 -Force
}
"Disable"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name SmartActiveHoursState -PropertyType DWord -Value 2 -Force
}
}
}
<#
.SYNOPSIS
Register app, calculate hash, and set as default for specific extension without the "How do you want to open this" pop-up
.PARAMETER ProgramPath
Set path to the .exe
.PARAMETER Extension
Set extension type
.PARAMETER Icon
Set path to the icon
.EXAMPLE
Set-Association -ProgramPath "C:\SumatraPDF.exe" -Extension .pdf -Icon "shell32.dll,100"
.EXAMPLE
Set-Association -ProgramPath "C:\Program Files\Notepad++\notepad++.exe" -Extension .psm1 -Icon "C:\Program Files\Notepad++\notepad++.exe,0"
.LINK
https://github.com/DanysysTeam/PS-SFTA
.NOTES
The app must be installed
Do not use relative paths like "%Program Files%"
Current user
#>
function Set-Association
{
[CmdletBinding()]
param
(
[Parameter(
Position = 0,
Mandatory = $true
)]
[ValidateScript({Test-Path -Path $_})]
[String]
$ProgramPath,
[Parameter(
Position = 1,
Mandatory = $true
)]
[String]
$Extension,
[Parameter(
Position = 3,
Mandatory = $false
)]
[String]
$Icon
)
$ProgId = "Applications\" + (Get-Item -Path $ProgramPath).BaseName + $Extension
if (-not (Test-Path -Path "HKCU:\SOFTWARE\Classes\$Extension\OpenWithProgids"))
{
New-Item -Path "HKCU:\SOFTWARE\Classes\$Extension\OpenWithProgids" -Force
}
New-ItemProperty -Path "HKCU:\SOFTWARE\Classes\$Extension\OpenWithProgids" -Name $ProgId -PropertyType None -Value ([byte[]]@()) -Force
if (-not (Test-Path -Path "HKCU:\SOFTWARE\Classes\$ProgId\shell\open\command"))
{
New-Item -Path "HKCU:\SOFTWARE\Classes\$ProgId\shell\open\command" -Force
}
New-ItemProperty -Path "HKCU:\SOFTWARE\Classes\$ProgId\shell\open\command" -Name "(Default)" -PropertyType String -Value "`"$ProgramPath`" `"%1`"" -Force
function Set-FTA
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[String]
$ProgId,
[Parameter(Mandatory = $true)]
[String]
$Extension,
[String]
$Icon
)
function local:Set-Icon
{
param
(
[Parameter(
Position = 0,
Mandatory = $true
)]
[String]
$ProgId,
[Parameter(
Position = 1,
Mandatory = $true
)]
[String]
$Icon
)
if (-not (Test-Path -Path "HKCU:\SOFTWARE\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\SOFTWARE\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\SOFTWARE\Classes\$ProgId\DefaultIcon" -Name "(Default)" -PropertyType String -Value $Icon -Force
}
function local:Write-ExtensionKeys
{
param
(
[Parameter(
Position = 0,
Mandatory = $true
)]
[String]
$ProgId,
[Parameter(
Position = 1,
Mandatory = $true
)]
[String]
$Extension,
[Parameter(
Position = 2,
Mandatory = $true
)]
[String]
$ProgHash
)
function local:Remove-UserChoiceKey
{
param
(
[Parameter(
Position = 0,
Mandatory = $true
)]
[String]
$Key
)
$Signature = @{
Namespace = "Registry"
Name = "Utils"
Language = "CSharp"
MemberDefinition = @"
[DllImport("advapi32.dll", SetLastError = true)]
private static extern int RegOpenKeyEx(UIntPtr hKey, string subKey, int ulOptions, int samDesired, out UIntPtr hkResult);
[DllImport("advapi32.dll", SetLastError=true, CharSet = CharSet.Unicode)]
private static extern uint RegDeleteKey(UIntPtr hKey, string subKey);
public static void DeleteKey(string key)
{
UIntPtr hKey = UIntPtr.Zero;
RegOpenKeyEx((UIntPtr)0x80000001u, key, 0, 0x20019, out hKey);
RegDeleteKey((UIntPtr)0x80000001u, key);
}
"@
}
if (-not ("Registry.Utils" -as [type]))
{
Add-Type @Signature
}
[Registry.Utils]::DeleteKey($Key)
}
Remove-UserChoiceKey -Key "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"))
{
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Force
}
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Name Hash -PropertyType String -Value $ProgHash -Force
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Name ProgId -PropertyType String -Value $ProgId -Force
}
function local:Get-HexDateTime
{
[OutputType([string])]
$now = [DateTime]::Now
$dateTime = [DateTime]::New($now.Year, $now.Month, $now.Day, $now.Hour, $now.Minute, 0)
$fileTime = $dateTime.ToFileTime()
$hi = ($fileTime -shr 32)
$low = ($fileTime -band 0xFFFFFFFFL)
$dateTimeHex = ($hi.ToString("X8") + $low.ToString("X8")).ToLower()
return $dateTimeHex
}
function Get-Hash
{
[CmdletBinding()]
param
(
[Parameter(
Position = 0,
Mandatory = $true
)]
[string]
$BaseInfo
)
function local:Get-ShiftRight
{
[CmdletBinding()]
param
(
[Parameter(
Position = 0,
Mandatory = $true
)]
[long]
$iValue,
[Parameter(
Position = 1,
Mandatory = $true
)]
[int]
$iCount
)
if ($iValue -band 0x80000000)
{
return (($iValue -shr $iCount) -bxor 0xFFFF0000)
}
else
{
return ($iValue -shr $iCount)
}
}
function local:Get-Long
{
[CmdletBinding()]
param
(
[Parameter(
Position = 0,
Mandatory = $true
)]
[byte[]]
$Bytes,
[Parameter(Position = 1)]
[int]
$Index = 0
)
return ([BitConverter]::ToInt32($Bytes, $Index))
}
function local:Convert-Int32
{
param
(
[Parameter(
Position = 0,
Mandatory = $true
)]
$Value
)
[byte[]]$bytes = [BitConverter]::GetBytes($Value)
return [BitConverter]::ToInt32($bytes, 0)
}
[byte[]]$bytesBaseInfo = [System.Text.Encoding]::Unicode.GetBytes($baseInfo)
$bytesBaseInfo += 0x00, 0x00
$MD5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
[byte[]]$bytesMD5 = $MD5.ComputeHash($bytesBaseInfo)
$lengthBase = ($baseInfo.Length * 2) + 2
$length = (($lengthBase -band 4) -le 1) + (Get-ShiftRight -iValue $lengthBase -iCount 2) - 1
$base64Hash = ""
if ($length -gt 1)
{
$Map = @{
PDATA = 0
CACHE = 0
COUNTER = 0
INDEX = 0
MD51 = 0
MD52 = 0
OUTHASH1 = 0
OUTHASH2 = 0
R0 = 0
R1 = @(0, 0)
R2 = @(0, 0)
R3 = 0
R4 = @(0, 0)
R5 = @(0, 0)
R6 = @(0, 0)
R7 = @(0, 0)
}
$Map.CACHE = 0
$Map.OUTHASH1 = 0
$Map.PDATA = 0
$Map.MD51 = (((Get-Long -Bytes $bytesMD5) -bor 1) + 0x69FB0000L)
$Map.MD52 = ((Get-Long -Bytes $bytesMD5 -Index 4) -bor 1) + 0x13DB0000L
$Map.INDEX = Get-ShiftRight -iValue ($length - 2) -iCount 1
$Map.COUNTER = $Map.INDEX + 1
while ($Map.COUNTER)
{
$Map.R0 = Convert-Int32 -Value ((Get-Long -Bytes $bytesBaseInfo -Index $Map.PDATA) + [long]$Map.OUTHASH1)
$Map.R1[0] = Convert-Int32 -Value (Get-Long -Bytes $bytesBaseInfo -Index ($Map.PDATA + 4))
$Map.PDATA = $Map.PDATA + 8
$Map.R2[0] = Convert-Int32 -Value (($Map.R0 * ([long]$Map.MD51)) - (0x10FA9605L * ((Get-ShiftRight -iValue $Map.R0 -iCount 16))))
$Map.R2[1] = Convert-Int32 -Value ((0x79F8A395L * ([long]$Map.R2[0])) + (0x689B6B9FL * (Get-ShiftRight -iValue $Map.R2[0] -iCount 16)))
$Map.R3 = Convert-Int32 -Value ((0xEA970001L * $Map.R2[1]) - (0x3C101569L * (Get-ShiftRight -iValue $Map.R2[1] -iCount 16) ))
$Map.R4[0] = Convert-Int32 -Value ($Map.R3 + $Map.R1[0])
$Map.R5[0] = Convert-Int32 -Value ($Map.CACHE + $Map.R3)
$Map.R6[0] = Convert-Int32 -Value (($Map.R4[0] * [long]$Map.MD52) - (0x3CE8EC25L * (Get-ShiftRight -iValue $Map.R4[0] -iCount 16)))
$Map.R6[1] = Convert-Int32 -Value ((0x59C3AF2DL * $Map.R6[0]) - (0x2232E0F1L * (Get-ShiftRight -iValue $Map.R6[0] -iCount 16)))
$Map.OUTHASH1 = Convert-Int32 -Value ((0x1EC90001L * $Map.R6[1]) + (0x35BD1EC9L * (Get-ShiftRight -iValue $Map.R6[1] -iCount 16)))
$Map.OUTHASH2 = Convert-Int32 -Value ([long]$Map.R5[0] + [long]$Map.OUTHASH1)
$Map.CACHE = ([long]$Map.OUTHASH2)
$Map.COUNTER = $Map.COUNTER - 1
}
[byte[]] $outHash = @(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
[byte[]] $buffer = [BitConverter]::GetBytes($Map.OUTHASH1)
$buffer.CopyTo($outHash, 0)
$buffer = [BitConverter]::GetBytes($Map.OUTHASH2)
$buffer.CopyTo($outHash, 4)
$Map = @{
PDATA = 0
CACHE = 0
COUNTER = 0
INDEX = 0
MD51 = 0
MD52 = 0
OUTHASH1 = 0
OUTHASH2 = 0
R0 = 0
R1 = @(0, 0)
R2 = @(0, 0)
R3 = 0
R4 = @(0, 0)
R5 = @(0, 0)
R6 = @(0, 0)
R7 = @(0, 0)
}
$Map.CACHE = 0
$Map.OUTHASH1 = 0
$Map.PDATA = 0
$Map.MD51 = ((Get-Long -Bytes $bytesMD5) -bor 1)
$Map.MD52 = ((Get-Long -Bytes $bytesMD5 4) -bor 1)
$Map.INDEX = Get-ShiftRight -iValue ($length - 2) -iCount 1
$Map.COUNTER = $Map.INDEX + 1
while ($Map.COUNTER)
{
$Map.R0 = Convert-Int32 -Value ((Get-Long -Bytes $bytesBaseInfo -Index $Map.PDATA) + ([long]$Map.OUTHASH1))
$Map.PDATA = $Map.PDATA + 8
$Map.R1[0] = Convert-Int32 -Value ($Map.R0 * [long]$Map.MD51)
$Map.R1[1] = Convert-Int32 -Value ((0xB1110000L * $Map.R1[0]) - (0x30674EEFL * (Get-ShiftRight -iValue $Map.R1[0] -iCount 16)))
$Map.R2[0] = Convert-Int32 -Value ((0x5B9F0000L * $Map.R1[1]) - (0x78F7A461L * (Get-ShiftRight -iValue $Map.R1[1] -iCount 16)))
$Map.R2[1] = Convert-Int32 -Value ((0x12CEB96DL * (Get-ShiftRight -iValue $Map.R2[0] 16)) - (0x46930000L * $Map.R2[0]))
$Map.R3 = Convert-Int32 -Value ((0x1D830000L * $Map.R2[1]) + (0x257E1D83L * (Get-ShiftRight -iValue $Map.R2[1] -iCount 16)))
$Map.R4[0] = Convert-Int32 -Value ([long]$Map.MD52 * ([long]$Map.R3 + (Get-Long -Bytes $bytesBaseInfo -Index ($Map.PDATA - 4))))
$Map.R4[1] = Convert-Int32 -Value ((0x16F50000L * $Map.R4[0]) - (0x5D8BE90BL * (Get-ShiftRight -iValue $Map.R4[0] -iCount 16)))
$Map.R5[0] = Convert-Int32 -Value ((0x96FF0000L * $Map.R4[1]) - (0x2C7C6901L * (Get-ShiftRight -iValue $Map.R4[1] -iCount 16)))
$Map.R5[1] = Convert-Int32 -Value ((0x2B890000L * $Map.R5[0]) + (0x7C932B89L * (Get-ShiftRight -iValue $Map.R5[0] -iCount 16)))
$Map.OUTHASH1 = Convert-Int32 -Value ((0x9F690000L * $Map.R5[1]) - (0x405B6097L * (Get-ShiftRight -iValue ($Map.R5[1]) -iCount 16)))
$Map.OUTHASH2 = Convert-Int32 -Value ([long]$Map.OUTHASH1 + $Map.CACHE + $Map.R3)
$Map.CACHE = ([long]$Map.OUTHASH2)
$Map.COUNTER = $Map.COUNTER - 1
}
$buffer = [BitConverter]::GetBytes($Map.OUTHASH1)
$buffer.CopyTo($outHash, 8)
$buffer = [BitConverter]::GetBytes($Map.OUTHASH2)
$buffer.CopyTo($outHash, 12)
[byte[]]$outHashBase = @(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
$hashValue1 = ((Get-Long -Bytes $outHash -Index 8) -bxor (Get-Long -Bytes $outHash))
$hashValue2 = ((Get-Long -Bytes $outHash 12) -bxor (Get-Long -Bytes $outHash -Index 4))
$buffer = [BitConverter]::GetBytes($hashValue1)
$buffer.CopyTo($outHashBase, 0)
$buffer = [BitConverter]::GetBytes($hashValue2)
$buffer.CopyTo($outHashBase, 4)
$base64Hash = [Convert]::ToBase64String($outHashBase)
}
return $base64Hash
}
# Get current user SID
$userSid = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
# Secret static string stored in %SystemRoot%\SysWOW64\shell32.dll
$userExperience = "User Choice set via Windows User Experience {D18B6DD5-6124-4341-9318-804003BAFA0B}"
$userDateTime = Get-HexDateTime
$baseInfo = "$Extension$userSid$ProgId$userDateTime$userExperience".ToLower()
$ProgHash = Get-Hash -BaseInfo $baseInfo
# Handle Extension
Write-ExtensionKeys -ProgId $ProgId -Extension $Extension -ProgHash $ProgHash
if ($Icon)
{
Set-Icon -ProgId $ProgId -Icon $Icon
}
}
Set-FTA -ProgId $ProgId -Extension $Extension -Icon $Icon
}
#endregion System
#region Start menu
<#
.SYNOPSIS
Configure recently added apps in the Start menu
.PARAMETER Hide
Hide recently added apps in the Start menu
.PARAMETER Show
Show recently added apps in the Start menu
.EXAMPLE
RecentlyAddedApps -Hide
.EXAMPLE
RecentlyAddedApps -Show
.NOTES
Machine-wide
#>
function RecentlyAddedApps
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer))
{
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Force
}
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecentlyAddedApps -PropertyType DWord -Value 1 -Force
}
"Show"
{
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecentlyAddedApps -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure app suggestions in the Start menu
.PARAMETER Hide
Hide app suggestions in the Start menu
.PARAMETER Show
Show app suggestions in the Start menu
.EXAMPLE
AppSuggestions -Hide
.EXAMPLE
AppSuggestions -Show
.NOTES
Current user
#>
function AppSuggestions
{
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-338388Enabled -PropertyType DWord -Value 0 -Force
}
"Show"
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-338388Enabled -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure how to run the Windows PowerShell shortcut
.PARAMETER Elevated
Run the Windows PowerShell shortcut from the Start menu as Administrator
.PARAMETER NonElevated
Run the Windows PowerShell shortcut from the Start menu as user
.EXAMPLE
RunPowerShellShortcut -Elevated
.EXAMPLE
RunPowerShellShortcut -NonElevated
.NOTES
Current user
#>
function RunPowerShellShortcut
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Elevated"
)]
[switch]
$Elevated,
[Parameter(
Mandatory = $true,
ParameterSetName = "NonElevated"
)]
[switch]
$NonElevated
)
switch ($PSCmdlet.ParameterSetName)
{
"Elevated"
{
[byte[]]$bytes = Get-Content -Path "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell.lnk" -Encoding Byte -Raw
$bytes[0x15] = $bytes[0x15] -bor 0x20
Set-Content -Path "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell.lnk" -Value $bytes -Encoding Byte -Force
}
"NonElevated"
{
[byte[]]$bytes = Get-Content -Path "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell.lnk" -Encoding Byte -Raw
$bytes[0x15] = $bytes[0x15] -bxor 0x20
Set-Content -Path "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell.lnk" -Value $bytes -Encoding Byte -Force
}
}
}
#endregion Start menu
#region Gaming
<#
.SYNOPSIS
Configure Xbox Game Bar
.PARAMETER Disable
Disable Xbox Game Bar
.PARAMETER Enable
Enable Xbox Game Bar
.EXAMPLE
XboxGameBar -Disable
.EXAMPLE
XboxGameBar -Enable
.NOTES
Current user
#>
function XboxGameBar
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if ((Get-AppxPackage -Name Microsoft.XboxGamingOverlay) -or (Get-AppxPackage -Name Microsoft.GamingApp))
{
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"
{
if ((Get-AppxPackage -Name Microsoft.XboxGamingOverlay) -or (Get-AppxPackage -Name Microsoft.GamingApp))
{
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
}
}
}
}
<#
.SYNOPSIS
Configure Xbox Game Bar tips
.PARAMETER Disable
Disable Xbox Game Bar tips
.PARAMETER Enable
Enable Xbox Game Bar tips
.EXAMPLE
XboxGameTips -Disable
.EXAMPLE
XboxGameTips -Enable
.NOTES
Current user
#>
function XboxGameTips
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if ((Get-AppxPackage -Name Microsoft.XboxGamingOverlay) -or (Get-AppxPackage -Name Microsoft.GamingApp))
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\GameBar -Name ShowStartupPanel -PropertyType DWord -Value 0 -Force
}
}
"Enable"
{
if ((Get-AppxPackage -Name Microsoft.XboxGamingOverlay) -or (Get-AppxPackage -Name Microsoft.GamingApp))
{
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\GameBar -Name ShowStartupPanel -PropertyType DWord -Value 1 -Force
}
}
}
}
<#
.SYNOPSIS
Choose an app to set "High performance" graphics preference
.NOTES
Only with a dedicated GPU
Current user
#>
function SetAppGraphicsPerformance
{
if (Get-CimInstance -ClassName Win32_VideoController | Where-Object -FilterScript {$_.AdapterDACType -ne "Internal" -and $null -ne $_.AdapterDACType})
{
$Title = $Localization.GraphicsPerformanceTitle
$Message = $Localization.GraphicsPerformanceRequest
$Add = $Localization.Add
$Skip = $Localization.Skip
$Options = "&$Add", "&$Skip"
$DefaultChoice = 1
do
{
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$OpenFileDialog = New-Object -TypeName System.Windows.Forms.OpenFileDialog
$OpenFileDialog.Filter = $Localization.EXEFilesFilter
$OpenFileDialog.InitialDirectory = "${env:ProgramFiles(x86)}"
$OpenFileDialog.Multiselect = $false
# Focus on open file dialog
$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
Write-Verbose -Message ("{0}" -f $OpenFileDialog.FileName) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
}
until ($Result -eq 1)
}
}
#endregion Gaming
#region Scheduled tasks
<#
.SYNOPSIS
The "Windows Cleanup" scheduled task for cleaning up unused files and Windows updates
.PARAMETER Register
Create the "Windows Cleanup" scheduled task for cleaning up unused files and Windows updates
.PARAMETER Delete
Delete the "Windows Cleanup" scheduled task for cleaning up unused files and Windows updates
.EXAMPLE
CleanUpTask -Register
.EXAMPLE
CleanUpTask -Delete
.NOTES
A minute before the task starts, a warning in the Windows action center will appear
Current user
The task runs every 90 days
#>
function CleanUpTask
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Register"
)]
[switch]
$Register,
[Parameter(
Mandatory = $true,
ParameterSetName = "Delete"
)]
[switch]
$Delete
)
switch ($PSCmdlet.ParameterSetName)
{
"Register"
{
Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches | ForEach-Object -Process {
Remove-ItemProperty -Path $_.PsPath -Name StateFlags1337 -Force -ErrorAction Ignore
}
$VolumeCaches = @(
# Delivery Optimization Files
# Файлы оптимизации доставки
"Delivery Optimization Files",
# Device driver packages
# Пакеты драйверов устройств
"Device Driver Packages",
# Previous Windows Installation(s)
# Предыдущие установки Windows
"Previous Installations",
# Setup log files
# Файлы журнала установки
"Setup Log Files",
# Temporary Setup Files
# Временные файлы установки
"Temporary Setup Files",
# Windows Defender
"Windows Defender",
# Windows upgrade log files
# Файлы журнала обновления Windows
"Windows Upgrade Log Files"
)
foreach ($VolumeCache in $VolumeCaches)
{
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\$VolumeCache" -Name StateFlags1337 -PropertyType DWord -Value 2 -Force
}
$TaskScript = @"
`$cleanmgr = """{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\cleanmgr.exe"""
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
`$Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
`$ToastXML = [xml]`$Template.GetXml()
`$ToastXML.GetElementsByTagName("""text""").AppendChild(`$ToastXML.CreateTextNode("""$($Localization.CleanUpTaskToast)"""))
`$XML = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument
`$XML.LoadXml(`$ToastXML.OuterXml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier(`$cleanmgr).Show(`$XML)
Get-Process -Name cleanmgr | Stop-Process -Force
Start-Sleep -Seconds 60
`$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo
`$ProcessInfo.FileName = """$env:SystemRoot\system32\cleanmgr.exe"""
`$ProcessInfo.Arguments = """/sagerun:1337"""
`$ProcessInfo.UseShellExecute = `$true
`$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized
`$Process = New-Object -TypeName System.Diagnostics.Process
`$Process.StartInfo = `$ProcessInfo
`$Process.Start() | Out-Null
Start-Sleep -Seconds 3
[int]`$SourceMainWindowHandle = (Get-Process -Name cleanmgr | Where-Object -FilterScript {`$_.PriorityClass -eq """BelowNormal"""}).MainWindowHandle
function MinimizeWindow
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = `$true)]
`$Process
)
`$ShowWindowAsync = @{
Namespace = """WinAPI"""
Name = """Win32ShowWindowAsync"""
Language = """CSharp"""
MemberDefinition = @'
[DllImport("""user32.dll""")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
'@
}
if (-not ("""WinAPI.Win32ShowWindowAsync""" -as [type]))
{
Add-Type @ShowWindowAsync
}
`$MainWindowHandle = (Get-Process -Name `$Process | Where-Object -FilterScript {`$_.PriorityClass -eq """BelowNormal"""}).MainWindowHandle
[WinAPI.Win32ShowWindowAsync]::ShowWindowAsync(`$MainWindowHandle, 2)
}
while (`$true)
{
[int]`$CurrentMainWindowHandle = (Get-Process -Name cleanmgr | Where-Object -FilterScript {`$_.PriorityClass -eq """BelowNormal"""}).MainWindowHandle
if (`$SourceMainWindowHandle -ne `$CurrentMainWindowHandle)
{
MinimizeWindow -Process cleanmgr
break
}
Start-Sleep -Milliseconds 5
}
`$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo
`$ProcessInfo.FileName = """`$env:SystemRoot\system32\dism.exe"""
`$ProcessInfo.Arguments = """/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart"""
`$ProcessInfo.UseShellExecute = `$true
`$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized
`$Process = New-Object -TypeName System.Diagnostics.Process
`$Process.StartInfo = `$ProcessInfo
`$Process.Start() | Out-Null
"@
$Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $TaskScript"
$Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 90 -At 9am
$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable
$Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
$Description = $Localization.CleanUpTaskDescription
$Parameters = @{
"TaskName" = "Windows Cleanup"
"TaskPath" = "Sophia Script"
"Principal" = $Principal
"Action" = $Action
"Description" = $Description
"Settings" = $Settings
"Trigger" = $Trigger
}
Register-ScheduledTask @Parameters -Force
}
"Delete"
{
Unregister-ScheduledTask -TaskName "Windows Cleanup" -Confirm:$false
}
}
}
<#
.SYNOPSIS
The "SoftwareDistribution" scheduled task for cleaning up the %SystemRoot%\SoftwareDistribution\Download folder
.PARAMETER Register
Create the "SoftwareDistribution" scheduled task for cleaning up the %SystemRoot%\SoftwareDistribution\Download folder
.PARAMETER Delete
Delete the "SoftwareDistribution" scheduled task for cleaning up the %SystemRoot%\SoftwareDistribution\Download folder
.EXAMPLE
SoftwareDistributionTask -Register
.EXAMPLE
SoftwareDistributionTask -Delete
.NOTES
The task runs on Thursdays every 4 weeks
Current user
#>
function SoftwareDistributionTask
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Register"
)]
[switch]
$Register,
[Parameter(
Mandatory = $true,
ParameterSetName = "Delete"
)]
[switch]
$Delete
)
switch ($PSCmdlet.ParameterSetName)
{
"Register"
{
$Argument = @"
(Get-Service -Name wuauserv).WaitForStatus('Stopped', '01:00:00')
Get-ChildItem -Path $env:SystemRoot\SoftwareDistribution\Download -Recurse -Force | Remove-Item -Recurse -Force
"@
$Action = New-ScheduledTaskAction -Execute powershell.exe -Argument $Argument
$Trigger = New-JobTrigger -Weekly -WeeksInterval 4 -DaysOfWeek Thursday -At 9am
$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable
$Principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -RunLevel Highest
$Description = $Localization.FolderTaskDescription -f "$env:SystemRoot\SoftwareDistribution\Download"
$Parameters = @{
"TaskName" = "SoftwareDistribution"
"TaskPath" = "Sophia Script"
"Principal" = $Principal
"Action" = $Action
"Description" = $Description
"Settings" = $Settings
"Trigger" = $Trigger
}
Register-ScheduledTask @Parameters -Force
}
"Delete"
{
Unregister-ScheduledTask -TaskName SoftwareDistribution -Confirm:$false
}
}
}
<#
.SYNOPSIS
The "Temp" scheduled task for cleaning up the %TEMP% folder
.PARAMETER Register
Create the "Temp" scheduled task for cleaning up the %TEMP% folder
.PARAMETER Delete
Delete the "Temp" scheduled task for cleaning up the %TEMP% folder
.EXAMPLE
TempTask -Register
.EXAMPLE
TempTask -Delete
.NOTES
The task runs every 62 days
Current user
#>
function TempTask
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Register"
)]
[switch]
$Register,
[Parameter(
Mandatory = $true,
ParameterSetName = "Delete"
)]
[switch]
$Delete
)
switch ($PSCmdlet.ParameterSetName)
{
"Register"
{
$Argument = "Get-ChildItem -Path $env:TEMP -Force -Recurse | Remove-Item -Recurse -Force"
$Action = New-ScheduledTaskAction -Execute powershell.exe -Argument $Argument
$Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 62 -At 9am
$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable
$Principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -RunLevel Highest
$Description = $Localization.FolderTaskDescription
$Parameters = @{
"TaskName" = "Temp"
"TaskPath" = "Sophia Script"
"Principal" = $Principal
"Action" = $Action
"Description" = $Description
"Settings" = $Settings
"Trigger" = $Trigger
}
Register-ScheduledTask @Parameters -Force
}
"Delete"
{
Unregister-ScheduledTask -TaskName Temp -Confirm:$false
}
}
}
#endregion Scheduled tasks
#region Windows Defender & Security
# Enable Controlled folder access and add protected folders
function AddProtectedFolders
{
$Title = $Localization.ControlledFolderAccess
$Message = $Localization.ProtectedFoldersRequest
$Add = $Localization.Add
$Skip = $Localization.Skip
$Options = "&$Add", "&$Skip"
$DefaultChoice = 1
do
{
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowserDialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
if ($FolderBrowserDialog.SelectedPath)
{
Set-MpPreference -EnableControlledFolderAccess Enabled
Add-MpPreference -ControlledFolderAccessProtectedFolders $FolderBrowserDialog.SelectedPath -Force
Write-Verbose -Message ("{0}" -f $FolderBrowserDialog.SelectedPath) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
}
until ($Result -eq 1)
}
# Remove all added protected folders
function RemoveProtectedFolders
{
if ($null -ne (Get-MpPreference).ControlledFolderAccessProtectedFolders)
{
(Get-MpPreference).ControlledFolderAccessProtectedFolders | Format-Table -AutoSize -Wrap
Remove-MpPreference -ControlledFolderAccessProtectedFolders (Get-MpPreference).ControlledFolderAccessProtectedFolders -Force
Write-Verbose -Message $Localization.ProtectedFoldersListRemoved -Verbose
}
}
# Allow an app through Controlled folder access
function AddAppControlledFolder
{
$Title = $Localization.ControlledFolderAccess
$Message = $Localization.AppControlledFolderRequest
$Add = $Localization.Add
$Skip = $Localization.Skip
$Options = "&$Add", "&$Skip"
$DefaultChoice = 1
do
{
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$OpenFileDialog = New-Object -TypeName System.Windows.Forms.OpenFileDialog
$OpenFileDialog.Filter = $Localization.EXEFilesFilter
$OpenFileDialog.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
$OpenFileDialog.Multiselect = $false
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$OpenFileDialog.ShowDialog($Focus)
if ($OpenFileDialog.FileName)
{
Add-MpPreference -ControlledFolderAccessAllowedApplications $OpenFileDialog.FileName -Force
Write-Verbose -Message ("{0}" -f $OpenFileDialog.FileName) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
}
until ($Result -eq 1)
}
# Remove all allowed apps through Controlled folder access
function RemoveAllowedAppsControlledFolder
{
if ($null -ne (Get-MpPreference).ControlledFolderAccessAllowedApplications)
{
(Get-MpPreference).ControlledFolderAccessAllowedApplications | Format-Table -AutoSize -Wrap
Remove-MpPreference -ControlledFolderAccessAllowedApplications (Get-MpPreference).ControlledFolderAccessAllowedApplications -Force
Write-Verbose -Message $Localization.AllowedControlledFolderAppsRemoved -Verbose
}
}
# Add a folder to the exclusion from Windows Defender scanning
function AddDefenderExclusionFolder
{
$Title = $Localization.DefenderTitle
$Message = $Localization.DefenderExclusionFolderRequest
$Add = $Localization.Add
$Skip = $Localization.Skip
$Options = "&$Add", "&$Skip"
$DefaultChoice = 1
do
{
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowserDialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
if ($FolderBrowserDialog.SelectedPath)
{
Add-MpPreference -ExclusionPath $FolderBrowserDialog.SelectedPath -Force
Write-Verbose -Message ("{0}" -f $FolderBrowserDialog.SelectedPath) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
}
until ($Result -eq 1)
}
# Remove all excluded folders from Windows Defender scanning
function RemoveDefenderExclusionFolders
{
if ($null -ne (Get-MpPreference).ExclusionPath)
{
$ExcludedFolders = (Get-Item -Path (Get-MpPreference).ExclusionPath -Force -ErrorAction Ignore | Where-Object -FilterScript {$_.Attributes -match "Directory"}).FullName
$ExcludedFolders | Format-Table -AutoSize -Wrap
Remove-MpPreference -ExclusionPath $ExcludedFolders -Force
Write-Verbose -Message $Localization.DefenderExclusionFoldersListRemoved -Verbose
}
}
# Add a file to the exclusion from Windows Defender scanning
function AddDefenderExclusionFile
{
$Title = "Windows Defender"
$Message = $Localization.AddDefenderExclusionFileRequest
$Add = $Localization.Add
$Skip = $Localization.Skip
$Options = "&$Add", "&$Skip"
$DefaultChoice = 1
do
{
$Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice)
switch ($Result)
{
"0"
{
Add-Type -AssemblyName System.Windows.Forms
$OpenFileDialog = New-Object -TypeName System.Windows.Forms.OpenFileDialog
$OpenFileDialog.Filter = $Localization.AllFilesFilter
$OpenFileDialog.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
$OpenFileDialog.Multiselect = $false
# Focus on open file dialog
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$OpenFileDialog.ShowDialog($Focus)
if ($OpenFileDialog.FileName)
{
Add-MpPreference -ExclusionPath $OpenFileDialog.FileName -Force
Write-Verbose -Message ("{0}" -f $OpenFileDialog.FileName) -Verbose
}
}
"1"
{
Write-Verbose -Message $Localization.Skipped -Verbose
}
}
}
until ($Result -eq 1)
}
# Remove all excluded files from Windows Defender scanning
function RemoveDefenderExclusionFiles
{
if ($null -ne (Get-MpPreference).ExclusionPath)
{
$ExcludedFiles = (Get-Item -Path (Get-MpPreference).ExclusionPath -Force -ErrorAction Ignore | Where-Object -FilterScript {$_.Attributes -notmatch "Directory"}).FullName
$ExcludedFiles | Format-Table -AutoSize -Wrap
Remove-MpPreference -ExclusionPath $ExcludedFiles -Force
Write-Verbose -Message $Localization.DefenderExclusionFilesRemoved -Verbose
}
}
<#
.SYNOPSIS
Configure Windows Defender Exploit Guard network protection
.PARAMETER Disable
Disable Windows Defender Exploit Guard network protection
.PARAMETER Enable
Enable Windows Defender Exploit Guard network protection
.EXAMPLE
NetworkProtection -Disable
.EXAMPLE
NetworkProtection -Enable
Current user
#>
function NetworkProtection
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
Set-MpPreference -EnableNetworkProtection Disabled
}
"Enable"
{
Set-MpPreference -EnableNetworkProtection Enabled
}
}
}
<#
.SYNOPSIS
Configure detection for potentially unwanted applications and block them
.PARAMETER Disable
Enable/disable detection for potentially unwanted applications and block them
.PARAMETER Enable
Enable/disable detection for potentially unwanted applications and block them
.EXAMPLE
PUAppsDetection -Disable
.EXAMPLE
PUAppsDetection -Enable
Current user
#>
function PUAppsDetection
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
Set-MpPreference -PUAProtection Disabled
}
"Enable"
{
Set-MpPreference -PUAProtection Enabled
}
}
}
<#
.SYNOPSIS
Configure sandboxing for Windows Defender
.PARAMETER Disable
Disable sandboxing for Windows Defender
.PARAMETER Enable
Enable sandboxing for Windows Defender
.EXAMPLE
DefenderSandbox -Disable
.EXAMPLE
DefenderSandbox -Enable
.NOTES
There is a bug in KVM with QEMU: enabling this function causes VM to freeze up during the loading phase of Windows
Current user
#>
function DefenderSandbox
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
setx /M MP_FORCE_USE_SANDBOX 0
}
"Enable"
{
setx /M MP_FORCE_USE_SANDBOX 1
}
}
}
# Dismiss Windows Defender offer in the Windows Security about signing in Microsoft account
function DismissMSAccount
{
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows Security Health\State" -Name AccountProtection_MicrosoftAccount_Disconnected -PropertyType DWord -Value 1 -Force
}
# Dismiss Windows Defender offer in the Windows Security about turning on the SmartScreen filter for Microsoft Edge
function DismissSmartScreenFilter
{
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows Security Health\State" -Name AppAndBrowser_EdgeSmartScreenOff -PropertyType DWord -Value 0 -Force
}
<#
.SYNOPSIS
Configure events auditing generated when a process is created or starts
.PARAMETER Disable
Disable events auditing generated when a process is created or starts
.PARAMETER Enable
Enable events auditing generated when a process is created or starts
.EXAMPLE
AuditProcess -Disable
.EXAMPLE
AuditProcess -Enable
Machine-wide
#>
function AuditProcess
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
auditpol /set /subcategory:"{0CCE922B-69AE-11D9-BED3-505054503030}" /success:disable /failure:disable
}
"Enable"
{
auditpol /set /subcategory:"{0CCE922B-69AE-11D9-BED3-505054503030}" /success:enable /failure:enable
}
}
}
<#
.SYNOPSIS
Configure command line in process creation events
.PARAMETER Disable
Do not include command line in process creation events
.PARAMETER Enable
Include command line in process creation events
.EXAMPLE
AuditCommandLineProcess -Disable
.EXAMPLE
AuditCommandLineProcess -Enable
.NOTES
In order this feature to work events auditing ("AuditProcess -Enable" function) will be enabled
Machine-wide
#>
function AuditCommandLineProcess
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit -Name ProcessCreationIncludeCmdLine_Enabled -Force -ErrorAction SilentlyContinue
}
"Enable"
{
# Enable events auditing generated when a process is created or starts
auditpol /set /subcategory:"{0CCE922B-69AE-11D9-BED3-505054503030}" /success:enable /failure:enable
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit -Name ProcessCreationIncludeCmdLine_Enabled -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure "Process Creation" Event Viewer Custom View
.PARAMETER Disable
Remove "Process Creation" Event Viewer Custom View
.PARAMETER Enable
Create "Process Creation" Event Viewer Custom View
.EXAMPLE
EventViewerCustomView -Disable
.EXAMPLE
EventViewerCustomView -Enable
.NOTES
In order this feature to work events auditing ("AuditProcess -Enable" function) and command line in process creation events will be enabled
Machine-wide
#>
function EventViewerCustomView
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
Remove-Item -Path "$env:ProgramData\Microsoft\Event Viewer\Views\ProcessCreation.xml" -Force -ErrorAction SilentlyContinue
}
"Enable"
{
# Enable events auditing generated when a process is created or 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
$XML = @"
<ViewerConfig>
<QueryConfig>
<QueryParams>
<UserQuery />
</QueryParams>
<QueryNode>
<Name>$($Localization.EventViewerCustomViewName)</Name>
<Description>$($Localization.EventViewerCustomViewDescription)</Description>
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4688)]]</Select>
</Query>
</QueryList>
</QueryNode>
</QueryConfig>
</ViewerConfig>
"@
if (-not (Test-Path -Path "$env:ProgramData\Microsoft\Event Viewer\Views"))
{
New-Item -Path "$env:ProgramData\Microsoft\Event Viewer\Views" -ItemType Directory -Force
}
# Saving ProcessCreation.xml in UTF-8 encoding
Set-Content -Path "$env:ProgramData\Microsoft\Event Viewer\Views\ProcessCreation.xml" -Value $XML -Encoding Default -Force
}
}
}
<#
.SYNOPSIS
Configure logging for all Windows PowerShell modules
.PARAMETER Disable
Disable logging for all Windows PowerShell modules
.PARAMETER Enable
Enable logging for all Windows PowerShell modules
.EXAMPLE
PowerShellModulesLogging -Disable
.EXAMPLE
PowerShellModulesLogging -Enable
Machine-wide
#>
function PowerShellModulesLogging
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames -Name * -Force -ErrorAction SilentlyContinue
}
"Enable"
{
if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames))
{
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames -Force
}
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames -Name * -PropertyType String -Value * -Force
}
}
}
<#
.SYNOPSIS
Configure logging for all PowerShell scripts input to the Windows PowerShell event log
.PARAMETER Disable
Disable logging for all PowerShell scripts input to the Windows PowerShell event log
.PARAMETER Enable
Enable logging for all PowerShell scripts input to the Windows PowerShell event log
.EXAMPLE
PowerShellScriptsLogging -Disable
.EXAMPLE
PowerShellScriptsLogging -Enable
Machine-wide
#>
function PowerShellScriptsLogging
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Force -ErrorAction SilentlyContinue
}
"Enable"
{
if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging))
{
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Force
}
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -PropertyType DWord -Value 1 -Force
}
}
}
<#
.SYNOPSIS
Configure apps and files checking within Microsofot Defender SmartScreen
.PARAMETER Disable
Disable apps and files checking within Microsofot Defender SmartScreen
.PARAMETER Enable
Enable apps and files checking within Microsofot Defender SmartScreen
.EXAMPLE
AppsSmartScreen -Disable
.EXAMPLE
AppsSmartScreen -Enable
Machine-wide
#>
function AppsSmartScreen
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
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
}
}
}
<#
.SYNOPSIS
Configure the Attachment Manager marking files that have been downloaded from the Internet as unsafe
.PARAMETER Disable
Disable the Attachment Manager marking files that have been downloaded from the Internet as unsafe
.PARAMETER Enable
Enable the Attachment Manager marking files that have been downloaded from the Internet as unsafe
.EXAMPLE
SaveZoneInformation -Disable
.EXAMPLE
SaveZoneInformation -Enable
.NOTES
Current user
#>
function SaveZoneInformation
{
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\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
}
"Enable"
{
Remove-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Attachments -Name SaveZoneInformation -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure Windows Script Host
.PARAMETER Disable
Disable Windows Script Host
.PARAMETER Enable
Enable Windows Script Host
.EXAMPLE
WindowsScriptHost -Disable
.EXAMPLE
WindowsScriptHost -Enable
.NOTES
Blocks WSH from executing .js and .vbs files
Current user
#>
function WindowsScriptHost
{
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\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 SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure Windows Sandbox
.PARAMETER Disable
Disable Windows Sandbox
.PARAMETER Enable
Enable Windows Sandbox
.EXAMPLE
WindowsSandbox -Disable
.EXAMPLE
WindowsSandbox -Enable
Current user
#>
function WindowsSandbox
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Disable"
)]
[switch]
$Disable,
[Parameter(
Mandatory = $true,
ParameterSetName = "Enable"
)]
[switch]
$Enable
)
switch ($PSCmdlet.ParameterSetName)
{
"Disable"
{
if (Get-WindowsEdition -Online | Where-Object -FilterScript {$_.Edition -eq "Professional" -or $_.Edition -like "Enterprise*"})
{
# Checking whether x86 virtualization is enabled in the firmware
if ((Get-CimInstance -ClassName CIM_Processor).VirtualizationFirmwareEnabled -eq $true)
{
Disable-WindowsOptionalFeature -FeatureName Containers-DisposableClientVM -Online -NoRestart
}
else
{
try
{
# Determining whether Hyper-V is enabled
if ((Get-CimInstance -ClassName CIM_ComputerSystem).HypervisorPresent -eq $true)
{
Disable-WindowsOptionalFeature -FeatureName Containers-DisposableClientVM -Online -NoRestart
}
}
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
}
}
}
}
"Enable"
{
if (Get-WindowsEdition -Online | Where-Object -FilterScript {$_.Edition -eq "Professional" -or $_.Edition -like "Enterprise*"})
{
# Checking whether x86 virtualization is enabled in the firmware
if ((Get-CimInstance -ClassName CIM_Processor).VirtualizationFirmwareEnabled -eq $true)
{
Enable-WindowsOptionalFeature -FeatureName Containers-DisposableClientVM -All -Online -NoRestart
}
else
{
try
{
# Determining whether Hyper-V is enabled
if ((Get-CimInstance -ClassName CIM_ComputerSystem).HypervisorPresent -eq $true)
{
Enable-WindowsOptionalFeature -FeatureName Containers-DisposableClientVM -All -Online -NoRestart
}
}
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
}
}
}
}
}
}
#endregion Windows Defender & Security
#region Context menu
<#
.SYNOPSIS
Configure the "Extract all" item in Windows Installer (.msi) context menu
.PARAMETER Remove
Remove the "Extract all" item to Windows Installer (.msi) context menu
.PARAMETER Add
Add the "Extract all" item to Windows Installer (.msi) context menu
.EXAMPLE
MSIExtractContext -Remove
.EXAMPLE
MSIExtractContext -Add
Current user
#>
function MSIExtractContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Remove"
)]
[switch]
$Remove,
[Parameter(
Mandatory = $true,
ParameterSetName = "Add"
)]
[switch]
$Add
)
switch ($PSCmdlet.ParameterSetName)
{
"Remove"
{
Remove-Item -Path Registry::HKEY_CLASSES_ROOT\Msi.Package\shell\Extract -Recurse -Force -ErrorAction SilentlyContinue
}
"Add"
{
if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\Msi.Package\shell\Extract\Command))
{
New-Item -Path Registry::HKEY_CLASSES_ROOT\Msi.Package\shell\Extract\Command -Force
}
$Value = "{0}" -f 'msiexec.exe /a "%1" /qb TARGETDIR="%1 extracted"'
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Msi.Package\shell\Extract\Command -Name "(Default)" -PropertyType String -Value $Value -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Msi.Package\shell\Extract -Name MUIVerb -PropertyType String -Value "@shell32.dll,-37514" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Msi.Package\shell\Extract -Name Icon -PropertyType String -Value "shell32.dll,-16817" -Force
}
}
}
<#
.SYNOPSIS
Configure the "Install" item in the .cab archives context menu
.PARAMETER Remove
Remove the "Install" item to the .cab archives context menu
.PARAMETER Add
Add the "Install" item to the .cab archives context menu
.EXAMPLE
CABInstallContext -Remove
.EXAMPLE
CABInstallContext -Add
Current user
#>
function CABInstallContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Remove"
)]
[switch]
$Remove,
[Parameter(
Mandatory = $true,
ParameterSetName = "Add"
)]
[switch]
$Add
)
switch ($PSCmdlet.ParameterSetName)
{
"Remove"
{
Remove-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\RunAs\Command -Recurse -Force -ErrorAction SilentlyContinue
}
"Add"
{
if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\RunAs\Command))
{
New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\RunAs\Command -Force
}
$Value = "{0}" -f "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause"
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\RunAs\Command -Name "(Default)" -PropertyType String -Value $Value -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\RunAs -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\RunAs -Name HasLUAShield -PropertyType String -Value "" -Force
}
}
}
<#
.SYNOPSIS
Configure the "Run as different user" item in the .exe files types context menu
.PARAMETER Remove
Remove the "Run as different user" item to the .exe files types context menu
.PARAMETER Add
Add the "Run as different user" item to the .exe files types context menu
.EXAMPLE
RunAsDifferentUserContext -Remove
.EXAMPLE
RunAsDifferentUserContext -Add
Current user
#>
function RunAsDifferentUserContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Remove"
)]
[switch]
$Remove,
[Parameter(
Mandatory = $true,
ParameterSetName = "Add"
)]
[switch]
$Add
)
switch ($PSCmdlet.ParameterSetName)
{
"Remove"
{
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\exefile\shell\runasuser -Name Extended -PropertyType String -Value "" -Force
}
"Add"
{
Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\exefile\shell\runasuser -Name Extended -Force -ErrorAction Ignore
}
}
}
<#
.SYNOPSIS
Configure the "Cast to Device" item in the context menu
.PARAMETER Hide
Hide the "Cast to Device" item from the context menu
.PARAMETER Show
Show the "Cast to Device" item from the context menu
.EXAMPLE
CastToDeviceContext -Hide
.EXAMPLE
CastToDeviceContext -Show
Current user
#>
function CastToDeviceContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked"))
{
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Force
}
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Name "{7AD84985-87B4-4a16-BE58-8B72A5B390F7}" -PropertyType String -Value "Play to menu" -Force
}
"Show"
{
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Name "{7AD84985-87B4-4a16-BE58-8B72A5B390F7}" -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the "Share" item in the context menu
.PARAMETER Hide
Hide the "Share" item from the context menu
.PARAMETER Show
Show the "Share" item in the context menu
.EXAMPLE
ShareContext -Hide
.EXAMPLE
ShareContext -Show
Current user
#>
function ShareContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked"))
{
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Force
}
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Name "{E2BF9676-5F8F-435C-97EB-11607A5BEDF7}" -PropertyType String -Value "" -Force
}
"Show"
{
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Name "{E2BF9676-5F8F-435C-97EB-11607A5BEDF7}" -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the "Edit with Paint 3D" item in the context menu
.PARAMETER Hide
Hide the "Edit with Paint 3D" item from the context menu
.PARAMETER Show
Show the "Edit with Paint 3D" item in the context menu
.EXAMPLE
EditWithPaint3DContext -Hide
.EXAMPLE
EditWithPaint3DContext -Show
Current user
#>
function EditWithPaint3DContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
$Extensions = @(".bmp", ".gif", ".jpe", ".jpeg", ".jpg", ".png", ".tif", ".tiff")
foreach ($extension in $extensions)
{
New-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\$Extension\Shell\3D Edit" -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
}
}
"Show"
{
$Extensions = @(".bmp", ".gif", ".jpe", ".jpeg", ".jpg", ".png", ".tif", ".tiff")
foreach ($Extension in $Extensions)
{
Remove-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\$Extension\Shell\3D Edit" -Name ProgrammaticAccessOnly -Force -ErrorAction SilentlyContinue
}
}
}
}
<#
.SYNOPSIS
Configure the "Print" item in the .bat and .cmd context menu
.PARAMETER Hide
Hide the "Print" item from the .bat and .cmd context menu
.PARAMETER Show
Show the "Print" item in the .bat and .cmd context menu
.EXAMPLE
PrintCMDContext -Hide
.EXAMPLE
PrintCMDContext -Show
Current user
#>
function PrintCMDContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\batfile\shell\print -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\cmdfile\shell\print -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
}
"Show"
{
Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\batfile\shell\print -Name ProgrammaticAccessOnly -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\cmdfile\shell\print -Name ProgrammaticAccessOnly -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the "Include in Library" item in the context menu
.PARAMETER Hide
Hide the "Include in Library" item from the context menu
.PARAMETER Show
Show the "Include in Library" item in the context menu
.EXAMPLE
IncludeInLibraryContext -Hide
.EXAMPLE
IncludeInLibraryContext -Show
Current user
#>
function IncludeInLibraryContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\Library Location" -Name "(Default)" -PropertyType String -Value "-{3dad6c5d-2167-4cae-9914-f99e41c12cfa}" -Force
}
"Show"
{
New-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\Library Location" -Name "(Default)" -PropertyType String -Value "{3dad6c5d-2167-4cae-9914-f99e41c12cfa}" -Force
}
}
}
<#
.SYNOPSIS
Configure the "Send to" item in the folders context menu
.PARAMETER Hide
Hide the "Send to" item from the folders context menu
.PARAMETER Show
Show the "Send to" item in the folders context menu
.EXAMPLE
SendToContext -Hide
.EXAMPLE
SendToContext -Show
Current user
#>
function SendToContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\SendTo -Name "(Default)" -PropertyType String -Value "-{7BA4C740-9E81-11CF-99D3-00AA004AE837}" -Force
}
"Show"
{
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\SendTo -Name "(Default)" -PropertyType String -Value "{7BA4C740-9E81-11CF-99D3-00AA004AE837}" -Force
}
}
}
<#
.SYNOPSIS
Configure the "Turn on BitLocker" item in the context menu
.PARAMETER Hide
Hide the "Turn on BitLocker" item from the context menu
.PARAMETER Show
Show the "Turn on BitLocker" item in the context menu
.EXAMPLE
BitLockerContext -Hide
.EXAMPLE
BitLockerContext -Show
Current user
#>
function BitLockerContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (Get-WindowsEdition -Online | Where-Object -FilterScript {$_.Edition -eq "Professional" -or $_.Edition -like "Enterprise*"})
{
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\encrypt-bde -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\encrypt-bde-elev -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\manage-bde -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\resume-bde -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\resume-bde-elev -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\unlock-bde -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force
}
}
"Show"
{
if (Get-WindowsEdition -Online | Where-Object -FilterScript {$_.Edition -eq "Professional" -or $_.Edition -like "Enterprise*"})
{
Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\encrypt-bde -Name ProgrammaticAccessOnly -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\encrypt-bde-elev -Name ProgrammaticAccessOnly -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\manage-bde -Name ProgrammaticAccessOnly -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\resume-bde -Name ProgrammaticAccessOnly -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\resume-bde-elev -Name ProgrammaticAccessOnly -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Drive\shell\unlock-bde -Name ProgrammaticAccessOnly -Force -ErrorAction SilentlyContinue
}
}
}
}
<#
.SYNOPSIS
Configure the "Bitmap image" item in the "New" context menu
.PARAMETER Remove
Remove the "Bitmap image" item from the "New" context menu
.PARAMETER Add
Add the "Bitmap image" item to the "New" context menu
.EXAMPLE
BitmapImageNewContext -Remove
.EXAMPLE
BitmapImageNewContext -Add
Current user
#>
function BitmapImageNewContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Remove"
)]
[switch]
$Remove,
[Parameter(
Mandatory = $true,
ParameterSetName = "Add"
)]
[switch]
$Add
)
switch ($PSCmdlet.ParameterSetName)
{
"Remove"
{
if ((Get-WindowsCapability -Online -Name "Microsoft.Windows.MSPaint*").State -eq "Installed")
{
Remove-Item -Path Registry::HKEY_CLASSES_ROOT\.bmp\ShellNew -Force -ErrorAction SilentlyContinue
}
}
"Add"
{
if ((Get-WindowsCapability -Online -Name "Microsoft.Windows.MSPaint*").State -eq "Installed")
{
if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\.bmp\ShellNew))
{
New-Item -Path Registry::HKEY_CLASSES_ROOT\.bmp\ShellNew -Force
}
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\.bmp\ShellNew -Name ItemName -PropertyType ExpandString -Value "@%systemroot%\system32\mspaint.exe,-59414" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\.bmp\ShellNew -Name NullFile -PropertyType String -Value "" -Force
}
else
{
try
{
if ((Invoke-WebRequest -Uri https://www.google.com -UseBasicParsing -DisableKeepAlive -Method Head).StatusDescription)
{
Get-WindowsCapability -Online -Name "Microsoft.Windows.MSPaint*" | Add-WindowsCapability -Online
}
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
return
}
}
}
}
}
<#
.SYNOPSIS
Configure the "Rich Text Document" item in the "New" context menu
.PARAMETER Remove
Remove the "Rich Text Document" item from the "New" context menu
.PARAMETER Add
Add the "Rich Text Document" item to the "New" context menu
.EXAMPLE
RichTextDocumentNewContext -Remove
.EXAMPLE
RichTextDocumentNewContext -Add
Current user
#>
function RichTextDocumentNewContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Remove"
)]
[switch]
$Remove,
[Parameter(
Mandatory = $true,
ParameterSetName = "Add"
)]
[switch]
$Add
)
switch ($PSCmdlet.ParameterSetName)
{
"Remove"
{
if ((Get-WindowsCapability -Online -Name "Microsoft.Windows.WordPad*").State -eq "Installed")
{
Remove-Item -Path Registry::HKEY_CLASSES_ROOT\.rtf\ShellNew -Force -ErrorAction Ignore
}
}
"Add"
{
if ((Get-WindowsCapability -Online -Name "Microsoft.Windows.WordPad*").State -eq "Installed")
{
if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\.rtf\ShellNew))
{
New-Item -Path Registry::HKEY_CLASSES_ROOT\.rtf\ShellNew -Force
}
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\.rtf\ShellNew -Name Data -PropertyType String -Value "{\rtf1}" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\.rtf\ShellNew -Name ItemName -PropertyType ExpandString -Value "@%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE,-213" -Force
}
else
{
try
{
if ((Invoke-WebRequest -Uri https://www.google.com -UseBasicParsing -DisableKeepAlive -Method Head).StatusDescription)
{
Get-WindowsCapability -Online -Name "Microsoft.Windows.WordPad*" | Add-WindowsCapability -Online
}
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
return
}
}
}
}
}
<#
.SYNOPSIS
Configure the "Compressed (zipped) Folder" item in the "New" context menu
.PARAMETER Remove
Remove the "Compressed (zipped) Folder" item from the "New" context menu
.PARAMETER Add
Add the "Compressed (zipped) Folder" item to the "New" context menu
.EXAMPLE
CompressedFolderNewContext -Remove
.EXAMPLE
CompressedFolderNewContext -Add
Current user
#>
function CompressedFolderNewContext
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Remove"
)]
[switch]
$Remove,
[Parameter(
Mandatory = $true,
ParameterSetName = "Add"
)]
[switch]
$Add
)
switch ($PSCmdlet.ParameterSetName)
{
"Remove"
{
Remove-Item -Path Registry::HKEY_CLASSES_ROOT\.zip\CompressedFolder\ShellNew -Force -ErrorAction Ignore
}
"Add"
{
if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\.zip\CompressedFolder\ShellNew))
{
New-Item -Path Registry::HKEY_CLASSES_ROOT\.zip\CompressedFolder\ShellNew -Force
}
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\.zip\CompressedFolder\ShellNew -Name Data -PropertyType Binary -Value ([byte[]](80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)) -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\.zip\CompressedFolder\ShellNew -Name ItemName -PropertyType ExpandString -Value "@%SystemRoot%\system32\zipfldr.dll,-10194" -Force
}
}
}
<#
.SYNOPSIS
Configure the "Open", "Print", and "Edit" context menu items for more than 15 items selected
.PARAMETER Enable
Enable the "Open", "Print", and "Edit" context menu items for more than 15 items selected
.PARAMETER Disable
Disable the "Open", "Print", and "Edit" context menu items for more than 15 items selected
.EXAMPLE
MultipleInvokeContext -Enable
.EXAMPLE
MultipleInvokeContext -Disable
Current user
#>
function MultipleInvokeContext
{
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 -Name MultipleInvokePromptMinimum -PropertyType DWord -Value 300 -Force
}
"Disable"
{
Remove-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name MultipleInvokePromptMinimum -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the "Look for an app in the Microsoft Store" item in the "Open with" dialog
.PARAMETER Hide
Hide the "Look for an app in the Microsoft Store" item in the "Open with" dialog
.PARAMETER Show
Show the "Look for an app in the Microsoft Store" item in the "Open with" dialog
.EXAMPLE
UseStoreOpenWith -Hide
.EXAMPLE
UseStoreOpenWith -Show
Current user
#>
function UseStoreOpenWith
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer))
{
New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Force
}
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -PropertyType DWord -Value 1 -Force
}
"Show"
{
Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -Force -ErrorAction SilentlyContinue
}
}
}
<#
.SYNOPSIS
Configure the "Previous Versions" tab in the files and folders context menu and the "Restore previous versions" context menu item
.PARAMETER Hide
Hide the "Previous Versions" tab from the files and folders context menu and the "Restore previous versions" context menu item
.PARAMETER Show
Show the "Previous Versions" tab from the files and folders context menu and the "Restore previous versions" context menu item
.EXAMPLE
PreviousVersionsPage -Hide
.EXAMPLE
PreviousVersionsPage -Show
Current user
#>
function PreviousVersionsPage
{
param
(
[Parameter(
Mandatory = $true,
ParameterSetName = "Hide"
)]
[switch]
$Hide,
[Parameter(
Mandatory = $true,
ParameterSetName = "Show"
)]
[switch]
$Show
)
switch ($PSCmdlet.ParameterSetName)
{
"Hide"
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name NoPreviousVersionsPage -PropertyType DWord -Value 1 -Force
}
"Show"
{
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name NoPreviousVersionsPage -Force -ErrorAction SilentlyContinue
}
}
}
#endregion Context menu
#region Refresh
function Refresh
{
$UpdateExplorer = @{
Namespace = "WinAPI"
Name = "UpdateExplorer"
Language = "CSharp"
MemberDefinition = @"
private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
private const int WM_SETTINGCHANGE = 0x1a;
private const int SMTO_ABORTIFHUNG = 0x0002;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern bool SendNotifyMessage(IntPtr hWnd, uint Msg, IntPtr wParam, string lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
private static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, IntPtr lpdwResult);
[DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = false)]
private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
public static void Refresh()
{
// Update desktop icons
SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
// Update environment variables
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, null, SMTO_ABORTIFHUNG, 100, IntPtr.Zero);
// Update taskbar
SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, "TraySettings");
}
private static readonly IntPtr hWnd = new IntPtr(65535);
private const int Msg = 273;
// Virtual key ID of the F5 in File Explorer
private static readonly UIntPtr UIntPtr = new UIntPtr(41504);
[DllImport("user32.dll", SetLastError=true)]
public static extern int PostMessageW(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
public static void PostMessage()
{
// Simulate pressing F5 to refresh the desktop
PostMessageW(hWnd, Msg, UIntPtr, IntPtr.Zero);
}
"@
}
if (-not ("WinAPI.UpdateExplorer" -as [type]))
{
Add-Type @UpdateExplorer
}
# Simulate pressing F5 to refresh the desktop
[WinAPI.UpdateExplorer]::PostMessage()
# Refresh desktop icons, environment variables, taskbar
[WinAPI.UpdateExplorer]::Refresh()
# Restart the Start menu
Stop-Process -Name StartMenuExperienceHost -Force -ErrorAction Ignore
# Turn on Controlled folder access if it was turned off
if ($Script:ControlledFolderAccess)
{
Set-MpPreference -EnableControlledFolderAccess Enabled
}
Write-Warning -Message $Localization.RestartWarning
}
#endregion Refresh
# Errors output
function Errors
{
if ($Global:Error)
{
($Global:Error | ForEach-Object -Process {
[PSCustomObject]@{
$Localization.ErrorsLine = $_.InvocationInfo.ScriptLineNumber
$Localization.ErrorsFile = Split-Path -Path $PSCommandPath -Leaf
$Localization.ErrorsMessage = $_.Exception.Message
}
} | Sort-Object -Property Line | Format-Table -AutoSize -Wrap | Out-String).Trim()
}
}