<# .SYNOPSIS Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks Version: v5.2.20 Date: 09.04.2022 Copyright (c) 2014—2022 farag Copyright (c) 2019—2022 farag & Inestic Thanks to all https://forum.ru-board.com members involved .NOTES Running the script is best done on a fresh install because running it on wrong tweaked system may result in errors occurring .NOTES Supported Windows 10 version 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 GitHub link https://github.com/farag2/Sophia-Script-for-Windows .LINK Telegram channel & group https://t.me/sophianews https://t.me/sophia_chat .NOTES https://forum.ru-board.com/topic.cgi?forum=62&topic=30617#15 https://habr.com/company/skillfactory/blog/553800/ https://forums.mydigitallife.net/threads/powershell-windows-10-sophia-script.81675/ https://www.reddit.com/r/PowerShell/comments/go2n5v/powershell_script_setup_windows_10/ .LINK Authors https://github.com/farag2 https://github.com/Inestic #> #region Checkings function Checkings { param ( [Parameter(Mandatory = $false)] [switch] $Warning ) 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 # Enable receiving updates for other Microsoft products when you update Windows (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") Start-Sleep -Seconds 1 # Open the "Windows Update" page Start-Process -FilePath "ms-settings:windowsupdate-action" Start-Sleep -Seconds 1 # Trigger Windows Update for detecting new updates (New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow() exit } } # Check the language mode switch ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") { $true { Write-Warning -Message $Localization.UnsupportedLanguageMode Start-Process -FilePath "https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_language_modes" exit } } # Check whether the logged-in user is an admin $CurrentUserName = (Get-Process -Id $PID -IncludeUserName).UserName | Split-Path -Leaf $CurrentSessionId = (Get-Process -Id $PID -IncludeUserName).SessionId $LoginUserName = (Get-Process -IncludeUserName | Where-Object -FilterScript {($_.ProcessName -eq "explorer") -and ($_.SessionId -eq $CurrentSessionId)}).UserName | Select-Object -First 1 | Split-Path -Leaf switch ($CurrentUserName -ne $LoginUserName) { $true { Write-Warning -Message $Localization.LoggedInUserNotAdmin exit } } # Check whether the script was run via PowerShell 5.1 if ($PSVersionTable.PSVersion.Major -ne 5) { Write-Warning -Message ($Localization.UnsupportedPowerShell -f $PSVersionTable.PSVersion.Major, $PSVersionTable.PSVersion.Minor) exit } # Check whether the script was run via PowerShell ISE if ($Host.Name -match "ISE") { Write-Warning -Message $Localization.UnsupportedISE exit } # Check whether the OS was infected by the Win 10 Tweaker's trojan # https://win10tweaker.ru if (Test-Path -Path "HKCU:\Software\Win 10 Tweaker") { Write-Warning -Message $Localization.Win10TweakerWarning Start-Process -FilePath "https://youtu.be/na93MS-1EkM" Start-Process -FilePath "https://pikabu.ru/story/byekdor_v_win_10_tweaker_ili_sovremennyie_metodyi_borbyi_s_piratstvom_8227558" exit } # Check whether the OS was destroyed by Sycnex's Windows10Debloater script # https://github.com/Sycnex/Windows10Debloater if (Test-Path -Path $env:SystemDrive\Temp\Windows10Debloater) { Write-Warning -Message $Localization.Windows10DebloaterWarning exit } # Check for a pending reboot $PendingActions = @( # CBS pending "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending", # Windows Update pending "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" ) if ($null -ne (Get-Item -Path $PendingActions -Force -ErrorAction Ignore)) { Write-Warning -Message $Localization.RebootPending exit } # Check if the current module version is the latest one try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json $Parameters = @{ Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" UseBasicParsing = $true } $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_LTSC2019 $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() 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/Sophia-Script-for-Windows/releases/latest" exit } } } catch [System.Net.WebException] { Write-Warning -Message ($Localization.NoResponse -f "https://github.com/farag2/Sophia-Script-for-Windows") Write-Error -Message ($Localization.NoResponse -f "https://github.com/farag2/Sophia-Script-for-Windows") -ErrorAction SilentlyContinue } # Unblock all files in the script folder by removing the Zone.Identifier alternate data stream with a value of "3" Get-ChildItem -Path $PSScriptRoot\..\ -File -Recurse -Force | Unblock-File # Display a warning message about whether a user has customized the preset file if ($Warning) { # Get the name of a preset (e.g Sophia.ps1) regardless it was named $PresetName = Split-Path -Path ((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File -match ".ps1"}).File -Leaf $Title = "" $Message = $Localization.CustomizationWarning -f $PresetName $Yes = $Localization.Yes $No = $Localization.No $Options = "&$No", "&$Yes" $DefaultChoice = 0 $Result = $Host.UI.PromptForChoice($Title, $Message, $Options, $DefaultChoice) switch ($Result) { "0" { Invoke-Item -Path $PSScriptRoot\..\$PresetName Start-Sleep -Seconds 5 Start-Process -FilePath "https://github.com/farag2/Sophia-Script-for-Windows#how-to-use" exit } "1" { continue } } } # Turn off Controlled folder access to let the script proceed # Checking whether Defender wasn't disabled first $productState = (Get-CimInstance -Namespace root/SecurityCenter2 -ClassName Antivirusproduct | Where-Object -FilterScript {$_.instanceGuid -eq "{D68DDC3A-831F-4fae-9E44-DA132C1ACF46}"}).productState $DefenderState = ('0x{0:x}' -f $productState).Substring(3, 2) if ($DefenderState -notmatch "00|01") { # Defender is enabled $Script:DefenderState = $true 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 } } } # Save all opened folders in order to restore them after File Explorer restart $Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke() } #endregion Checkings #region Protection # Enable script logging. The log will be being recorded into the script root 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 -FilterScript {$_.DriveLetter -eq "$($env:SystemDrive[0])"}).UniqueID $SystemProtection = ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SPP\Clients" -ErrorAction Ignore)."{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 "Sophia Script for Windows 10" -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 before without deleting the existing restore points if ($ComputerRestorePoint) { Disable-ComputerRestore -Drive $env:SystemDrive } } #endregion Protection #region Privacy & Telemetry <# .SYNOPSIS The Connected User Experiences and Telemetry (DiagTrack) service .PARAMETER Disable Disable the Connected User Experiences and Telemetry (DiagTrack) service, and block connection for the Unified Telemetry Client Outbound Traffic .PARAMETER Enable Enable the Connected User Experiences and Telemetry (DiagTrack) service, and allow connection for the Unified Telemetry Client Outbound Traffic .EXAMPLE DiagTrackService -Disable .EXAMPLE DiagTrackService -Enable .NOTES Current user #> function DiagTrackService { param ( [Parameter( Mandatory = $true, ParameterSetName = "Disable" )] [switch] $Disable, [Parameter( Mandatory = $true, ParameterSetName = "Enable" )] [switch] $Enable ) switch ($PSCmdlet.ParameterSetName) { "Disable" { # Connected User Experiences and Telemetry Get-Service -Name DiagTrack | Stop-Service -Force Get-Service -Name DiagTrack | Set-Service -StartupType Disabled # Block connection for the Unified Telemetry Client Outbound Traffic Get-NetFirewallRule -Group DiagTrack | Set-NetFirewallRule -Enabled False -Action Block } "Enable" { # Connected User Experiences and Telemetry Get-Service -Name DiagTrack | Set-Service -StartupType Automatic Get-Service -Name DiagTrack | Start-Service # Allow connection for the Unified Telemetry Client Outbound Traffic Get-NetFirewallRule -Group DiagTrack | Set-NetFirewallRule -Enabled True -Action Allow } } } <# .SYNOPSIS Diagnostic data .PARAMETER Minimal Set the diagnostic data collection to minimum .PARAMETER Default Set the diagnostic data collection to default .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" { # Security level New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 0 -Force New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 1 -Force New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 1 -Force } "Default" { # Full level New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 3 -Force New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 3 -Force New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 3 -Force } } } <# .SYNOPSIS 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 } Get-Service -Name WerSvc | Stop-Service -Force Get-Service -Name WerSvc | Set-Service -StartupType Disabled } "Enable" { Get-ScheduledTask -TaskName QueueReporting | Enable-ScheduledTask Remove-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Force -ErrorAction Ignore Get-Service -Name WerSvc | Set-Service -StartupType Manual Get-Service -Name WerSvc | Start-Service } } } <# .SYNOPSIS The feedback frequency .PARAMETER Never Change the feedback frequency to "Never" .PARAMETER Automatically Change feedback frequency to "Automatically" .EXAMPLE FeedbackFrequency -Never .EXAMPLE FeedbackFrequency -Automatically .NOTES Current user #> function FeedbackFrequency { param ( [Parameter( Mandatory = $true, ParameterSetName = "Never" )] [switch] $Never, [Parameter( Mandatory = $true, ParameterSetName = "Automatically" )] [switch] $Automatically ) switch ($PSCmdlet.ParameterSetName) { "Never" { if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Siuf\Rules)) { New-Item -Path HKCU:\SOFTWARE\Microsoft\Siuf\Rules -Force } New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Siuf\Rules -Name NumberOfSIUFInPeriod -PropertyType DWord -Value 0 -Force } "Automatically" { Remove-Item -Path HKCU:\SOFTWARE\Microsoft\Siuf\Rules -Force -ErrorAction Ignore } } } <# .SYNOPSIS 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 lets a user select tasks .NOTES Current user #> function ScheduledTasks { param ( [Parameter( Mandatory = $true, ParameterSetName = "Disable" )] [switch] $Disable, [Parameter( Mandatory = $true, ParameterSetName = "Enable" )] [switch] $Enable ) Add-Type -AssemblyName PresentationCore, PresentationFramework #region Variables # Initialize an array list to store the selected scheduled tasks $SelectedTasks = New-Object -TypeName System.Collections.ArrayList($null) # The following tasks will have their checkboxes checked [string[]]$CheckedScheduledTasks = @( # Collects program telemetry information if opted-in to the Microsoft Customer Experience Improvement Program "ProgramDataUpdater", # This task collects and uploads autochk SQM data if opted-in to the Microsoft Customer Experience Improvement Program "Proxy", # If the user has consented to participate in the Windows Customer Experience Improvement Program, this job collects and sends usage data to Microsoft "Consolidator", # The USB CEIP (Customer Experience Improvement Program) task collects Universal Serial Bus related statistics and information about your machine and sends it to the Windows Device Connectivity engineering group at Microsoft "UsbCeip", # The Windows Disk Diagnostic reports general disk and system information to Microsoft for users participating in the Customer Experience Program "Microsoft-Windows-DiskDiagnosticDataCollector", # This task shows various Map related toasts "MapsToastTask", # This task checks for updates to maps which you have downloaded for offline use "MapsUpdateTask", # Initializes Family Safety monitoring and enforcement "FamilySafetyMonitor", # Synchronizes the latest settings with the Microsoft family features service "FamilySafetyRefreshTask", # XblGameSave Standby Task "XblGameSaveTask" ) # Check if device has a camera $DeviceHasCamera = Get-CimInstance -ClassName Win32_PnPEntity | Where-Object -FilterScript {(($_.PNPClass -eq "Camera") -or ($_.PNPClass -eq "Image")) -and ($_.Service -ne "StillCam")} if (-not $DeviceHasCamera) { # Windows Hello $CheckedScheduledTasks += "FODCleanupTask" } #endregion Variables #region XAML Markup # The section defines the design of the upcoming dialog box [xml]$XAML = '