Browse Source

Update Sophia.psm1

pull/619/head
Dmitry Nefedov 7 months ago
parent
commit
be96db875b
  1. 22
      Download_Sophia.ps1
  2. 2
      Wrapper/Localizations/en-US/tooltip_Windows_10.json
  3. 2
      Wrapper/Localizations/en-US/tooltip_Windows_11.json
  4. 2
      src/Sophia_Script_for_Windows_10/Localizations/uk-UA/Sophia.psd1
  5. 625
      src/Sophia_Script_for_Windows_10/Module/Sophia.psm1
  6. 2
      src/Sophia_Script_for_Windows_10/Sophia.ps1
  7. 2
      src/Sophia_Script_for_Windows_10_LTSC_2019/Localizations/uk-UA/Sophia.psd1
  8. 485
      src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1
  9. 2
      src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1
  10. 2
      src/Sophia_Script_for_Windows_10_LTSC_2021/Localizations/uk-UA/Sophia.psd1
  11. 527
      src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1
  12. 2
      src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1
  13. 2
      src/Sophia_Script_for_Windows_10_PowerShell_7/Localizations/uk-UA/Sophia.psd1
  14. 2
      src/Sophia_Script_for_Windows_10_PowerShell_7/Manifest/Sophia.psd1
  15. 625
      src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1
  16. 2
      src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1
  17. 2
      src/Sophia_Script_for_Windows_11/Localizations/uk-UA/Sophia.psd1
  18. 537
      src/Sophia_Script_for_Windows_11/Module/Sophia.psm1
  19. 2
      src/Sophia_Script_for_Windows_11/Sophia.ps1
  20. 2
      src/Sophia_Script_for_Windows_11_LTSC_2024/Localizations/uk-UA/Sophia.psd1
  21. 535
      src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1
  22. 2
      src/Sophia_Script_for_Windows_11_LTSC_2024/Sophia.ps1
  23. 2
      src/Sophia_Script_for_Windows_11_PowerShell_7/Localizations/uk-UA/Sophia.psd1
  24. 2
      src/Sophia_Script_for_Windows_11_PowerShell_7/Manifest/Sophia.psd1
  25. 557
      src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1
  26. 2
      src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1

22
Download_Sophia.ps1

@ -49,7 +49,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber)
Verbose = $true
}
$Version = "LTSC2019"
$Version = "Windows_10_LTSC2019"
}
else
{
@ -79,7 +79,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber)
UseBasicParsing = $true
Verbose = $true
}
$Version = "LTSC2021"
$Version = "Windows_10_LTSC2021"
}
else
{
@ -163,7 +163,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber)
Verbose = $true
}
$Version = "LTSC2024"
$Version = "Windows_11_LTSC2024"
}
}
}
@ -176,10 +176,10 @@ if (-not (Test-Path -Path "$DownloadsFolder\Sophia.Script.zip"))
# Check for updates
Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan
# Open the "Windows Update" page
# Open t"Windows Update" page
Start-Process -FilePath "ms-settings:windowsupdate"
return
exit
}
$Parameters = @{
@ -195,23 +195,25 @@ Start-Sleep -Second 1
switch ($Version)
{
"LTSC2019"
"Windows_10_LTSC2019"
{
Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_LTSC_2019_v$LatestRelease"
if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544"))
{
Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_LTSC_2019_v$LatestRelease"
}
}
"LTSC2021"
"Windows_10_LTSC2021"
{
Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_LTSC_2021_v$LatestRelease"
if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544"))
{
Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_LTSC_2021_v$LatestRelease"
}
}
"LTSC2024"
"Windows_11_LTSC2024"
{
Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_LTSC_2024_v$LatestRelease"
if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544"))
@ -222,6 +224,7 @@ switch ($Version)
"Windows_10_PowerShell_5.1"
{
Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_v$LatestRelease"
if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544"))
{
Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_v$LatestRelease"
@ -230,6 +233,7 @@ switch ($Version)
"Windows_10_PowerShell_7"
{
Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_PowerShell_7_v$LatestRelease"
if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544"))
{
Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_PowerShell_7_v$LatestRelease"
@ -238,6 +242,7 @@ switch ($Version)
"Windows_11_PowerShell_5.1"
{
Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_v$LatestRelease"
if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544"))
{
Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_v$LatestRelease"
@ -246,6 +251,7 @@ switch ($Version)
"Windows_11_PowerShell_7"
{
Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_PowerShell_7_v$LatestRelease"
if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544"))
{
Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_PowerShell_7_v$LatestRelease"

2
Wrapper/Localizations/en-US/tooltip_Windows_10.json

@ -2084,7 +2084,7 @@
"Arg": {
"Zero": {
"Tag": "",
"ToolTip": "Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc). This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources."
"ToolTip": "Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc). This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources."
}
}
}

2
Wrapper/Localizations/en-US/tooltip_Windows_11.json

@ -1955,7 +1955,7 @@
"Arg": {
"Zero": {
"Tag": "",
"ToolTip": "Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc). This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources."
"ToolTip": "Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc). This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources."
}
}
}

2
src/Sophia_Script_for_Windows_10/Localizations/uk-UA/Sophia.psd1

@ -12,7 +12,7 @@ TweakerWarning = Стабільність вашої
Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів.
RebootPending = Комп'ютер очікує на перезавантаження.
UnsupportedRelease = Виявлено нову версію.
KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1}
KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1}
CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script?
WindowsComponentBroken = {0} пошкоджено або видалено з ОС.
UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу.

625
src/Sophia_Script_for_Windows_10/Module/Sophia.psm1

@ -301,6 +301,116 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
# Remove harmful blocked DNS domains list from https://github.com/schrebra/Windows.10.DNS.Block.List
Get-NetFirewallRule -DisplayName Block.MSFT* -ErrorAction Ignore | Remove-NetFirewallRule
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# Check whether Get-WindowsEdition cmdlet is working
# https://github.com/PowerShell/PowerShell/issues/21295
try
@ -550,20 +660,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
@ -593,12 +689,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
# Check whether LGPO.exe exists in the bin folder
if (-not (Test-Path -Path "$PSScriptRoot\..\bin\LGPO.exe"))
@ -644,20 +734,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
"19045"
{
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json
@ -669,17 +745,11 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
$LatestSupportedBuild = 0
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# We may use Test-Path -Path variable:LatestSupportedBuild
@ -709,155 +779,24 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Open the "Windows Update" page
Start-Process -FilePath "ms-settings:windowsupdate"
exit
}
}
}
# Enable back the SysMain service if it was disabled by harmful tweakers
if ((Get-Service -Name SysMain).Status -eq "Stopped")
{
Get-Service -Name SysMain | Set-Service -StartupType Automatic
Get-Service -Name SysMain | Start-Service
Write-Verbose -Message "https://www.outsidethebox.ms/19318/" -Verbose
}
# Automatically manage paging file size for all drives
if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile)
{
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true}
}
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
exit
}
}
catch [System.ComponentModel.Win32Exception]
}
# Enable back the SysMain service if it was disabled by harmful tweakers
if ((Get-Service -Name SysMain).Status -eq "Stopped")
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Get-Service -Name SysMain | Set-Service -StartupType Automatic
Get-Service -Name SysMain | Start-Service
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
Write-Verbose -Message "https://www.outsidethebox.ms/19318/" -Verbose
}
# Automatically manage paging file size for all drives
if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile)
{
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true}
}
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
@ -920,7 +859,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$Menu += [WinAPI.GetStrings]::GetString(16956)
}
# Check if current terminal is Windows Terminal
# Check whether current terminal is Windows Terminal
if ($env:WT_SESSION)
{
# https://github.com/microsoft/terminal/issues/14992
@ -3710,7 +3649,7 @@ public static extern int HashData(byte[] pbData, int cbData, byte[] piet, int ou
}
}
Remove-Item -Path "$env:SystemRoot\System32\powershell_temp.exe" -Force
Remove-Item -Path "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Force
}
<#
@ -4738,20 +4677,6 @@ function Cursors
{
"Dark"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4844,30 +4769,8 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Light"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4960,14 +4863,6 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Default"
{
New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "" -Force
@ -5357,18 +5252,6 @@ public static bool MarkFileDelete (string sourcefile)
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
@ -5407,12 +5290,14 @@ public static bool MarkFileDelete (string sourcefile)
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
@ -6564,10 +6449,12 @@ function WindowsCapabilities
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Uninstall"
@ -9939,7 +9826,7 @@ function UninstallPCHealthCheck
foreach ($MSI in @(Get-ChildItem -Path "$env:SystemRoot\Installer" -Filter *.msi -File -Force))
{
$Name = $Files.Keys | Where-Object -FilterScript {$_ -eq $MSI.Name}
# Check if necessary files exist in folder unless we get a bunch of errors for $File variable
# Check whether necessary files exist in folder unless we get a bunch of errors for $File variable
if ($Name)
{
$File = $Files[$Name]
@ -9978,33 +9865,6 @@ function UninstallPCHealthCheck
function InstallVCRedist
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/VCRedist/2015%2B
winget install --id=Microsoft.VCRedist.2015+.x86 --exact --force --accept-source-agreements
winget install --id=Microsoft.VCRedist.2015+.x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
{
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
@ -10037,11 +9897,10 @@ function InstallVCRedist
)
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -10074,48 +9933,13 @@ function InstallDotNetRuntimes
$Runtimes
)
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
foreach ($Runtime in $Runtimes)
{
switch ($Runtime)
{
NET6x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/6
# .NET Desktop Runtime 6 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# Install .NET Desktop Runtime 6
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -10126,7 +9950,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 6 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -10135,6 +9971,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -10146,22 +9992,9 @@ function InstallDotNetRuntimes
)
Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
NET8x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# .NET Desktop Runtime 8 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# .NET Desktop Runtime 8
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -10172,7 +10005,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 8 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -10181,6 +10026,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -10194,7 +10049,6 @@ function InstallDotNetRuntimes
}
}
}
}
}
<#
@ -10510,20 +10364,6 @@ function RegistryBackup
#>
function Install-WSL
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json
@ -10539,6 +10379,16 @@ function Install-WSL
"Alias" = $_.Name
}
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Add-Type -AssemblyName PresentationCore, PresentationFramework
@ -10662,18 +10512,6 @@ function Install-WSL
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
}
#endregion WSL
@ -11589,29 +11427,6 @@ function HEVC
return
}
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName)
{
"Install"
@ -11654,6 +11469,19 @@ function HEVC
# Installing "HEVC Video Extensions from Device Manufacturer"
if ([System.Version]$HEVCPackageName -gt [System.Version](Get-AppxPackage -Name Microsoft.HEVCVideoExtension).Version)
{
try
{
# Check whether https://store.rg-adguard.net is alive
$Parameters = @{
Uri = $TempURL
UseBasicParsing = $true
Verbose = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
@ -11672,6 +11500,16 @@ function HEVC
Add-AppxPackage -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Verbose
Remove-Item -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
else
{
Write-Information -MessageData "" -InformationAction Continue
@ -11684,6 +11522,8 @@ function HEVC
Write-Error -Message ($Localization.NoResponse -f "https://store.rg-adguard.net/api/GetFiles") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Manually"
@ -13713,7 +13553,7 @@ function WindowsScriptHost
{
"Disable"
{
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
# Check whether any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" -ErrorAction Ignore | ForEach-Object -Process {
# Skip if a scheduled task exists
if ($_.State -eq "Ready")
@ -13803,6 +13643,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -13826,6 +13667,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -13878,7 +13720,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateSet("1.0.0.1", "1.1.1.1", "149.112.112.112", "8.8.4.4", "8.8.8.8", "9.9.9.9")]
[ValidateScript({
# Check if $PrimaryDNS is not equal to $SecondaryDNS
# Check whether $PrimaryDNS is not equal to $SecondaryDNS
$_ -ne $SecondaryDNS
})]
[string]
@ -13887,7 +13729,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateSet("1.0.0.1", "1.1.1.1", "149.112.112.112", "8.8.4.4", "8.8.8.8", "9.9.9.9")]
[ValidateScript({
# Check if $PrimaryDNS is not equal to $SecondaryDNS
# Check whether $PrimaryDNS is not equal to $SecondaryDNS
$_ -ne $PrimaryDNS
})]
[string]
@ -14541,8 +14383,8 @@ function BitmapImageNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -14632,8 +14474,8 @@ function RichTextDocumentNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -14816,7 +14658,7 @@ function UseStoreOpenWith
<#
.SYNOPSIS
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
.EXAMPLE
UpdateLGPEPolicies
@ -14847,6 +14689,8 @@ function UpdateLGPEPolicies
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Verbose -Message $Localization.GPOUpdate -Verbose
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKLM -Verbose
Write-Information -MessageData "" -InformationAction Continue
@ -14907,6 +14751,7 @@ function UpdateLGPEPolicies
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKCU -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Current User policies paths to scan recursively
$CU_Paths = @(

2
src/Sophia_Script_for_Windows_10/Sophia.ps1

@ -1408,7 +1408,7 @@ UseStoreOpenWith -Hide
#region Update Policies
<#
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc)
Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы

2
src/Sophia_Script_for_Windows_10_LTSC_2019/Localizations/uk-UA/Sophia.psd1

@ -12,7 +12,7 @@ TweakerWarning = Стабільність вашої
Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів.
RebootPending = Комп'ютер очікує на перезавантаження.
UnsupportedRelease = Виявлено нову версію.
KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1}
KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1}
CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script?
WindowsComponentBroken = {0} пошкоджено або видалено з ОС.
UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу.

485
src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1

@ -299,6 +299,116 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
# Remove harmful blocked DNS domains list from https://github.com/schrebra/Windows.10.DNS.Block.List
Get-NetFirewallRule -DisplayName Block.MSFT* -ErrorAction Ignore | Remove-NetFirewallRule
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# Check whether Get-WindowsEdition cmdlet is working
# https://github.com/PowerShell/PowerShell/issues/21295
try
@ -511,20 +621,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
@ -554,12 +650,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
# Check whether LGPO.exe exists in the bin folder
if (-not (Test-Path -Path "$PSScriptRoot\..\bin\LGPO.exe"))
@ -615,20 +705,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
"17763"
{
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json
@ -640,17 +716,11 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10_LTSC_2019
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
$LatestSupportedBuild = 0
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# We may use Test-Path -Path variable:LatestSupportedBuild
@ -697,137 +767,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true}
}
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
@ -888,7 +827,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$Menu += [WinAPI.GetStrings]::GetString(16956)
}
# Check if current terminal is Windows Terminal
# Check whether current terminal is Windows Terminal
if ($env:WT_SESSION)
{
# https://github.com/microsoft/terminal/issues/14992
@ -3637,20 +3576,6 @@ function Cursors
{
"Dark"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -3743,30 +3668,8 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Light"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -3859,14 +3762,6 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Default"
{
New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "" -Force
@ -5154,10 +5049,12 @@ function WindowsCapabilities
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Uninstall"
@ -8167,33 +8064,6 @@ function Import-Associations
function InstallVCRedist
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/VCRedist/2015%2B
winget install --id=Microsoft.VCRedist.2015+.x86 --exact --force --accept-source-agreements
winget install --id=Microsoft.VCRedist.2015+.x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
{
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
@ -8226,11 +8096,10 @@ function InstallVCRedist
)
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -8263,48 +8132,13 @@ function InstallDotNetRuntimes
$Runtimes
)
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
foreach ($Runtime in $Runtimes)
{
switch ($Runtime)
{
NET6x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/6
# .NET Desktop Runtime 6 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# Install .NET Desktop Runtime 6
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -8315,7 +8149,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 6 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -8324,6 +8170,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -8335,22 +8191,9 @@ function InstallDotNetRuntimes
)
Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
NET8x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# .NET Desktop Runtime 8 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# .NET Desktop Runtime 8
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -8361,7 +8204,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 8 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -8370,6 +8225,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -8383,7 +8248,6 @@ function InstallDotNetRuntimes
}
}
}
}
}
<#
@ -10486,7 +10350,7 @@ function WindowsScriptHost
{
"Disable"
{
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
# Check whether any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" -ErrorAction Ignore | ForEach-Object -Process {
# Skip if a scheduled task exists
if ($_.State -eq "Ready")
@ -10568,6 +10432,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -10591,6 +10456,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -11131,8 +10997,8 @@ function BitmapImageNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -11222,8 +11088,8 @@ function RichTextDocumentNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -11344,7 +11210,7 @@ function MultipleInvokeContext
<#
.SYNOPSIS
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
.EXAMPLE
UpdateLGPEPolicies
@ -11375,6 +11241,8 @@ function UpdateLGPEPolicies
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Verbose -Message $Localization.GPOUpdate -Verbose
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKLM -Verbose
Write-Information -MessageData "" -InformationAction Continue
@ -11435,6 +11303,7 @@ function UpdateLGPEPolicies
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKCU -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Current User policies paths to scan recursively
$CU_Paths = @(

2
src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1

@ -1047,7 +1047,7 @@ MultipleInvokeContext -Enable
#region Update Policies
<#
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc)
Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы

2
src/Sophia_Script_for_Windows_10_LTSC_2021/Localizations/uk-UA/Sophia.psd1

@ -12,7 +12,7 @@ TweakerWarning = Стабільність вашої
Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів.
RebootPending = Комп'ютер очікує на перезавантаження.
UnsupportedRelease = Виявлено нову версію.
KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1}
KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1}
CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script?
WindowsComponentBroken = {0} пошкоджено або видалено з ОС.
UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу.

527
src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1

@ -299,6 +299,116 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
# Remove harmful blocked DNS domains list from https://github.com/schrebra/Windows.10.DNS.Block.List
Get-NetFirewallRule -DisplayName Block.MSFT* -ErrorAction Ignore | Remove-NetFirewallRule
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# Check whether Get-WindowsEdition cmdlet is working
# https://github.com/PowerShell/PowerShell/issues/21295
try
@ -511,20 +621,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
@ -533,7 +629,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Verbose = $true
UseBasicParsing = $true
}
$LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_LTSC2021
$LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_PowerShell_5_1
$CurrentRelease = (Get-Module -Name Sophia).Version.ToString()
if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease)
@ -554,12 +650,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
# Check whether LGPO.exe exists in the bin folder
if (-not (Test-Path -Path "$PSScriptRoot\..\bin\LGPO.exe"))
@ -615,20 +705,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
"19044"
{
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json
@ -640,17 +716,11 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10_LTSC_2021
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
$LatestSupportedBuild = 0
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# We may use Test-Path -Path variable:LatestSupportedBuild
@ -697,137 +767,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true}
}
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
@ -888,7 +827,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$Menu += [WinAPI.GetStrings]::GetString(16956)
}
# Check if current terminal is Windows Terminal
# Check whether current terminal is Windows Terminal
if ($env:WT_SESSION)
{
# https://github.com/microsoft/terminal/issues/14992
@ -4013,20 +3952,6 @@ function Cursors
{
"Dark"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4119,30 +4044,8 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Light"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4235,14 +4138,6 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Default"
{
New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "" -Force
@ -5546,10 +5441,12 @@ function WindowsCapabilities
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Uninstall"
@ -8798,33 +8695,6 @@ function Import-Associations
function InstallVCRedist
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/VCRedist/2015%2B
winget install --id=Microsoft.VCRedist.2015+.x86 --exact --force --accept-source-agreements
winget install --id=Microsoft.VCRedist.2015+.x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
{
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
@ -8857,11 +8727,10 @@ function InstallVCRedist
)
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -8894,48 +8763,13 @@ function InstallDotNetRuntimes
$Runtimes
)
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
foreach ($Runtime in $Runtimes)
{
switch ($Runtime)
{
NET6x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/6
# .NET Desktop Runtime 6 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# Install .NET Desktop Runtime 6
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -8946,7 +8780,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 6 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -8955,6 +8801,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -8966,22 +8822,9 @@ function InstallDotNetRuntimes
)
Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
NET8x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# .NET Desktop Runtime 8 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# .NET Desktop Runtime 8
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -8992,7 +8835,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 8 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -9001,6 +8856,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -9014,7 +8879,6 @@ function InstallDotNetRuntimes
}
}
}
}
}
<#
@ -9330,20 +9194,6 @@ function RegistryBackup
#>
function Install-WSL
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json
@ -9359,6 +9209,16 @@ function Install-WSL
"Alias" = $_.Name
}
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Add-Type -AssemblyName PresentationCore, PresentationFramework
@ -9482,18 +9342,6 @@ function Install-WSL
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
}
#endregion WSL
@ -11617,7 +11465,7 @@ function WindowsScriptHost
{
"Disable"
{
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
# Check whether any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" -ErrorAction Ignore | ForEach-Object -Process {
# Skip if a scheduled task exists
if ($_.State -eq "Ready")
@ -11699,6 +11547,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -11722,6 +11571,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -11774,7 +11624,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateSet("1.0.0.1", "1.1.1.1", "149.112.112.112", "8.8.4.4", "8.8.8.8", "9.9.9.9")]
[ValidateScript({
# Check if $PrimaryDNS is not equal to $SecondaryDNS
# Check whether $PrimaryDNS is not equal to $SecondaryDNS
$_ -ne $SecondaryDNS
})]
[string]
@ -11783,7 +11633,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateSet("1.0.0.1", "1.1.1.1", "149.112.112.112", "8.8.4.4", "8.8.8.8", "9.9.9.9")]
[ValidateScript({
# Check if $PrimaryDNS is not equal to $SecondaryDNS
# Check whether $PrimaryDNS is not equal to $SecondaryDNS
$_ -ne $PrimaryDNS
})]
[string]
@ -12497,8 +12347,8 @@ function BitmapImageNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -12588,8 +12438,8 @@ function RichTextDocumentNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -12710,7 +12560,7 @@ function MultipleInvokeContext
<#
.SYNOPSIS
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
.EXAMPLE
UpdateLGPEPolicies
@ -12741,6 +12591,8 @@ function UpdateLGPEPolicies
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Verbose -Message $Localization.GPOUpdate -Verbose
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKLM -Verbose
Write-Information -MessageData "" -InformationAction Continue
@ -12801,6 +12653,7 @@ function UpdateLGPEPolicies
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKCU -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Current User policies paths to scan recursively
$CU_Paths = @(

2
src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1

@ -1212,7 +1212,7 @@ MultipleInvokeContext -Enable
#region Update Policies
<#
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc)
Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы

2
src/Sophia_Script_for_Windows_10_PowerShell_7/Localizations/uk-UA/Sophia.psd1

@ -12,7 +12,7 @@ TweakerWarning = Стабільність вашої
Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів.
RebootPending = Комп'ютер очікує на перезавантаження.
UnsupportedRelease = Виявлено нову версію.
KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1}
KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1}
CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script?
WindowsComponentBroken = {0} пошкоджено або видалено з ОС.
UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу.

2
src/Sophia_Script_for_Windows_10_PowerShell_7/Manifest/Sophia.psd1

@ -5,7 +5,7 @@
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014—2024 farag, Inestic & lowl1f3. All rights reserved'
Description = 'Module for Windows fine-tuning and automating the routine tasks'
PowerShellVersion = '7.3'
PowerShellVersion = '7.4'
ProcessorArchitecture = 'AMD64'
FunctionsToExport = '*'

625
src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1

@ -300,6 +300,116 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
# Remove harmful blocked DNS domains list from https://github.com/schrebra/Windows.10.DNS.Block.List
Get-NetFirewallRule -DisplayName Block.MSFT* -ErrorAction Ignore | Remove-NetFirewallRule
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# Check whether Get-WindowsEdition cmdlet is working
# https://github.com/PowerShell/PowerShell/issues/21295
try
@ -549,20 +659,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
@ -592,12 +688,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
# Check whether all necessary files exist in the bin folder
$Files = @(
@ -648,20 +738,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
"19045"
{
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json
@ -673,17 +749,11 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
$LatestSupportedBuild = 0
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# We may use Test-Path -Path variable:LatestSupportedBuild
@ -713,155 +783,24 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Open the "Windows Update" page
Start-Process -FilePath "ms-settings:windowsupdate"
exit
}
}
}
# Enable back the SysMain service if it was disabled by harmful tweakers
if ((Get-Service -Name SysMain).Status -eq "Stopped")
{
Get-Service -Name SysMain | Set-Service -StartupType Automatic
Get-Service -Name SysMain | Start-Service
Write-Verbose -Message "https://www.outsidethebox.ms/19318/" -Verbose
}
# Automatically manage paging file size for all drives
if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile)
{
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true}
}
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
exit
}
}
catch [System.ComponentModel.Win32Exception]
}
# Enable back the SysMain service if it was disabled by harmful tweakers
if ((Get-Service -Name SysMain).Status -eq "Stopped")
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Get-Service -Name SysMain | Set-Service -StartupType Automatic
Get-Service -Name SysMain | Start-Service
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
Write-Verbose -Message "https://www.outsidethebox.ms/19318/" -Verbose
}
# Automatically manage paging file size for all drives
if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile)
{
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true}
}
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
@ -924,7 +863,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$Menu += [WinAPI.GetStrings]::GetString(16956)
}
# Check if current terminal is Windows Terminal
# Check whether current terminal is Windows Terminal
if ($env:WT_SESSION)
{
# https://github.com/microsoft/terminal/issues/14992
@ -3714,7 +3653,7 @@ public static extern int HashData(byte[] pbData, int cbData, byte[] piet, int ou
}
}
Remove-Item -Path "$env:SystemRoot\System32\powershell_temp.exe" -Force
Remove-Item -Path "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell_temp.exe" -Force
}
<#
@ -4742,20 +4681,6 @@ function Cursors
{
"Dark"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4848,30 +4773,8 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Light"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4964,14 +4867,6 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Default"
{
New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "" -Force
@ -5363,18 +5258,6 @@ public static bool MarkFileDelete (string sourcefile)
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
@ -5413,12 +5296,14 @@ public static bool MarkFileDelete (string sourcefile)
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
@ -6570,10 +6455,12 @@ function WindowsCapabilities
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Uninstall"
@ -9945,7 +9832,7 @@ function UninstallPCHealthCheck
foreach ($MSI in @(Get-ChildItem -Path "$env:SystemRoot\Installer" -Filter *.msi -File -Force))
{
$Name = $Files.Keys | Where-Object -FilterScript {$_ -eq $MSI.Name}
# Check if necessary files exist in folder unless we get a bunch of errors for $File variable
# Check whether necessary files exist in folder unless we get a bunch of errors for $File variable
if ($Name)
{
$File = $Files[$Name]
@ -9984,33 +9871,6 @@ function UninstallPCHealthCheck
function InstallVCRedist
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/VCRedist/2015%2B
winget install --id=Microsoft.VCRedist.2015+.x86 --exact --force --accept-source-agreements
winget install --id=Microsoft.VCRedist.2015+.x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
{
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
@ -10043,11 +9903,10 @@ function InstallVCRedist
)
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -10080,48 +9939,13 @@ function InstallDotNetRuntimes
$Runtimes
)
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
foreach ($Runtime in $Runtimes)
{
switch ($Runtime)
{
NET6x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/6
# .NET Desktop Runtime 6 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# Install .NET Desktop Runtime 6
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -10132,7 +9956,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 6 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -10141,6 +9977,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -10152,22 +9998,9 @@ function InstallDotNetRuntimes
)
Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
NET8x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# .NET Desktop Runtime 8 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# .NET Desktop Runtime 8
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -10178,7 +10011,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 8 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -10187,6 +10032,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -10200,7 +10055,6 @@ function InstallDotNetRuntimes
}
}
}
}
}
<#
@ -10516,20 +10370,6 @@ function RegistryBackup
#>
function Install-WSL
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json
@ -10545,6 +10385,16 @@ function Install-WSL
"Alias" = $_.Name
}
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Add-Type -AssemblyName PresentationCore, PresentationFramework
@ -10668,18 +10518,6 @@ function Install-WSL
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
}
#endregion WSL
@ -11605,29 +11443,6 @@ function HEVC
return
}
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName)
{
"Install"
@ -11670,6 +11485,19 @@ function HEVC
# Installing "HEVC Video Extensions from Device Manufacturer"
if ([System.Version]$HEVCPackageName -gt [System.Version](Get-AppxPackage -Name Microsoft.HEVCVideoExtension).Version)
{
try
{
# Check whether https://store.rg-adguard.net is alive
$Parameters = @{
Uri = $TempURL
UseBasicParsing = $true
Verbose = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
@ -11688,6 +11516,16 @@ function HEVC
Add-AppxPackage -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Verbose
Remove-Item -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
else
{
Write-Information -MessageData "" -InformationAction Continue
@ -11700,6 +11538,8 @@ function HEVC
Write-Error -Message ($Localization.NoResponse -f "https://store.rg-adguard.net/api/GetFiles") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Manually"
@ -13729,7 +13569,7 @@ function WindowsScriptHost
{
"Disable"
{
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
# Check whether any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" -ErrorAction Ignore | ForEach-Object -Process {
# Skip if a scheduled task exists
if ($_.State -eq "Ready")
@ -13819,6 +13659,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -13842,6 +13683,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -13894,7 +13736,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateSet("1.0.0.1", "1.1.1.1", "149.112.112.112", "8.8.4.4", "8.8.8.8", "9.9.9.9")]
[ValidateScript({
# Check if $PrimaryDNS is not equal to $SecondaryDNS
# Check whether $PrimaryDNS is not equal to $SecondaryDNS
$_ -ne $SecondaryDNS
})]
[string]
@ -13903,7 +13745,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateSet("1.0.0.1", "1.1.1.1", "149.112.112.112", "8.8.4.4", "8.8.8.8", "9.9.9.9")]
[ValidateScript({
# Check if $PrimaryDNS is not equal to $SecondaryDNS
# Check whether $PrimaryDNS is not equal to $SecondaryDNS
$_ -ne $PrimaryDNS
})]
[string]
@ -14557,8 +14399,8 @@ function BitmapImageNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -14648,8 +14490,8 @@ function RichTextDocumentNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -14832,7 +14674,7 @@ function UseStoreOpenWith
<#
.SYNOPSIS
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
.EXAMPLE
UpdateLGPEPolicies
@ -14863,6 +14705,8 @@ function UpdateLGPEPolicies
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Verbose -Message $Localization.GPOUpdate -Verbose
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKLM -Verbose
Write-Information -MessageData "" -InformationAction Continue
@ -14923,6 +14767,7 @@ function UpdateLGPEPolicies
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKCU -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Current User policies paths to scan recursively
$CU_Paths = @(

2
src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1

@ -1419,7 +1419,7 @@ UseStoreOpenWith -Hide
#region Update Policies
<#
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc)
Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы

2
src/Sophia_Script_for_Windows_11/Localizations/uk-UA/Sophia.psd1

@ -11,7 +11,7 @@ TweakerWarning = Стабільність вашої
Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів.
RebootPending = Комп'ютер очікує на перезавантаження.
UnsupportedRelease = Виявлено нову версію.
KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1}
KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1}
CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script?
WindowsComponentBroken = {0} пошкоджено або видалено з ОС.
UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу.

537
src/Sophia_Script_for_Windows_11/Module/Sophia.psm1

@ -287,6 +287,116 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
# Remove harmful blocked DNS domains list from https://github.com/schrebra/Windows.10.DNS.Block.List
Get-NetFirewallRule -DisplayName Block.MSFT* -ErrorAction Ignore | Remove-NetFirewallRule
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# Check whether Get-WindowsEdition cmdlet is working
# https://github.com/PowerShell/PowerShell/issues/21295
try
@ -524,20 +634,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
@ -567,12 +663,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
# Check whether LGPO.exe exists in the bin folder
if (-not (Test-Path -Path "$PSScriptRoot\..\bin\LGPO.exe"))
@ -618,20 +708,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
"22631"
{
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json
@ -643,17 +719,11 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_11
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
$LatestSupportedBuild = 0
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# We may use Test-Path -Path variable:LatestSupportedBuild
@ -703,137 +773,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true}
}
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
@ -894,7 +833,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$Menu += [WinAPI.GetStrings]::GetString(16956)
}
# Check if current terminal is Windows Terminal
# Check whether current terminal is Windows Terminal
if ($env:WT_SESSION)
{
# https://github.com/microsoft/terminal/issues/14992
@ -4331,20 +4270,6 @@ function Cursors
{
"Dark"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4437,30 +4362,8 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Light"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4553,14 +4456,6 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Default"
{
New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "" -Force
@ -4950,18 +4845,6 @@ public static bool MarkFileDelete (string sourcefile)
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
@ -5000,12 +4883,14 @@ public static bool MarkFileDelete (string sourcefile)
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
@ -6157,10 +6042,12 @@ function WindowsCapabilities
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Uninstall"
@ -9596,33 +9483,6 @@ function DefaultTerminalApp
function InstallVCRedist
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/VCRedist/2015%2B
winget install --id=Microsoft.VCRedist.2015+.x86 --exact --force --accept-source-agreements
winget install --id=Microsoft.VCRedist.2015+.x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
{
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
@ -9655,11 +9515,10 @@ function InstallVCRedist
)
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -9692,48 +9551,13 @@ function InstallDotNetRuntimes
$Runtimes
)
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
foreach ($Runtime in $Runtimes)
{
switch ($Runtime)
{
NET6x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/6
# .NET Desktop Runtime 6 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# Install .NET Desktop Runtime 6
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -9744,7 +9568,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 6 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -9753,6 +9589,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -9764,22 +9610,9 @@ function InstallDotNetRuntimes
)
Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
NET8x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# .NET Desktop Runtime 8 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# .NET Desktop Runtime 8
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -9790,7 +9623,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 8 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -9799,6 +9644,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -9812,7 +9667,6 @@ function InstallDotNetRuntimes
}
}
}
}
}
<#
@ -10128,20 +9982,6 @@ function RegistryBackup
#>
function Install-WSL
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json
@ -10157,6 +9997,16 @@ function Install-WSL
"Alias" = $_.Name
}
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Add-Type -AssemblyName PresentationCore, PresentationFramework
@ -10280,18 +10130,6 @@ function Install-WSL
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
}
#endregion WSL
@ -12874,7 +12712,7 @@ function WindowsScriptHost
{
"Disable"
{
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
# Check whether any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" -ErrorAction Ignore | ForEach-Object -Process {
# Skip if a scheduled task exists
if ($_.State -eq "Ready")
@ -12964,6 +12802,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -12987,6 +12826,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -13038,7 +12878,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateScript({
# Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS
# Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS
((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $SecondaryDNS)
})]
[string]
@ -13046,7 +12886,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateScript({
# Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS
# Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS
((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $PrimaryDNS)
})]
[string]
@ -13888,7 +13728,7 @@ function OpenWindowsTerminalAdminContext
<#
.SYNOPSIS
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
.EXAMPLE
UpdateLGPEPolicies
@ -13919,6 +13759,8 @@ function UpdateLGPEPolicies
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Verbose -Message $Localization.GPOUpdate -Verbose
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKLM -Verbose
Write-Information -MessageData "" -InformationAction Continue
@ -13979,6 +13821,7 @@ function UpdateLGPEPolicies
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKCU -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Current User policies paths to scan recursively
$CU_Paths = @(

2
src/Sophia_Script_for_Windows_11/Sophia.ps1

@ -1338,7 +1338,7 @@ OpenWindowsTerminalAdminContext -Enable
#region Update Policies
<#
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc)
Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы

2
src/Sophia_Script_for_Windows_11_LTSC_2024/Localizations/uk-UA/Sophia.psd1

@ -11,7 +11,7 @@ TweakerWarning = Стабільність вашої
Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів.
RebootPending = Комп'ютер очікує на перезавантаження.
UnsupportedRelease = Виявлено нову версію.
KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1}
KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1}
CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script?
WindowsComponentBroken = {0} пошкоджено або видалено з ОС.
UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу.

535
src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1

@ -285,6 +285,116 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
# Remove harmful blocked DNS domains list from https://github.com/schrebra/Windows.10.DNS.Block.List
Get-NetFirewallRule -DisplayName Block.MSFT* -ErrorAction Ignore | Remove-NetFirewallRule
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# Check whether Get-WindowsEdition cmdlet is working
# https://github.com/PowerShell/PowerShell/issues/21295
try
@ -509,20 +619,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
@ -552,12 +648,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
# Check whether LGPO.exe exists in the bin folder
if (-not (Test-Path -Path "$PSScriptRoot\..\bin\LGPO.exe"))
@ -614,20 +704,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
"26100"
{
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json
@ -636,20 +712,14 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Verbose = $true
UseBasicParsing = $true
}
$LatestSupportedBuild = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_LTSC2024
$LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_11_LTSC_2024
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
$LatestSupportedBuild = 0
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# We may use Test-Path -Path variable:LatestSupportedBuild
@ -696,137 +766,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true}
}
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
@ -887,7 +826,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$Menu += [WinAPI.GetStrings]::GetString(16956)
}
# Check if current terminal is Windows Terminal
# Check whether current terminal is Windows Terminal
if ($env:WT_SESSION)
{
# https://github.com/microsoft/terminal/issues/14992
@ -4118,20 +4057,6 @@ function Cursors
{
"Dark"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4224,30 +4149,8 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Light"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4340,14 +4243,6 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Default"
{
New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "" -Force
@ -5703,10 +5598,12 @@ function WindowsCapabilities
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Uninstall"
@ -9065,33 +8962,6 @@ function Import-Associations
function InstallVCRedist
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/VCRedist/2015%2B
winget install --id=Microsoft.VCRedist.2015+.x86 --exact --force --accept-source-agreements
winget install --id=Microsoft.VCRedist.2015+.x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
{
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
@ -9124,11 +8994,10 @@ function InstallVCRedist
)
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -9161,48 +9030,13 @@ function InstallDotNetRuntimes
$Runtimes
)
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
foreach ($Runtime in $Runtimes)
{
switch ($Runtime)
{
NET6x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/6
# .NET Desktop Runtime 6 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# Install .NET Desktop Runtime 6
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -9213,7 +9047,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 6 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -9222,6 +9068,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -9233,22 +9089,9 @@ function InstallDotNetRuntimes
)
Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
NET8x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# .NET Desktop Runtime 8 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# .NET Desktop Runtime 8
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -9259,7 +9102,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 8 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -9268,6 +9123,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -9281,7 +9146,6 @@ function InstallDotNetRuntimes
}
}
}
}
}
<#
@ -9597,20 +9461,6 @@ function RegistryBackup
#>
function Install-WSL
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json
@ -9626,6 +9476,16 @@ function Install-WSL
"Alias" = $_.Name
}
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Add-Type -AssemblyName PresentationCore, PresentationFramework
@ -9749,18 +9609,6 @@ function Install-WSL
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
}
#endregion WSL
@ -9907,10 +9755,10 @@ function UninstallUWPApps
# Xbox Speech To Text Overlay
"Microsoft.XboxSpeechToTextOverlay",
# Xbox Game Bar
# Game Bar
"Microsoft.XboxGamingOverlay",
# Xbox Game Bar Plugin
# Game Bar Plugin
"Microsoft.XboxGameOverlay"
)
@ -9923,6 +9771,10 @@ function UninstallUWPApps
"AppUp.IntelGraphicsControlPanel",
"AppUp.IntelGraphicsExperience",
# ELAN Touchpad
"ELANMicroelectronicsCorpo.ELANTouchpadforThinkpad",
"ELANMicroelectronicsCorpo.ELANTrackPointforThinkpa",
# Microsoft Application Compatibility Enhancements
"Microsoft.ApplicationCompatibilityEnhancements",
@ -9983,7 +9835,11 @@ function UninstallUWPApps
"NVIDIACorp.NVIDIAControlPanel",
# Realtek Audio Console
"RealtekSemiconductorCorp.RealtekAudioControl"
"RealtekSemiconductorCorp.RealtekAudioControl",
# Synaptics
"SynapticsIncorporated.SynapticsControlPanel",
"SynapticsIncorporated.24916F58D6E7"
)
#region Variables
@ -10208,7 +10064,7 @@ function UninstallUWPApps
$Window.Close() | Out-Null
# If Xbox Game Bar is selected to uninstall stop its processes
# If Game Bar is selected to uninstall stop its processes
if ($PackagesToRemove -match "Microsoft.XboxGamingOverlay")
{
Get-Process -Name GameBar, GameBarFTServer -ErrorAction Ignore | Stop-Process -Force
@ -12094,7 +11950,7 @@ function WindowsScriptHost
{
"Disable"
{
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
# Check whether any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" -ErrorAction Ignore | ForEach-Object -Process {
# Skip if a scheduled task exists
if ($_.State -eq "Ready")
@ -12176,6 +12032,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -12199,6 +12056,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -12250,7 +12108,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateScript({
# Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS
# Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS
((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $SecondaryDNS)
})]
[string]
@ -12258,7 +12116,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateScript({
# Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS
# Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS
((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $PrimaryDNS)
})]
[string]
@ -12740,7 +12598,7 @@ function MultipleInvokeContext
<#
.SYNOPSIS
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
.EXAMPLE
UpdateLGPEPolicies
@ -12771,6 +12629,8 @@ function UpdateLGPEPolicies
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Verbose -Message $Localization.GPOUpdate -Verbose
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKLM -Verbose
Write-Information -MessageData "" -InformationAction Continue
@ -12831,6 +12691,7 @@ function UpdateLGPEPolicies
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKCU -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Current User policies paths to scan recursively
$CU_Paths = @(

2
src/Sophia_Script_for_Windows_11_LTSC_2024/Sophia.ps1

@ -1225,7 +1225,7 @@ MultipleInvokeContext -Enable
#region Update Policies
<#
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc)
Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы

2
src/Sophia_Script_for_Windows_11_PowerShell_7/Localizations/uk-UA/Sophia.psd1

@ -11,7 +11,7 @@ TweakerWarning = Стабільність вашої
Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів.
RebootPending = Комп'ютер очікує на перезавантаження.
UnsupportedRelease = Виявлено нову версію.
KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1}
KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1}
CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script?
WindowsComponentBroken = {0} пошкоджено або видалено з ОС.
UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу.

2
src/Sophia_Script_for_Windows_11_PowerShell_7/Manifest/Sophia.psd1

@ -5,7 +5,7 @@
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014—2024 farag, Inestic & lowl1f3. All rights reserved'
Description = 'Module for Windows fine-tuning and automating the routine tasks'
PowerShellVersion = '7.3'
PowerShellVersion = '7.4'
ProcessorArchitecture = 'AMD64'
FunctionsToExport = '*'

557
src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

@ -286,6 +286,116 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
# Remove harmful blocked DNS domains list from https://github.com/schrebra/Windows.10.DNS.Block.List
Get-NetFirewallRule -DisplayName Block.MSFT* -ErrorAction Ignore | Remove-NetFirewallRule
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# Check whether Get-WindowsEdition cmdlet is working
# https://github.com/PowerShell/PowerShell/issues/21295
try
@ -523,20 +633,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
@ -566,12 +662,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
# Check whether all necessary files exist in the bin folder
$Files = @(
@ -622,20 +712,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
"22631"
{
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json
@ -647,17 +723,11 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_11
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
$LatestSupportedBuild = 0
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
}
# We may use Test-Path -Path variable:LatestSupportedBuild
@ -707,137 +777,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true}
}
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript {($_.DisplayName -match "Blocker MicrosoftTelemetry") -or ($_.DisplayName -match "Blocker MicrosoftExtra") -or ($_.DisplayName -match "windowsSpyBlocker")} | Remove-NetFirewallRule
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
$Parameters = @{
Uri = "https://github.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt"
UseBasicParsing = $true
Verbose = $true
}
$update = (Invoke-WebRequest @Parameters).Content
$Parameters = @{
Uri = "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt"
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = (Invoke-WebRequest @Parameters).Content
$IPArray += $extra, $extra_v6, $spy, $spy_v6, $update, $update_v6
# Split the Array variable content
$IPArray = $IPArray -split "`r?`n" | Where-Object -FilterScript {$_ -notmatch "#"}
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ((Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force | ForEach-Object -Process {$_.Trim()} | ForEach-Object -Process {
($_ -ne "") -and ($_ -ne " ") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_)
}) -contains $true)
{
Write-Warning -Message ($Localization.TweakerWarning -f "WindowsSpyBlocker")
# Clear hosts file
$hosts = Get-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force
$hosts | ForEach-Object -Process {
if (($_ -ne "") -and (-not $_.StartsWith("#")) -and ($IPArray -split "`r?`n" | Select-String -Pattern $_.Trim()))
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData}
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force
Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts"
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://github.com")
Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
@ -898,7 +837,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$Menu += [WinAPI.GetStrings]::GetString(16956)
}
# Check if current terminal is Windows Terminal
# Check whether current terminal is Windows Terminal
if ($env:WT_SESSION)
{
# https://github.com/microsoft/terminal/issues/14992
@ -4335,20 +4274,6 @@ function Cursors
{
"Dark"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4441,30 +4366,8 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Light"
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# Check whether https://github.com is alive
@ -4557,14 +4460,6 @@ function Cursors
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
"Default"
{
New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "" -Force
@ -4956,18 +4851,6 @@ public static bool MarkFileDelete (string sourcefile)
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
@ -5006,12 +4889,14 @@ public static bool MarkFileDelete (string sourcefile)
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
@ -6163,10 +6048,12 @@ function WindowsCapabilities
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice")
Write-Error -Message ($Localization.NoResponse -f "http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
}
"Uninstall"
@ -9602,33 +9489,6 @@ function DefaultTerminalApp
function InstallVCRedist
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/VCRedist/2015%2B
winget install --id=Microsoft.VCRedist.2015+.x86 --exact --force --accept-source-agreements
winget install --id=Microsoft.VCRedist.2015+.x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
{
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
@ -9661,11 +9521,10 @@ function InstallVCRedist
)
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
@ -9698,48 +9557,13 @@ function InstallDotNetRuntimes
$Runtimes
)
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
foreach ($Runtime in $Runtimes)
{
switch ($Runtime)
{
NET6x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/6
# .NET Desktop Runtime 6 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# Install .NET Desktop Runtime 6
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -9750,7 +9574,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com")
Write-Error -Message ($Localization.NoResponse -f "https://download.visualstudio.microsoft.com") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 6 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -9759,6 +9595,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -9770,22 +9616,9 @@ function InstallDotNetRuntimes
)
Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
NET8x64
{
if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller)
{
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller).Version -ge [System.Version]"1.17")
{
# .NET Desktop Runtime 8 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path "$env:TEMP\WinGet" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# .NET Desktop Runtime 8
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -9796,7 +9629,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 8 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
@ -9805,6 +9650,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net")
Write-Error -Message ($Localization.NoResponse -f "https://dotnetcli.blob.core.windows.net") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
@ -9818,7 +9673,6 @@ function InstallDotNetRuntimes
}
}
}
}
}
<#
@ -10134,20 +9988,6 @@ function RegistryBackup
#>
function Install-WSL
{
try
{
# Check the internet connection
$Parameters = @{
Name = "dns.msftncsi.com"
Server = "1.1.1.1"
DnsOnly = $true
ErrorAction = "Stop"
}
if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255")
{
return
}
try
{
# https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json
@ -10163,6 +10003,16 @@ function Install-WSL
"Alias" = $_.Name
}
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json") -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
Add-Type -AssemblyName PresentationCore, PresentationFramework
@ -10286,18 +10136,6 @@ function Install-WSL
# Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
catch [System.Net.WebException]
{
Write-Warning -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com")
Write-Error -Message ($Localization.NoResponse -f "https://raw.githubusercontent.com") -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
}
}
#endregion WSL
@ -10454,10 +10292,10 @@ function UninstallUWPApps
# Xbox Speech To Text Overlay
"Microsoft.XboxSpeechToTextOverlay",
# Xbox Game Bar
# Game Bar
"Microsoft.XboxGamingOverlay",
# Xbox Game Bar Plugin
# Game Bar Plugin
"Microsoft.XboxGameOverlay"
)
@ -10763,7 +10601,7 @@ function UninstallUWPApps
$Window.Close() | Out-Null
# If Xbox Game Bar is selected to uninstall stop its processes
# If Game Bar is selected to uninstall stop its processes
if ($PackagesToRemove -match "Microsoft.XboxGamingOverlay")
{
Get-Process -Name GameBar, GameBarFTServer -ErrorAction Ignore | Stop-Process -Force
@ -11018,13 +10856,13 @@ function TeamsAutostart
#region Gaming
<#
.SYNOPSIS
Xbox Game Bar
Game Bar
.PARAMETER Disable
Disable Xbox Game Bar
Disable Game Bar
.PARAMETER Enable
Enable Xbox Game Bar
Enable Game Bar
.EXAMPLE
XboxGameBar -Disable
@ -11033,7 +10871,7 @@ function TeamsAutostart
XboxGameBar -Enable
.NOTES
To prevent popping up the "You'll need a new app to open this ms-gamingoverlay" warning, you need to disable the Xbox Game Bar app, even if you uninstalled it before
To prevent popping up the "You'll need a new app to open this ms-gamingoverlay" warning, you need to disable the Game Bar app, even if you uninstalled it before
.NOTES
Current user
@ -11074,13 +10912,13 @@ function XboxGameBar
<#
.SYNOPSIS
Xbox Game Bar tips
Game Bar tips
.PARAMETER Disable
Disable Xbox Game Bar tips
Disable Game Bar tips
.PARAMETER Enable
Enable Xbox Game Bar tips
Enable Game Bar tips
.EXAMPLE
XboxGameTips -Disable
@ -12890,7 +12728,7 @@ function WindowsScriptHost
{
"Disable"
{
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
# Check whether any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" -ErrorAction Ignore | ForEach-Object -Process {
# Skip if a scheduled task exists
if ($_.State -eq "Ready")
@ -12980,6 +12818,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -13003,6 +12842,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
}
}
}
@ -13054,7 +12894,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateScript({
# Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS
# Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS
((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $SecondaryDNS)
})]
[string]
@ -13062,7 +12902,7 @@ function DNSoverHTTPS
[Parameter(Mandatory = $false)]
[ValidateScript({
# Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS
# Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS
((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $PrimaryDNS)
})]
[string]
@ -13904,7 +13744,7 @@ function OpenWindowsTerminalAdminContext
<#
.SYNOPSIS
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
.EXAMPLE
UpdateLGPEPolicies
@ -13935,6 +13775,8 @@ function UpdateLGPEPolicies
Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose
Write-Verbose -Message $Localization.GPOUpdate -Verbose
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKLM -Verbose
Write-Information -MessageData "" -InformationAction Continue
@ -13995,6 +13837,7 @@ function UpdateLGPEPolicies
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message HKCU -Verbose
Write-Information -MessageData "" -InformationAction Continue
# Current User policies paths to scan recursively
$CU_Paths = @(

2
src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1

@ -1349,7 +1349,7 @@ OpenWindowsTerminalAdminContext -Enable
#region Update Policies
<#
Display all policy registry keys (even manually created ones) in the Local Group Policy Editor snap-in (gpedit.msc)
This can take up to 30 minutes, depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes, depending on the number of policies created in the registry and your system resources
Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc)
Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы

Loading…
Cancel
Save