#Requires -RunAsAdministrator #Requires -Version 5.1 # ------------------------------------------------------------ # Funkcje function script:Set-Policy { [CmdletBinding()] param ( [Parameter( Mandatory = $true, Position = 1 )] [string] [ValidateSet("Computer", "User")] $Scope, [Parameter( Mandatory = $true, Position = 2 )] [string] $Path, [Parameter( Mandatory = $true, Position = 3 )] [string] $Name, [Parameter( Mandatory = $true, Position = 4 )] [ValidateSet("DWORD", "SZ", "EXSZ", "CLEAR")] [string] $Type, [Parameter( Mandatory = $false, Position = 5 )] $Value ) if (-not (Test-Path -Path "$env:SystemRoot\System32\gpedit.msc")) { return } switch ($Type) { "CLEAR" { $Policy = @" $Scope $($Path) $($Name) $($Type)`n "@ } default { $Policy = @" $Scope $($Path) $($Name) $($Type):$($Value)`n "@ } } if ($Scope -eq "Computer") { $Path = "$env:TEMP\Computer.txt" } else { $Path = "$env:TEMP\User.txt" } # Save in UTF8 without BOM Add-Content -Path $Path -Value $Policy -Encoding Default -Force } function script:Show-Menu { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [array] $Menu, [Parameter(Mandatory = $true)] [int] $Default, [Parameter(Mandatory = $false)] [switch] $AddSkip ) Write-Information -MessageData "" -InformationAction Continue # Add "Please use the arrow keys 🠕 and 🠗 on your keyboard to select your answer" to menu $Menu += "Użyj klawiszy strzałek {0} i {1} na klawiaturze, aby wybrać odpowiedź" -f [System.Char]::ConvertFromUtf32(0x2191), [System.Char]::ConvertFromUtf32(0x2193) if ($AddSkip) { # Extract the localized "Skip" string from shell32.dll $Menu += "Skip" } # Checking whether current terminal is Windows Terminal if ($env:WT_SESSION) { # https://github.com/microsoft/terminal/issues/14992 [System.Console]::BufferHeight += $Menu.Count } $minY = [Console]::CursorTop $y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0) do { [Console]::CursorTop = $minY [Console]::CursorLeft = 0 $i = 0 foreach ($item in $Menu) { if ($i -ne $y) { Write-Information -MessageData (' {1} ' -f ($i+1), $item) -InformationAction Continue } else { Write-Information -MessageData ('[ {1} ]' -f ($i+1), $item) -InformationAction Continue } $i++ } $k = [Console]::ReadKey() switch ($k.Key) { "UpArrow" { if ($y -gt 0) { $y-- } } "DownArrow" { if ($y -lt ($Menu.Count - 1)) { $y++ } } "Enter" { return $Menu[$y] } } } while ($k.Key -notin ([ConsoleKey]::Escape, [ConsoleKey]::Enter)) } # Extract the localized "Browse" string from shell32.dll $Script:Browse = "Browse" # Extract the localized "&No" string from shell32.dll $Script:No = "No" # Extract the localized "&Yes" string from shell32.dll $Script:Yes = "Yes" $Script:KeyboardArrows = "Użyj klawiszy strzałek {0} i {1} na klawiaturze, aby wybrać odpowiedź" -f [System.Char]::ConvertFromUtf32(0x2191), [System.Char]::ConvertFromUtf32(0x2193) # Extract the localized "Skip" string from shell32.dll $Script:Skip = "Skip" Write-Information -MessageData "https://t.me/sophianews" -InformationAction Continue Write-Information -MessageData "https://t.me/sophia_chat" -InformationAction Continue Write-Information -MessageData "https://discord.gg/sSryhaEv79" -InformationAction Continue # Display a warning message about whether a user has customized the preset file if ($Warning) { # Get the name of a preset (e.g Sophia.ps1) regardless it was named # $_.File has no EndsWith() method Write-Information -MessageData "" -InformationAction Continue [string]$PresetName = ((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")} Write-Verbose -Message ("Czy dostosowałeś funkcje w predefiniowanym pliku {0} przed uruchomieniem Sophia Script?" -f "`"$PresetName`"") -Verbose do { $Choice = Show-Menu -Menu @($Yes, $No) -Default 2 switch ($Choice) { $Yes { continue } $No { Invoke-Item -Path $PresetName Start-Sleep -Seconds 5 Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows#how-to-use" -Verbose Write-Verbose -Message "https://t.me/sophia_chat" -Verbose Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose exit } $KeyboardArrows {} } } until ($Choice -ne $KeyboardArrows) } # ------------------------------------------------------------ # Clear-Host Write-Host "Start" $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.8.3 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) Team Sophia, 2014$([System.Char]0x2013)2025" # Disable the "Connected User Experiences and Telemetry" service (DiagTrack), and block the connection for the Unified Telemetry Client Outbound Traffic function DiagTrackService { param ( [Parameter( Mandatory = $true, ParameterSetName = "Disable" )] [switch] $Disable, [Parameter( Mandatory = $true, ParameterSetName = "Enable" )] [switch] $Enable ) switch ($PSCmdlet.ParameterSetName) { "Disable" { # Connected User Experiences and Telemetry # Disabling the "Connected User Experiences and Telemetry" service (DiagTrack) can cause you not being able to get Xbox achievements anymore and affects Feedback Hub Get-Service -Name DiagTrack -ErrorAction Ignore | Stop-Service -Force Get-Service -Name DiagTrack -ErrorAction Ignore | Set-Service -StartupType Disabled # Block connection for the Unified Telemetry Client Outbound Traffic Get-NetFirewallRule -Group DiagTrack -ErrorAction Ignore | Set-NetFirewallRule -Enabled True -Action Block } "Enable" { # Connected User Experiences and Telemetry Get-Service -Name DiagTrack -ErrorAction Ignore | Set-Service -StartupType Automatic Get-Service -Name DiagTrack -ErrorAction Ignore | Start-Service # Allow connection for the Unified Telemetry Client Outbound Traffic Get-NetFirewallRule -Group DiagTrack -ErrorAction Ignore | Set-NetFirewallRule -Enabled True -Action Allow } } } # Disable the "Connected User Experiences and Telemetry" service (DiagTrack), and block the connection for the Unified Telemetry Client Outbound Traffic # Disabling the "Connected User Experiences and Telemetry" service (DiagTrack) can cause you not being able to get Xbox achievements anymore and affects Feedback Hub DiagTrackService -Disable Write-Host "Set the diagnostic data collection to minimum" function DiagnosticDataLevel { param ( [Parameter( Mandatory = $true, ParameterSetName = "Minimal" )] [switch] $Minimal, [Parameter( Mandatory = $true, ParameterSetName = "Default" )] [switch] $Default ) if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection)) { New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Force } if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack)) { New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Force } switch ($PSCmdlet.ParameterSetName) { "Minimal" { $EditionID = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").EditionID if (($EditionID -match "Enterprise") -or ($EditionID -match "Education")) { # Diagnostic data off New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 0 -Force Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Type DWORD -Value 0 } else { # Send required diagnostic data New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 1 -Force Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Type DWORD -Value 1 } New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 1 -Force New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 1 -Force } "Default" { # Optional diagnostic data New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 3 -Force New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 3 -Force Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Force -ErrorAction Ignore Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Type CLEAR } } } Write-Host "Set the diagnostic data collection to minimum" DiagnosticDataLevel -Minimal # Turn off the Windows Error Reporting function ErrorReporting { param ( [Parameter( Mandatory = $true, ParameterSetName = "Disable" )] [switch] $Disable, [Parameter( Mandatory = $true, ParameterSetName = "Enable" )] [switch] $Enable ) # Remove all policies in order to make changes visible in UI only if it's possible Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Error Reporting", "HKCU:\Software\Policies\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Force -ErrorAction Ignore Set-Policy -Scope Computer -Path "SOFTWARE\Policies\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Type CLEAR Set-Policy -Scope User -Path "Software\Policies\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Type CLEAR switch ($PSCmdlet.ParameterSetName) { "Disable" { Get-ScheduledTask -TaskName QueueReporting -ErrorAction Ignore | Disable-ScheduledTask New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Windows Error Reporting" -Name Disabled -PropertyType DWord -Value 1 -Force Get-Service -Name WerSvc | Stop-Service -Force Get-Service -Name WerSvc | Set-Service -StartupType Disabled } "Enable" { Get-ScheduledTask -TaskName QueueReporting -ErrorAction Ignore | Enable-ScheduledTask Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Force -ErrorAction Ignore Get-Service -Name WerSvc | Set-Service -StartupType Manual Get-Service -Name WerSvc | Start-Service } } } Write-Host "Turn off the Windows Error Reporting" ErrorReporting -Disable # Change the feedback frequency to "Never" function FeedbackFrequency { param ( [Parameter( Mandatory = $true, ParameterSetName = "Never" )] [switch] $Never, [Parameter( Mandatory = $true, ParameterSetName = "Automatically" )] [switch] $Automatically ) # Remove all policies in order to make changes visible in UI only if it's possible Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DoNotShowFeedbackNotifications -Force -ErrorAction Ignore Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DoNotShowFeedbackNotifications -Type CLEAR switch ($PSCmdlet.ParameterSetName) { "Never" { if (-not (Test-Path -Path HKCU:\Software\Microsoft\Siuf\Rules)) { New-Item -Path HKCU:\Software\Microsoft\Siuf\Rules -Force } New-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name NumberOfSIUFInPeriod -PropertyType DWord -Value 0 -Force Remove-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name PeriodInNanoSeconds -Force -ErrorAction Ignore } "Automatically" { Remove-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name PeriodInNanoSeconds, NumberOfSIUFInPeriod -Force -ErrorAction Ignore } } } # Change the feedback frequency to "Never" FeedbackFrequency -Never function FeedbackFrequency { param ( [Parameter( Mandatory = $true, ParameterSetName = "Never" )] [switch] $Never, [Parameter( Mandatory = $true, ParameterSetName = "Automatically" )] [switch] $Automatically ) # Remove all policies in order to make changes visible in UI only if it's possible Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DoNotShowFeedbackNotifications -Force -ErrorAction Ignore Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DoNotShowFeedbackNotifications -Type CLEAR switch ($PSCmdlet.ParameterSetName) { "Never" { if (-not (Test-Path -Path HKCU:\Software\Microsoft\Siuf\Rules)) { New-Item -Path HKCU:\Software\Microsoft\Siuf\Rules -Force } New-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name NumberOfSIUFInPeriod -PropertyType DWord -Value 0 -Force Remove-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name PeriodInNanoSeconds -Force -ErrorAction Ignore } "Automatically" { Remove-ItemProperty -Path HKCU:\Software\Microsoft\Siuf\Rules -Name PeriodInNanoSeconds, NumberOfSIUFInPeriod -Force -ErrorAction Ignore } } } # Turn off the diagnostics tracking scheduled tasks function ScheduledTasks { param ( [Parameter( Mandatory = $true, ParameterSetName = "Disable" )] [switch] $Disable, [Parameter( Mandatory = $true, ParameterSetName = "Enable" )] [switch] $Enable ) Add-Type -AssemblyName PresentationCore, PresentationFramework #region Variables # Initialize an array list to store the selected scheduled tasks $SelectedTasks = New-Object -TypeName System.Collections.ArrayList($null) # The following tasks will have their checkboxes checked [string[]]$CheckedScheduledTasks = @( # Collects program telemetry information if opted-in to the Microsoft Customer Experience Improvement Program "MareBackup", # Collects program telemetry information if opted-in to the Microsoft Customer Experience Improvement Program "Microsoft Compatibility Appraiser", # Updates compatibility database "StartupAppTask", # This task collects and uploads autochk SQM data if opted-in to the Microsoft Customer Experience Improvement Program "Proxy", # If the user has consented to participate in the Windows Customer Experience Improvement Program, this job collects and sends usage data to Microsoft "Consolidator", # The USB CEIP (Customer Experience Improvement Program) task collects Universal Serial Bus related statistics and information about your machine and sends it to the Windows Device Connectivity engineering group at Microsoft "UsbCeip", # The Windows Disk Diagnostic reports general disk and system information to Microsoft for users participating in the Customer Experience Program "Microsoft-Windows-DiskDiagnosticDataCollector", # This task shows various Map related toasts "MapsToastTask", # This task checks for updates to maps which you have downloaded for offline use "MapsUpdateTask", # Initializes Family Safety monitoring and enforcement "FamilySafetyMonitor", # Synchronizes the latest settings with the Microsoft family features service "FamilySafetyRefreshTask", # XblGameSave Standby Task "XblGameSaveTask" ) #endregion Variables #region XAML Markup # The section defines the design of the upcoming dialog box [xml]$XAML = @"