@ -451,7 +451,8 @@ function Checks
}
}
Remove-Item -Path " $ env:TEMP\Computer.txt " , " $ env:TEMP\User.txt " -Force -ErrorAction Ignore
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
Get-ChildItem -Path " $ env:TEMP\Computer.txt " , " $ env:TEMP\User.txt " -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
# Save all opened folders in order to restore them after File Explorer restart
$Script:OpenedFolders = { ( New-Object -ComObject Shell . Application ) . Windows ( ) | ForEach-Object -Process { $_ . Document . Folder . Self . Path } } . Invoke ( )
@ -3747,9 +3748,7 @@ function OneDrive
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . OneDriveUninstalling -Verbose
Stop-Process -Name OneDrive -Force -ErrorAction Ignore
Stop-Process -Name OneDriveSetup -Force -ErrorAction Ignore
Stop-Process -Name FileCoAuth -Force -ErrorAction Ignore
Stop-Process -Name OneDrive , OneDriveSetup , FileCoAuth -Force -ErrorAction Ignore
# Getting link to the OneDriveSetup.exe and its' argument(s)
[string[]] $OneDriveSetup = ( $UninstallString -Replace ( " \s*/ " , " ,/ " ) ) . Split ( " , " ) . Trim ( )
@ -3818,10 +3817,7 @@ public static bool MarkFileDelete (string sourcefile)
}
Remove-ItemProperty -Path HKCU : \ Environment -Name OneDrive , OneDriveConsumer -Force -ErrorAction Ignore
Remove-Item -Path HKCU : \ Software \ Microsoft \ OneDrive -Recurse -Force -ErrorAction Ignore
Remove-Item -Path HKLM : \ SOFTWARE \ WOW6432Node \ Microsoft \ OneDrive -Recurse -Force -ErrorAction Ignore
Remove-Item -Path " $ env:ProgramData\Microsoft OneDrive " -Recurse -Force -ErrorAction Ignore
Remove-Item -Path $env:SystemDrive \ OneDriveTemp -Recurse -Force -ErrorAction Ignore
Remove-Item -Path HKCU : \ Software \ Microsoft \ OneDrive , HKLM : \ SOFTWARE \ WOW6432Node \ Microsoft \ OneDrive , " $ env:ProgramData\Microsoft OneDrive " , $env:SystemDrive \ OneDriveTemp -Recurse -Force -ErrorAction Ignore
Unregister-ScheduledTask -TaskName * OneDrive * -Confirm : $false -ErrorAction Ignore
# Getting the OneDrive folder path
@ -3870,10 +3866,7 @@ public static bool MarkFileDelete (string sourcefile)
}
}
Remove-Item -Path $OneDriveFolder -Recurse -Force -ErrorAction Ignore
Remove-Item -Path $env:LOCALAPPDATA \ OneDrive -Recurse -Force -ErrorAction Ignore
Remove-Item -Path $env:LOCALAPPDATA \ Microsoft \ OneDrive -Recurse -Force -ErrorAction Ignore
Remove-Item -Path " $ env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk " -Force -ErrorAction Ignore
Remove-Item -Path $OneDriveFolder , $env:LOCALAPPDATA \ OneDrive , $env:LOCALAPPDATA \ Microsoft \ OneDrive , " $ env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk " -Recurse -Force -ErrorAction Ignore
}
}
" Install "
@ -4227,14 +4220,17 @@ function TempFolder
{
" SystemDrive "
{
if ( $env:TEMP -ne " $ env:SystemDrive\Temp " )
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
if ( ( Get-Item -Path $env:TEMP ) . FullName -eq " $ env:SystemDrive\Temp " )
{
return ###
}
# Restart the Printer Spooler service (Spooler)
Restart-Service -Name Spooler -Force
# Stop OneDrive processes
Stop-Process -Name OneDrive -Force -ErrorAction Ignore
Stop-Process -Name FileCoAuth -Force -ErrorAction Ignore
Stop-Process -Name OneDrive , FileCoAuth -Force -ErrorAction Ignore
if ( -not ( Test-Path -Path $env:SystemDrive \ Temp ) )
{
@ -4320,7 +4316,6 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false
New-Item -Path $env:LOCALAPPDATA \ Temp -ItemType SymbolicLink -Value $env:SystemDrive \ Temp -Force
}
#region main
# Change the %TEMP% environment variable path to %LOCALAPPDATA%\Temp
# The additional registry key creating are needed to fix the property type of the keys: SetEnvironmentVariable creates them with the "String" type instead of "ExpandString" as by default
[Environment] :: SetEnvironmentVariable ( " TMP " , " $ env:SystemDrive\Temp " , " User " )
@ -4334,20 +4329,20 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false
New-ItemProperty -Path HKCU : \ Environment -Name TEMP -PropertyType ExpandString -Value $env:SystemDrive \ Temp -Force
New-ItemProperty -Path " HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment " -Name TMP -PropertyType ExpandString -Value $env:SystemDrive \ Temp -Force
New-ItemProperty -Path " HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment " -Name TEMP -PropertyType ExpandString -Value $env:SystemDrive \ Temp -Force
# endregion main
}
}
" Default "
{
if ( $env:TEMP -ne " $ env:LOCALAPPDATA\Temp " )
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
if ( ( Get-Item -Path $env:TEMP ) . FullName -eq " $ env:LOCALAPPDATA\Temp " )
{
return
}
# Restart the Printer Spooler service (Spooler)
Restart-Service -Name Spooler -Force
# Stop OneDrive processes
Stop-Process -Name OneDrive -Force -ErrorAction Ignore
Stop-Process -Name FileCoAuth -Force -ErrorAction Ignore
Stop-Process -Name OneDrive , FileCoAuth -Force -ErrorAction Ignore
# Remove a symbolic link to the %SystemDrive%\Temp folder
if ( Get-Item -Path $env:LOCALAPPDATA \ Temp -Force -ErrorAction Ignore | Where-Object -FilterScript { $_ . LinkType -eq " SymbolicLink " } )
@ -4365,7 +4360,8 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false
}
# Removing folders
Remove-Item -Path $env:TEMP -Recurse -Force -ErrorAction Ignore
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
Remove-Item -Path $ ( ( Get-Item -Path $env:TEMP ) . FullName ) -Recurse -Force -ErrorAction Ignore
if ( ( Get-ChildItem -Path $env:TEMP -Force -ErrorAction Ignore | Measure-Object ) . Count -ne 0 )
{
@ -4399,7 +4395,8 @@ public static bool MarkFileDelete (string sourcefile)
try
{
Remove-Item -Path $env:TEMP -Recurse -Force -ErrorAction Stop
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
Remove-Item -Path $ ( ( Get-Item -Path $env:TEMP ) . FullName ) -Recurse -Force -ErrorAction Stop
}
catch
{
@ -4407,10 +4404,10 @@ public static bool MarkFileDelete (string sourcefile)
Get-ChildItem -Path $env:TEMP -Recurse -Force -ErrorAction Ignore | ForEach-Object -Process { [WinAPI.DeleteFiles] :: MarkFileDelete ( $_ . FullName ) }
}
$TempFolder = [System.Environment] :: ExpandEnvironmentVariables ( $env:TEMP )
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
$TempFolder = ( Get-Item -Path $env:TEMP ) . FullName
$TempFolderCleanupTask = @ "
Remove-Item -Path " $ TempFolder " -Recurse -Force
Unregister-ScheduledTask -TaskName TemporaryTask -Confirm : `$ false
" @
@ -4429,7 +4426,6 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false
Register-ScheduledTask @Parameters -Force
}
#region main
# Change the %TEMP% environment variable path to %LOCALAPPDATA%\Temp
[Environment] :: SetEnvironmentVariable ( " TMP " , " $ env:LOCALAPPDATA\Temp " , " User " )
[Environment] :: SetEnvironmentVariable ( " TMP " , " $ env:SystemRoot\TEMP " , " Machine " )
@ -4443,8 +4439,6 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false
New-ItemProperty -Path " HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment " -Name TMP -PropertyType ExpandString -Value " %SystemRoot%\TEMP " -Force
New-ItemProperty -Path " HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment " -Name TEMP -PropertyType ExpandString -Value " %SystemRoot%\TEMP " -Force
# endregion main
}
}
}
}
@ -5710,7 +5704,7 @@ function LatestInstalled.NET
. NOTES
Current user
#>
function NetworkAdaptersSavePower ###
function NetworkAdaptersSavePower
{
param
(
@ -8615,15 +8609,7 @@ function InstallVCRedist
Start-Process -FilePath " $ DownloadsFolder\VC_redist.x64.exe " -ArgumentList " /install /passive /norestart " -Wait
<#
PowerShell 5 . 1 ( 7 . 2 too ) interprets the 8 . 3 file name literally , if an environment variable contains a non-latin word ,
so you won ' t be able to remove " $ env:TEMP\dd_vcredist_amd64_*.log " file explicitly
Another ways to get normal path to % TEMP %
[Environment] :: GetEnvironmentVariable ( " TEMP " , " User " )
( Get-ItemProperty -Path HKCU : \ Environment -Name TEMP ) . TEMP
[System.IO.Path] :: GetTempPath ( )
#>
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
Get-ChildItem -Path " $ DownloadsFolder\VC_redist.x86.exe " , " $ DownloadsFolder\VC_redist.x64.exe " , " $ env:TEMP\dd_vcredist_amdx86_*.log " , " $ env:TEMP\dd_vcredist_amd64_*.log " -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
@ -10758,9 +10744,7 @@ function CleanupTask
New-ItemProperty -Path Registry :: HKEY_CLASSES_ROOT \ WindowsCleanup \ shell \ open \ command -Name " (default) " -PropertyType String -Value 'powershell.exe -Command "& {Start-ScheduledTask -TaskPath ''\Sophia\'' -TaskName ''Windows Cleanup''}"' -Force
$CleanupTask = @ "
Get-Process -Name cleanmgr | Stop-Process -Force
Get-Process -Name Dism | Stop-Process -Force
Get-Process -Name DismHost | Stop-Process -Force
Get-Process -Name cleanmgr , Dism , DismHost | Stop-Process -Force
`$ ProcessInfo = New-Object -TypeName System . Diagnostics . ProcessStartInfo
`$ ProcessInfo . FileName = " "" $ env:SystemRoot\system32\cleanmgr.exe "" "
@ -10921,8 +10905,6 @@ while (`$true)
Remove-ItemProperty -Path $_ . PsPath -Name StateFlags1337 -Force -ErrorAction Ignore
}
Remove-Item -Path Registry :: HKEY_CLASSES_ROOT \ WindowsCleanup -Recurse -Force -ErrorAction Ignore
Remove-Item -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings \ Sophia -Recurse -Force -ErrorAction Ignore
Remove-Item -Path Registry :: HKEY_CLASSES_ROOT \ AppUserModelId \ Sophia -Force -ErrorAction Ignore
# Remove folder in Task Scheduler if there is no tasks left there
if ( Test-Path -Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia " )
@ -10931,6 +10913,8 @@ while (`$true)
{
$ScheduleService . GetFolder ( " \ " ) . DeleteFolder ( " Sophia " , $null )
}
Remove-Item -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings \ Sophia , Registry :: HKEY_CLASSES_ROOT \ AppUserModelId \ Sophia -Recurse -Force -ErrorAction Ignore
}
}
}
@ -11060,9 +11044,6 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For
}
" Delete "
{
Remove-Item -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings \ Sophia -Recurse -Force -ErrorAction Ignore
Remove-Item -Path Registry :: HKEY_CLASSES_ROOT \ AppUserModelId \ Sophia -Force -ErrorAction Ignore
# Remove all old tasks
Unregister-ScheduledTask -TaskPath " \Sophia Script\ " , " \SophiApp\ " -TaskName " Windows Cleanup " , " Windows Cleanup Notification " , SoftwareDistribution , Temp -Confirm : $false -ErrorAction Ignore
@ -11088,6 +11069,8 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For
{
$ScheduleService . GetFolder ( " \ " ) . DeleteFolder ( " Sophia " , $null )
}
Remove-Item -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings \ Sophia , Registry :: HKEY_CLASSES_ROOT \ AppUserModelId \ Sophia -Recurse -Force -ErrorAction Ignore
}
}
}
@ -11216,9 +11199,6 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_
}
" Delete "
{
Remove-Item -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings \ Sophia -Recurse -Force -ErrorAction Ignore
Remove-Item -Path Registry :: HKEY_CLASSES_ROOT \ AppUserModelId \ Sophia -Force -ErrorAction Ignore
# Remove all old tasks
Unregister-ScheduledTask -TaskPath " \Sophia Script\ " , " \SophiApp\ " -TaskName " Windows Cleanup " , " Windows Cleanup Notification " , SoftwareDistribution , Temp -Confirm : $false -ErrorAction Ignore
@ -11244,6 +11224,8 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_
{
$ScheduleService . GetFolder ( " \ " ) . DeleteFolder ( " Sophia " , $null )
}
Remove-Item -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings \ Sophia , Registry :: HKEY_CLASSES_ROOT \ AppUserModelId \ Sophia -Recurse -Force -ErrorAction Ignore
}
}
}
@ -12386,7 +12368,7 @@ function ShareContext
. NOTES
Current user
#>
function EditWithPhotosContext
function EditWithPhotosContext ###
{
param
(
@ -12405,7 +12387,7 @@ function EditWithPhotosContext
$Show
)
if ( ( Get-CimInstance -ClassName CIM_OperatingSystem ) . BuildNumber -le 22623 )
if ( ( Get-CimInstance -ClassName CIM_OperatingSystem ) . BuildNumber -lt 22621 )
{
if ( Get-AppxPackage -Name Microsoft . Windows . Photos )
{
@ -12443,7 +12425,7 @@ function EditWithPhotosContext
. NOTES
Current user
#>
function CreateANewVideoContext
function CreateANewVideoContext ###
{
param
(
@ -12462,6 +12444,8 @@ function CreateANewVideoContext
$Show
)
if ( ( Get-CimInstance -ClassName CIM_OperatingSystem ) . BuildNumber -lt 22621 )
{
if ( Get-AppxPackage -Name Microsoft . Windows . Photos )
{
switch ( $PSCmdlet . ParameterSetName )
@ -12476,6 +12460,7 @@ function CreateANewVideoContext
}
}
}
}
}
<#
@ -13354,7 +13339,8 @@ public static void PostMessage()
MeetNow -Hide
}
Remove-Item -Path " $ env:TEMP\Computer.txt " , " $ env:TEMP\User.txt " -Force -ErrorAction Ignore
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
Get-ChildItem -Path " $ env:TEMP\Computer.txt " , " $ env:TEMP\User.txt " -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3