@ -2,8 +2,8 @@
. SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version : v6 . 0 . 3
Date : 25 . 08 . 2021
Version : v6 . 0 . 4
Date : 19 . 09 . 2021
Copyright ( c ) 2014 – 2021 farag
Copyright ( c ) 2019 – 2021 farag & Inestic
@ -16,7 +16,7 @@
. NOTES
Supported Windows 11 version
Version : 21H2
Build : 22000 . 160
Build : 22000 . 194
Editions : Home / Pro / Enterprise
. NOTES
@ -30,15 +30,15 @@
https : / / t . me / sophianews
https : / / t . me / sophia_chat
. LINK Authors
https : / / github . com / farag2
https : / / github . com / Inestic
. LINK
. NOTES
https : / / forum . ru-board . com / topic . cgi ? forum = 62 & topic = 30617 #15
https : / / habr . com / company / skillfactory / blog / 553800 /
https : / / forums . mydigitallife . net / threads / powershell-windows - 10 -sophia -script . 81675 /
https : / / www . reddit . com / r / PowerShell / comments / go2n5v / powershell_script_setup_windows_10 /
. LINK Authors
https : / / github . com / farag2
https : / / github . com / Inestic
#>
#region Checkings
@ -66,18 +66,26 @@ function Checkings
}
}
# Check whether the OS minor build version is 160 minimum
switch ( ( Get-ItemPropertyValue -Path " HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion " -Name UBR ) -ge 160 )
# Check whether the OS minor build version is 194 minimum
switch ( ( Get-ItemPropertyValue -Path " HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion " -Name UBR ) -ge 194 )
{
$false
{
$Version = Get-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion "
Write-Warning -Message ( $Localization . UpdateWarning -f $Version . CurrentBuild , $Version . UBR )
# Check for updates
# Receive updates for other Microsoft products when you update Windows
( New-Object -ComObject Microsoft . Update . ServiceManager ) . AddService2 ( " 7971f918-a847-4430-9279-4a52d1efe18d " , 7 , " " )
Start-Sleep -Seconds 1
# Open the "Windows Update" page
Start-Process -FilePath " ms-settings:windowsupdate-action "
Start-Sleep -Seconds 3
Start-Process -FilePath " ms-settings:windowsupdate-optionalupdates "
Start-Sleep -Seconds 1
# Trigger Windows Update for detecting new updates
( New-Object -ComObject Microsoft . Update . AutoUpdate ) . DetectNow ( )
exit
}
@ -93,7 +101,7 @@ function Checkings
Start-Sleep -Seconds 5
Start-Process -FilePath " https://docs.microsoft.com/en-us/ windows/whats-new/windows-11-requirements "
Start-Process -FilePath " https://docs.microsoft.com/windows/whats-new/windows-11-requirements "
exit
}
}
@ -179,7 +187,7 @@ function Checkings
}
# Unblock all files in the script folder by removing the Zone.Identifier alternate data stream with a value of "3"
Get-ChildItem -Path $PSScriptRoot -Recurse -Force | Unblock-File
Get-ChildItem -Path $PSScriptRoot \ . . \ -File -Recurse -Force | Unblock-File
# Display a warning message about whether a user has customized the preset file
if ( $Warning )
@ -232,12 +240,12 @@ function Checkings
#endregion Checkings
#region Protection
# Enable script logging. The log will be being recorded into the script folder
# Enable script logging. The log will be being recorded into the script root folder
# To stop logging just close the console or type "Stop-Transcript"
function Logging
{
$TrascriptFilename = " Log- $( ( Get-Date ) . ToString ( " dd.MM.yyyy-HH-mm " ) ) "
Start-Transcript -Path $PSScriptRoot \ $TrascriptFilename . txt -Force
Start-Transcript -Path $PSScriptRoot \ . . \ $TrascriptFilename . txt -Force
}
# Create a restore point for the system drive
@ -514,7 +522,7 @@ function FeedbackFrequency
}
" Automatically "
{
Remove-Item -Path HKCU : \ SOFTWARE \ Microsoft \ Siuf \ Rules -Force -ErrorAction SilentlyContinu e
Remove-Item -Path HKCU : \ SOFTWARE \ Microsoft \ Siuf \ Rules -Force -ErrorAction Ignor e
}
}
}
@ -801,10 +809,13 @@ function ScheduledTasks
if ( -not ( $Tasks ) )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . NoData -Verbose
return
}
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . DialogBoxOpening -Verbose
#region Sendkey function
@ -814,9 +825,9 @@ function ScheduledTasks
Add-Type -AssemblyName System . Windows . Forms
$SetForegroundWindow = @ {
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " user32.dll " ) ]
public static extern bool ShowWindowAsync ( IntPtr hWnd , int nCmdShow ) ;
@ -1509,7 +1520,7 @@ function Windows10FileExplorer
}
" Disable "
{
Remove-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked " -Name " {E2BF9676-5F8F-435C-97EB-11607A5BEDF7} " -Force
Remove-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked " -Name " {E2BF9676-5F8F-435C-97EB-11607A5BEDF7} " -Force -ErrorAction Ignore
}
}
@ -2053,24 +2064,27 @@ function FileTransferDialog
<#
. SYNOPSIS
The File Explorer ribbon
The Windows 10 File Explorer ribbon
. PARAMETER Expanded
Expand the File Explorer ribbon
Expand the Windows 10 File Explorer ribbon
. PARAMETER Minimized
Minimize the File Explorer ribbon
Minimize the Windows 10 File Explorer ribbon
. EXAMPLE
FileExplorerRibbon -Expanded
Windows10 FileExplorerRibbon -Expanded
. EXAMPLE
FileExplorerRibbon -Minimized
Windows10FileExplorerRibbon -Minimized
. NOTES
In order this feature to work you need to enable the Windows 10 File Explorer ( Windows10FileExplorer -Enable )
. NOTES
Current user
#>
function FileExplorerRibbon
function Windows10 FileExplorerRibbon
{
param
(
@ -2581,9 +2595,9 @@ function UnpinTaskbarShortcuts
# Extract strings from shell32.dll using its' number
$Signature = @ {
Namespace = " WinAPI "
Name = " GetStr "
Language = " CSharp "
Namespace = " WinAPI "
Name = " GetStr "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " kernel32.dll " , CharSet = CharSet . Auto ) ]
public static extern IntPtr GetModuleHandle ( string lpModuleName ) ;
@ -2617,9 +2631,8 @@ public static string GetString(uint strId)
if ( Test-Path -Path " $ env:AppData\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Edge.lnk " )
{
# Call the shortcut context menu item
$Shell = New-Object -ComObject Shell . Application
$Folder = $Shell . NameSpace ( " $ env:AppData\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar " )
$Shortcut = $Folder . ParseName ( " Microsoft Edge.lnk " )
$Shell = ( New-Object -ComObject Shell . Application ) . NameSpace ( " $ env:AppData\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar " )
$Shortcut = $Shell . ParseName ( " Microsoft Edge.lnk " )
$Shortcut . Verbs ( ) | Where-Object -FilterScript { $_ . Name -eq $LocalizedString } | ForEach-Object -Process { $_ . DoIt ( ) }
}
}
@ -2930,11 +2943,11 @@ function FirstLogonAnimation
{
" Disable "
{
New-ItemProperty -Path HKLM : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Policies \ System -Name EnableFirstLogonAnimation -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon " -Name EnableFirstLogonAnimation -PropertyType DWord -Value 0 -Force
}
" Enable "
{
New-ItemProperty -Path HKLM : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Policies \ System -Name EnableFirstLogonAnimation -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon " -Name EnableFirstLogonAnimation -PropertyType DWord -Value 1 -Force
}
}
}
@ -3373,6 +3386,7 @@ function OneDrive
[string] $UninstallString = Get-Package -Name " Microsoft OneDrive " -ProviderName Programs -ErrorAction Ignore | ForEach-Object -Process { $_ . Meta . Attributes [ " UninstallString " ] }
if ( $UninstallString )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . OneDriveUninstalling -Verbose
Stop-Process -Name OneDrive -Force -ErrorAction Ignore
@ -3401,9 +3415,9 @@ function OneDrive
# The system does not move the file until the operating system is restarted
# The system moves the file immediately after AUTOCHK is executed, but before creating any paging files
$Signature = @ {
Namespace = " WinAPI "
Name = " DeleteFiles "
Language = " CSharp "
Namespace = " WinAPI "
Name = " DeleteFiles "
Language = " CSharp "
MemberDefinition = @ "
public enum MoveFileFlags
{
@ -3512,25 +3526,40 @@ public static bool MarkFileDelete (string sourcefile)
{
if ( Test-Path -Path $env:SystemRoot \ SysWOW64 \ OneDriveSetup . exe )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . OneDriveInstalling -Verbose
Start-Process -FilePath $env:SystemRoot \ SysWOW64 \ OneDriveSetup . exe
}
else
{
# Downloading the latest OneDrive
try
{
# Downloading the latest OneDrive installer x64
if ( ( Invoke-WebRequest -Uri https : / / www . google . com -UseBasicParsing -DisableKeepAlive -Method Head ) . StatusDescription )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . OneDriveDownloading -Verbose
[Net.ServicePointManager] :: SecurityProtocol = [Net.SecurityProtocolType] :: Tls12
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @ {
Uri = " https://g.live.com/1rewlive5skydrive/OneDriveProduction "
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Remove invalid chars
[xml] $OneDriveXML = $Content -replace "  " , " "
$OneDriveURL = ( $OneDriveXML ) . root . update . amd64binary . url [ - 1 ]
$DownloadsFolder = Get-ItemPropertyValue -Path " HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders " -Name " {374DE290-123F-4565-9164-39C4925E467B} "
$Parameters = @ {
Uri = " https://go.microsoft.com/fwlink/p/?LinkID=2121808 "
Uri = $OneDriveURL
OutFile = " $ DownloadsFolder\OneDriveSetup.exe "
Verbose = [switch] :: Present
Verbose = $true
}
Invoke-WebRequest @Parameters
@ -3549,6 +3578,7 @@ public static bool MarkFileDelete (string sourcefile)
}
Get-ScheduledTask -TaskName " Onedrive* Update* " | Enable-ScheduledTask
Get-ScheduledTask -TaskName " Onedrive* Update* " | Start-ScheduledTask
}
}
}
@ -3790,10 +3820,10 @@ function Hibernation
The % TEMP % environment variable path
. PARAMETER SystemDrive
Change the % TEMP % environment variable path to " %SystemDrive%\Temp "
Change the % TEMP % environment variable path to % SystemDrive % \ Temp
. PARAMETER Default
Change the % TEMP % environment variable path to " %LOCALAPPDATA%\Temp "
Change the % TEMP % environment variable path to % LOCALAPPDATA % \ Temp
. EXAMPLE
TempFolder -SystemDrive
@ -3857,9 +3887,9 @@ function TempFolder
# The system does not move the file until the operating system is restarted
# The system moves the file immediately after AUTOCHK is executed, but before creating any paging files
$Signature = @ {
Namespace = " WinAPI "
Name = " DeleteFiles "
Language = " CSharp "
Namespace = " WinAPI "
Name = " DeleteFiles "
Language = " CSharp "
MemberDefinition = @ "
public enum MoveFileFlags
{
@ -3901,10 +3931,10 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false
" @
# Create a temporary scheduled task to create a symbolic link to the %SystemDrive%\Temp folder
$Action = New-ScheduledTaskAction -Execute powershell . exe -Argument " -WindowStyle Hidden -Command $ SymbolicLinkTask "
$Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME
$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8
$Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
$Action = New-ScheduledTaskAction -Execute powershell . exe -Argument " -WindowStyle Hidden -Command $ SymbolicLinkTask "
$Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME
$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8
$Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
$Parameters = @ {
TaskName = " SymbolicLink "
Principal = $Principal
@ -3921,7 +3951,7 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false
}
#region main
# Change the %TEMP% environment variable path to " %LOCALAPPDATA%\Temp"
# Change the %TEMP% environment variable path to %LOCALAPPDATA%\Temp
[Environment] :: SetEnvironmentVariable ( " TMP " , " $ env:SystemDrive\Temp " , " User " )
[Environment] :: SetEnvironmentVariable ( " TMP " , " $ env:SystemDrive\Temp " , " Machine " )
[Environment] :: SetEnvironmentVariable ( " TMP " , " $ env:SystemDrive\Temp " , " Process " )
@ -3972,9 +4002,9 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false
# The system does not move the file until the operating system is restarted
# The system moves the file immediately after AUTOCHK is executed, but before creating any paging files
$Signature = @ {
Namespace = " WinAPI "
Name = " DeleteFiles "
Language = " CSharp "
Namespace = " WinAPI "
Name = " DeleteFiles "
Language = " CSharp "
MemberDefinition = @ "
public enum MoveFileFlags
{
@ -4014,10 +4044,10 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false
" @
# Create a temporary scheduled task to clean up the temporary folder
$Action = New-ScheduledTaskAction -Execute powershell . exe -Argument " -WindowStyle Hidden -Command $ TempFolderCleanupTask "
$Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME
$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8
$Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
$Action = New-ScheduledTaskAction -Execute powershell . exe -Argument " -WindowStyle Hidden -Command $ TempFolderCleanupTask "
$Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME
$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8
$Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
$Parameters = @ {
TaskName = " TemporaryTask "
Principal = $Principal
@ -4029,7 +4059,7 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false
}
#region main
# Change the %TEMP% environment variable path to " %LOCALAPPDATA%\Temp"
# Change the %TEMP% environment variable path to %LOCALAPPDATA%\Temp
[Environment] :: SetEnvironmentVariable ( " TMP " , " $ env:LOCALAPPDATA\Temp " , " User " )
[Environment] :: SetEnvironmentVariable ( " TMP " , " $ env:SystemRoot\TEMP " , " Machine " )
[Environment] :: SetEnvironmentVariable ( " TMP " , " $ env:LOCALAPPDATA\Temp " , " Process " )
@ -4247,7 +4277,7 @@ function MappedDrivesAppElevatedAccess
}
" Disable "
{
New -ItemProperty -Path HKLM : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Policies \ System -Name EnableLinkedConnections -PropertyType DWord -Value 0 -Forc e
Remove -ItemProperty -Path HKLM : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Policies \ System -Name EnableLinkedConnections -Force -ErrorAction Ignor e
}
}
}
@ -4670,6 +4700,7 @@ function WindowsFeatures
}
}
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
# Getting list of all optional features according to the conditions
@ -4681,10 +4712,13 @@ function WindowsFeatures
if ( -not ( $Features ) )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . NoData -Verbose
return
}
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . DialogBoxOpening -Verbose
#region Sendkey function
@ -4694,9 +4728,9 @@ function WindowsFeatures
Add-Type -AssemblyName System . Windows . Forms
$SetForegroundWindow = @ {
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " user32.dll " ) ]
public static extern bool ShowWindowAsync ( IntPtr hWnd , int nCmdShow ) ;
@ -4950,6 +4984,7 @@ function WindowsCapabilities
function UninstallButton
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
[void] $Window . Close ( )
@ -4959,12 +4994,14 @@ function WindowsCapabilities
if ( [string] $SelectedCapabilities . Name -match " Browser.InternetExplorer " )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . RestartWarning
}
}
function InstallButton
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
[void] $Window . Close ( )
@ -4974,6 +5011,7 @@ function WindowsCapabilities
if ( [string] $SelectedCapabilities . Name -match " Browser.InternetExplorer " )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . RestartWarning
}
}
@ -5051,6 +5089,7 @@ function WindowsCapabilities
}
}
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
# Getting list of all capabilities according to the conditions
@ -5062,10 +5101,13 @@ function WindowsCapabilities
if ( -not ( $Capabilities ) )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . NoData -Verbose
return
}
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . DialogBoxOpening -Verbose
#region Sendkey function
@ -5075,9 +5117,9 @@ function WindowsCapabilities
Add-Type -AssemblyName System . Windows . Forms
$SetForegroundWindow = @ {
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " user32.dll " ) ]
public static extern bool ShowWindowAsync ( IntPtr hWnd , int nCmdShow ) ;
@ -5588,18 +5630,18 @@ function SetUserShellFolderLocation
)
$KnownFolders = @ {
" Desktop " = @ ( " B4BFCC3A-DB2C-424C-B029-7FE99A87C641 " ) ;
" Documents " = @ ( " FDD39AD0-238F-46AF-ADB4-6C85480369C7 " , " f42ee2d3-909f-4907-8871-4c22fc0bf756 " ) ;
" Downloads " = @ ( " 374DE290-123F-4565-9164-39C4925E467B " , " 7d83ee9b-2244-4e70-b1f5-5393042af1e4 " ) ;
" Music " = @ ( " 4BD8D571-6D19-48D3-BE97-422220080E43 " , " a0c69a99-21c8-4671-8703-7934162fcf1d " ) ;
" Pictures " = @ ( " 33E28130-4E1E-4676-835A-98395C3BC3BB " , " 0ddd015d-b06c-45d5-8c4c-f59713854639 " ) ;
" Videos " = @ ( " 18989B1D-99B5-455B-841C-AB7C74E4DDFC " , " 35286a68-3c57-41a1-bbb1-0eae73d76c95 " ) ;
" Desktop " = @ ( " B4BFCC3A-DB2C-424C-B029-7FE99A87C641 " ) ;
" Documents " = @ ( " FDD39AD0-238F-46AF-ADB4-6C85480369C7 " , " f42ee2d3-909f-4907-8871-4c22fc0bf756 " ) ;
" Downloads " = @ ( " 374DE290-123F-4565-9164-39C4925E467B " , " 7d83ee9b-2244-4e70-b1f5-5393042af1e4 " ) ;
" Music " = @ ( " 4BD8D571-6D19-48D3-BE97-422220080E43 " , " a0c69a99-21c8-4671-8703-7934162fcf1d " ) ;
" Pictures " = @ ( " 33E28130-4E1E-4676-835A-98395C3BC3BB " , " 0ddd015d-b06c-45d5-8c4c-f59713854639 " ) ;
" Videos " = @ ( " 18989B1D-99B5-455B-841C-AB7C74E4DDFC " , " 35286a68-3c57-41a1-bbb1-0eae73d76c95 " ) ;
}
$Signature = @ {
Namespace = " WinAPI "
Name = " KnownFolders "
Language = " CSharp "
Namespace = " WinAPI "
Name = " KnownFolders "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " shell32.dll " ) ]
public extern static int SHSetKnownFolderPath ( ref Guid folderId , uint flags , IntPtr token , [ MarshalAs ( UnmanagedType . LPWStr ) ] string path ) ;
@ -5779,9 +5821,9 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int
# Get the localized user folders names
$Signature = @ {
Namespace = " WinAPI "
Name = " GetStr "
Language = " CSharp "
Namespace = " WinAPI "
Name = " GetStr "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " kernel32.dll " , CharSet = CharSet . Auto ) ]
public static extern IntPtr GetModuleHandle ( string lpModuleName ) ;
@ -5815,6 +5857,7 @@ public static string GetString(uint strId)
{
" Root "
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . RetrievingDrivesList -Verbose
Write-Information -MessageData " " -InformationAction Continue
@ -5838,7 +5881,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $DesktopLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -5872,7 +5914,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $DocumentsLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -5906,7 +5947,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $DownloadsLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -5940,7 +5980,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $MusicLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -5972,8 +6011,8 @@ public static string GetString(uint strId)
$CurrentUserFolderLocation = Get-ItemPropertyValue -Path " HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders " -Name " My Pictures "
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $PicturesLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6007,7 +6046,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $VideosLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6041,7 +6079,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $DesktopLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6085,7 +6122,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $DocumentsLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6129,7 +6165,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $DownloadsLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6173,7 +6208,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $MusicLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6217,7 +6251,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $PicturesLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6261,7 +6294,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $VideosLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6307,7 +6339,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $DesktopLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6338,7 +6369,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $DocumentsLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6369,7 +6399,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $DownloadsLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6400,7 +6429,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $MusicLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6431,7 +6459,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $PicturesLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6462,7 +6489,6 @@ public static string GetString(uint strId)
Write-Verbose -Message ( $Localization . CurrentUserFolderLocation -f $VideosLocalizedString , $CurrentUserFolderLocation ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . FilesWontBeMoved
Write-Information -MessageData " " -InformationAction Continue
@ -6556,7 +6582,7 @@ function WinPrtScrFolder
{
if ( Test-Path -Path $OpenedFolder )
{
Invoke-Item -Path $OpenedFolder
Start-Process -FilePath explorer -ArgumentList $OpenedFolder
}
}
}
@ -6572,7 +6598,7 @@ function WinPrtScrFolder
Ask me before running troubleshooter
. EXAMPLE
RecommendedTroubleshooting -Automatic
RecommendedTroubleshooting -Automatically
. EXAMPLE
RecommendedTroubleshooting -Default
@ -6589,10 +6615,10 @@ function RecommendedTroubleshooting
(
[ Parameter (
Mandatory = $true ,
ParameterSetName = " Automatic "
ParameterSetName = " Automatically "
) ]
[switch]
$Automatic ,
$Automatically ,
[ Parameter (
Mandatory = $true ,
@ -6604,7 +6630,7 @@ function RecommendedTroubleshooting
switch ( $PSCmdlet . ParameterSetName )
{
" Automatic "
" Automatically "
{
if ( -not ( Test-Path -Path HKLM : \ SOFTWARE \ Microsoft \ WindowsMitigation ) )
{
@ -6795,7 +6821,7 @@ function F1HelpPage
}
" Enable "
{
Remove-Item -Path " HKCU:\SOFTWARE\Classes\Typelib\{8cec5860-07a1-11d9-b15e-000d56bfe6ee} " -Recurse -Force -ErrorAction SilentlyContinu e
Remove-Item -Path " HKCU:\SOFTWARE\Classes\Typelib\{8cec5860-07a1-11d9-b15e-000d56bfe6ee} " -Recurse -Force -ErrorAction Ignor e
}
}
}
@ -6897,7 +6923,7 @@ function CapsLock
}
" Enable "
{
Remove-ItemProperty -Path " HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout " -Name " Scancode Map " -Force
Remove-ItemProperty -Path " HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout " -Name " Scancode Map " -Force -ErrorAction Ignore
}
}
}
@ -7895,6 +7921,7 @@ namespace FileAssoc
Set-Icon -ProgId $ProgId -Icon $Icon
}
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
# Setting additional parameters to comply with the requirements before configuring the extension
@ -7905,9 +7932,9 @@ namespace FileAssoc
# Refresh the desktop icons
$UpdateExplorer = @ {
Namespace = " WinAPI "
Name = " UpdateExplorer "
Language = " CSharp "
Namespace = " WinAPI "
Name = " UpdateExplorer "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " shell32.dll " , CharSet = CharSet . Auto , SetLastError = false ) ]
private static extern int SHChangeNotify ( int eventId , int flags , IntPtr item1 , IntPtr item2 ) ;
@ -8129,9 +8156,9 @@ function WSL
Add-Type -AssemblyName System . Windows . Forms
$SetForegroundWindow = @ {
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " user32.dll " ) ]
public static extern bool ShowWindowAsync ( IntPtr hWnd , int nCmdShow ) ;
@ -8499,6 +8526,7 @@ function UninstallUWPApps
$AllUsers
)
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
$AppxPackages = @ ( Get-AppxPackage -PackageTypeFilter Bundle -AllUsers : $AllUsers | Where-Object -FilterScript { $_ . Name -notin $ExcludedAppxPackages } )
@ -8591,6 +8619,7 @@ function UninstallUWPApps
function ButtonUninstallClick
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
$Window . Close ( ) | Out-Null
@ -8678,10 +8707,12 @@ function UninstallUWPApps
if ( $AppxPackages . Count -eq 0 )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . NoData -Verbose
}
else
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . DialogBoxOpening -Verbose
#region Sendkey function
@ -8691,9 +8722,9 @@ function UninstallUWPApps
Add-Type -AssemblyName System . Windows . Forms
$SetForegroundWindow = @ {
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " user32.dll " ) ]
public static extern bool ShowWindowAsync ( IntPtr hWnd , int nCmdShow ) ;
@ -8762,7 +8793,7 @@ function RestoreUWPApps
xmlns : x = " http://schemas.microsoft.com/winfx/2006/xaml "
Name = " Window "
MinHeight = " 400 " MinWidth = " 410 "
SizeToContent = " WidthAndHeight " WindowStartupLocation = " CenterScreen "
SizeToContent = " Width " WindowStartupLocation = " CenterScreen "
TextOptions . TextFormattingMode = " Display " SnapsToDevicePixels = " True "
FontFamily = " Candara " FontSize = " 16 " ShowInTaskbar = " True "
Background = " #F1F1F1 " Foreground = " #262626 " >
@ -8839,11 +8870,17 @@ function RestoreUWPApps
#region Functions
function Get-AppxManifest
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
# You cannot retrieve packages using -PackageTypeFilter Bundle, otherwise you won't get the InstallLocation attribute. It can be retrieved only by comparing with $Bundles
$Bundles = ( Get-AppXPackage -PackageTypeFilter Bundle -AllUsers ) . Name
$AppxPackages = Get-AppxPackage -AllUsers | Where-Object -FilterScript { $_ . PackageUserInformation -match " Staged " } | Where-Object -FilterScript { $_ . Name -in $Bundles }
$AppxPackages = @ ( Get-AppxPackage -AllUsers | Where-Object -FilterScript { $_ . PackageUserInformation -match " Staged " } | Where-Object -FilterScript { $_ . Name -in $Bundles } )
# The Bundle packages contains no Microsoft Teams
if ( Get-AppxPackage -Name MicrosoftTeams -AllUsers )
{
$AppxPackages + = Get-AppxPackage -Name MicrosoftTeams -AllUsers | Where-Object -FilterScript { $_ . PackageUserInformation -match " Staged " }
}
$PackagesIds = [ Windows . Management . Deployment . PackageManager , Windows . Web , ContentType = WindowsRuntime ] :: new ( ) . FindPackages ( ) | Select-Object -Property DisplayName -ExpandProperty Id | Select-Object -Property Name , DisplayName
foreach ( $AppxPackage in $AppxPackages )
@ -8912,6 +8949,7 @@ function RestoreUWPApps
function ButtonRestoreClick
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
$Window . Close ( ) | Out-Null
@ -8920,8 +8958,8 @@ function RestoreUWPApps
Register = $true
ForceApplicationShutdown = $true
ForceUpdateFromAnyVersion = $true
DisableDevelopmentMod = $true
Verbose = [switch] :: Present
DisableDevelopmentMode = $true
Verbose = $true
}
$PackagesToRestore | Add-AppxPackage @Parameters
}
@ -8994,10 +9032,12 @@ function RestoreUWPApps
if ( $AppxPackages . Count -eq 0 )
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . NoData -Verbose
}
else
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . DialogBoxOpening -Verbose
#region Sendkey function
@ -9007,9 +9047,9 @@ function RestoreUWPApps
Add-Type -AssemblyName System . Windows . Forms
$SetForegroundWindow = @ {
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
Namespace = " WinAPI "
Name = " ForegroundWindow "
Language = " CSharp "
MemberDefinition = @ "
[ DllImport ( " user32.dll " ) ]
public static extern bool ShowWindowAsync ( IntPtr hWnd , int nCmdShow ) ;
@ -9104,7 +9144,7 @@ function HEIF
" Install "
{
# Check whether the extension is already installed
if ( -not ( Get-AppxPackage -Name Microsoft . HEVCVideoExtension ) -and ( Get-AppxPackage -Name Microsoft . Windows . Photos ) )
if ( ( -not ( Get-AppxPackage -Name Microsoft . HEVCVideoExtension ) ) -and ( Get-AppxPackage -Name Microsoft . Windows . Photos ) )
{
try
{
@ -9142,9 +9182,9 @@ function HEIF
$DownloadsFolder = Get-ItemPropertyValue -Path " HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders " -Name " {374DE290-123F-4565-9164-39C4925E467B} "
$Parameters = @ {
Uri = $TempURL
Uri = $TempURL
OutFile = " $ DownloadsFolder\ $ Package "
Verbose = [switch] :: Present
Verbose = $true
}
Invoke-WebRequest @Parameters
@ -9450,6 +9490,7 @@ function SetAppGraphicsPerformance
}
" 1 "
{
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Skipped -Verbose
}
}
@ -9681,9 +9722,9 @@ while (`$true)
" @
# Create the "Windows Cleanup" task
$Action = New-ScheduledTaskAction -Execute powershell . exe -Argument " -WindowStyle Hidden -Command $ CleanupTask "
$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable
$Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
$Action = New-ScheduledTaskAction -Execute powershell . exe -Argument " -WindowStyle Hidden -Command $ CleanupTask "
$Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable
$Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
$Parameters = @ {
TaskName = " Windows Cleanup "
TaskPath = " Sophia Script "
@ -10365,7 +10406,7 @@ function EventViewerCustomView
}
" Disable "
{
Remove-Item -Path " $ env:ProgramData\Microsoft\Event Viewer\Views\ProcessCreation.xml " -Force -ErrorAction SilentlyContinu e
Remove-Item -Path " $ env:ProgramData\Microsoft\Event Viewer\Views\ProcessCreation.xml " -Force -ErrorAction Ignor e
}
}
}
@ -10884,16 +10925,15 @@ function MSIExtractContext
{
New-Item -Path Registry :: HKEY_CLASSES_ROOT \ Msi . Package \ shell \ Extract \ Command -Force
}
$Value = " {0} " -f 'msiexec.exe /a "%1" /qb TARGETDIR="%1 extracted"'
$Value = " {0} " -f " msiexec.exe /a `" %1 `" /qb TARGETDIR= `" %1 extracted `" "
New-ItemProperty -Path Registry :: HKEY_CLASSES_ROOT \ Msi . Package \ shell \ Extract \ Command -Name " (default) " -PropertyType String -Value $Value -Force
New-ItemProperty -Path Registry :: HKEY_CLASSES_ROOT \ Msi . Package \ shell \ Extract -Name MUIVerb -PropertyType String -Value " @shell32.dll,-37514 " -Force
New-ItemProperty -Path Registry :: HKEY_CLASSES_ROOT \ Msi . Package \ shell \ Extract -Name Icon -PropertyType String -Value " shell32.dll,-16817 " -Force
}
" Hide "
{
Remove-Item -Path Registry :: HKEY_CLASSES_ROOT \ Msi . Package \ shell \ Extract -Recurse -Force -ErrorAction SilentlyContinu e
Remove-Item -Path Registry :: HKEY_CLASSES_ROOT \ Msi . Package \ shell \ Extract -Recurse -Force -ErrorAction Ignor e
}
}
}
@ -10950,9 +10990,8 @@ function CABInstallContext
}
" Hide "
{
Remove-Item -Path Registry :: HKEY_CLASSES_ROOT \ CABFolder \ Shell \ RunAs -Recurse -Force -ErrorAction SilentlyContinu e
Remove-Item -Path Registry :: HKEY_CLASSES_ROOT \ CABFolder \ Shell \ RunAs -Recurse -Force -ErrorAction Ignor e
}
}
}
@ -11678,9 +11717,9 @@ function OpenWindowsTerminalContext
function RefreshEnvironment
{
$UpdateEnvironment = @ {
Namespace = " WinAPI "
Name = " UpdateEnvironment "
Language = " CSharp "
Namespace = " WinAPI "
Name = " UpdateEnvironment "
Language = " CSharp "
MemberDefinition = @ "
private static readonly IntPtr HWND_BROADCAST = new IntPtr ( 0xffff ) ;
private const int WM_SETTINGCHANGE = 0x1a ;
@ -11809,13 +11848,13 @@ function Errors
{
if ( $Global:Error )
{
# Some errors may have the Windows nature and don't have a path to any of the module's files
$ErrorInFile = if ( $_ . InvocationInfo . PSCommandPath )
{
Split-Path -Path $_ . InvocationInfo . PSCommandPath -Leaf
}
( $Global:Error | ForEach-Object -Process {
# Some errors may have the Windows nature and don't have a path to any of the module's files
$ErrorInFile = if ( $_ . InvocationInfo . PSCommandPath )
{
Split-Path -Path $_ . InvocationInfo . PSCommandPath -Leaf
}
[PSCustomObject] @ {
$Localization . ErrorsLine = $_ . InvocationInfo . ScriptLineNumber
$Localization . ErrorsFile = $ErrorInFile