Browse Source

Improved OneDrive function

pull/450/head
Dmitry Nefedov 1 year ago
parent
commit
b09d58efa6
  1. 2
      CHANGELOG.md
  2. 12
      sophia_script_versions.json
  3. 8
      src/Sophia_Script_for_Windows_10/Functions.ps1
  4. 2
      src/Sophia_Script_for_Windows_10/Manifest/Sophia.psd1
  5. 303
      src/Sophia_Script_for_Windows_10/Module/Sophia.psm1
  6. 10
      src/Sophia_Script_for_Windows_10/Sophia.ps1
  7. 8
      src/Sophia_Script_for_Windows_10_LTSC_2019/Functions.ps1
  8. 2
      src/Sophia_Script_for_Windows_10_LTSC_2019/Manifest/Sophia.psd1
  9. 2
      src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1
  10. 10
      src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1
  11. 8
      src/Sophia_Script_for_Windows_10_LTSC_2021/Functions.ps1
  12. 2
      src/Sophia_Script_for_Windows_10_LTSC_2021/Manifest/Sophia.psd1
  13. 2
      src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1
  14. 10
      src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1
  15. 8
      src/Sophia_Script_for_Windows_10_PowerShell_7/Functions.ps1
  16. 2
      src/Sophia_Script_for_Windows_10_PowerShell_7/Manifest/Sophia.psd1
  17. 309
      src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1
  18. 10
      src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1
  19. 8
      src/Sophia_Script_for_Windows_11/Functions.ps1
  20. 2
      src/Sophia_Script_for_Windows_11/Manifest/Sophia.psd1
  21. 303
      src/Sophia_Script_for_Windows_11/Module/Sophia.psm1
  22. 10
      src/Sophia_Script_for_Windows_11/Sophia.ps1
  23. 8
      src/Sophia_Script_for_Windows_11_PowerShell_7/Functions.ps1
  24. 2
      src/Sophia_Script_for_Windows_11_PowerShell_7/Manifest/Sophia.psd1
  25. 309
      src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1
  26. 10
      src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1

2
CHANGELOG.md

@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 5.15.0 | 6.3.0 — 30.01.2023
## 5.15.1 | 6.3.1 — 30.01.2023
* Added new function to prevent Microsoft Edge desktop shortcut creation upon its' update;
* By default it prevents for all Microsofot Edge channels (with checks if any of them is installed): `PreventEdgeShortcutCreation -Channels Stable, Beta, Dev, Canary`.

12
sophia_script_versions.json

@ -1,9 +1,9 @@
{
"Sophia_Script_Windows_10_PowerShell_5_1": "5.15.0",
"Sophia_Script_Windows_10_PowerShell_7": "5.15.0",
"Sophia_Script_Windows_10_LTSC2019": "5.5.0",
"Sophia_Script_Windows_10_LTSC2021": "5.15.0",
"Sophia_Script_Windows_11_PowerShell_5_1": "6.3.0",
"Sophia_Script_Windows_11_PowerShell_7": "6.3.0",
"Sophia_Script_Windows_10_PowerShell_5_1": "5.15.1",
"Sophia_Script_Windows_10_PowerShell_7": "5.15.1",
"Sophia_Script_Windows_10_LTSC2019": "5.5.1",
"Sophia_Script_Windows_10_LTSC2021": "5.15.1",
"Sophia_Script_Windows_11_PowerShell_5_1": "6.3.1",
"Sophia_Script_Windows_11_PowerShell_7": "6.3.1",
"Sophia_Script_Wrapper": "2.6.1"
}

8
src/Sophia_Script_for_Windows_10/Functions.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
The TAB completion for functions and their arguments
Version: v5.15.0
Version: v5.15.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -44,13 +44,13 @@ function Sophia
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
}
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.15.0 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.15.1 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

2
src/Sophia_Script_for_Windows_10/Manifest/Sophia.psd1

@ -1,6 +1,6 @@
@{
RootModule = '..\Module\Sophia.psm1'
ModuleVersion = '5.15.0'
ModuleVersion = '5.15.1'
GUID = '109cc881-c42b-45af-a74a-550781989d6a'
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014—2023 farag & Inestic. All rights reserved'

303
src/Sophia_Script_for_Windows_10/Module/Sophia.psm1

@ -2,7 +2,7 @@
.SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version: v5.15.0
Version: v5.15.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -4436,39 +4436,56 @@ function OneDrive
"Uninstall"
{
[string]$UninstallString = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -ErrorAction Ignore | ForEach-Object -Process {$_.Meta.Attributes["UninstallString"]}
if ($UninstallString)
if (-not $UninstallString)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveUninstalling -Verbose
# OneDrive is not installed
return
}
# Check if script was launched from OneDrive folder and preset file has function to uninstall OneDrive
# Check how the script was invoked: via a preset or Function.ps1
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and ($_.Text -eq "OneDrive -Uninstall") -or ($_.Text -match "Invoke-Expression")
}
# Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($PresetName -and $UserEmail)
{
# Exit if user accidentelly set function in preset to uninstall but he's logged into the app
return
}
Stop-Process -Name OneDrive, OneDriveSetup, FileCoAuth -Force -ErrorAction Ignore
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveUninstalling -Verbose
# Getting link to the OneDriveSetup.exe and its' argument(s)
[string[]]$OneDriveSetup = ($UninstallString -Replace("\s*/", ",/")).Split(",").Trim()
if ($OneDriveSetup.Count -eq 2)
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..1] -Wait
}
else
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..2] -Wait
}
Stop-Process -Name OneDrive, OneDriveSetup, FileCoAuth -Force -ErrorAction Ignore
# Get the OneDrive user folder path and remove it if it doesn't contain any user files
if (Test-Path -Path $env:OneDrive)
# Getting link to the OneDriveSetup.exe and its' argument(s)
[string[]]$OneDriveSetup = ($UninstallString -Replace("\s*/", ",/")).Split(",").Trim()
if ($OneDriveSetup.Count -eq 2)
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..1] -Wait
}
else
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..2] -Wait
}
# Get the OneDrive user folder path and remove it if it doesn't contain any user files
if (Test-Path -Path $env:OneDrive)
{
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -eq 0)
{
if ((Get-ChildItem -Path $env:OneDrive | Measure-Object).Count -eq 0)
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Ignore
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa
# 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"
MemberDefinition = @"
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Ignore
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa
# 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"
MemberDefinition = @"
public enum MoveFileFlags
{
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004
@ -4482,159 +4499,153 @@ public static bool MarkFileDelete (string sourcefile)
return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
}
"@
}
# If there are some files or folders left in %OneDrive%
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
try
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Stop
}
catch
{
# If files are in use remove them at the next boot
Get-ChildItem -Path $env:OneDrive -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
}
else
{
Start-Process -FilePath explorer -ArgumentList $env:OneDrive
}
}
Remove-ItemProperty -Path HKCU:\Environment -Name OneDrive, OneDriveConsumer -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
$OneDriveFolder = Split-Path -Path (Split-Path -Path $OneDriveSetup[0] -Parent)
# Save all opened folders in order to restore them after File Explorer restarting
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke()
# Terminate the File Explorer process
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 0 -Force
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 1 -Force
# Attempt to unregister FileSyncShell64.dll and remove
$FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\FileSyncShell64.dll" -Force
foreach ($FileSyncShell64dll in $FileSyncShell64dlls.FullName)
{
Start-Process -FilePath regsvr32.exe -ArgumentList "/u /s $FileSyncShell64dll" -Wait
Remove-Item -Path $FileSyncShell64dll -Force -ErrorAction Ignore
if (Test-Path -Path $FileSyncShell64dll)
# If there are some files or folders left in %OneDrive%
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
# If files are in use remove them at the next boot
Get-ChildItem -Path $FileSyncShell64dll -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
try
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Stop
}
catch
{
# If files are in use remove them at the next boot
Get-ChildItem -Path $env:OneDrive -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
}
else
{
Start-Process -FilePath explorer -ArgumentList $env:OneDrive
}
}
Start-Sleep -Seconds 1
Remove-ItemProperty -Path HKCU:\Environment -Name OneDrive, OneDriveConsumer -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
# Start the File Explorer process
Start-Process -FilePath explorer
# Getting the OneDrive folder path
$OneDriveFolder = Split-Path -Path (Split-Path -Path $OneDriveSetup[0] -Parent)
# Terminate the File Explorer process
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 0 -Force
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 1 -Force
# Restoring closed folders
foreach ($OpenedFolder in $OpenedFolders)
# Attempt to unregister FileSyncShell64.dll and remove
$FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\FileSyncShell64.dll" -Force
foreach ($FileSyncShell64dll in $FileSyncShell64dlls.FullName)
{
Start-Process -FilePath regsvr32.exe -ArgumentList "/u /s $FileSyncShell64dll" -Wait
Remove-Item -Path $FileSyncShell64dll -Force -ErrorAction Ignore
if (Test-Path -Path $FileSyncShell64dll)
{
if (Test-Path -Path $OpenedFolder)
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Start-Process -FilePath explorer -ArgumentList $OpenedFolder
Add-Type @Signature
}
}
Remove-Item -Path $OneDriveFolder, $env:LOCALAPPDATA\OneDrive, $env:LOCALAPPDATA\Microsoft\OneDrive, "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Recurse -Force -ErrorAction Ignore
# If files are in use remove them at the next boot
Get-ChildItem -Path $FileSyncShell64dll -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
Start-Sleep -Seconds 1
# Start the File Explorer process
Start-Process -FilePath explorer
$Path = @(
$OneDriveFolder,
"$env:LOCALAPPDATA\OneDrive",
"$env:LOCALAPPDATA\Microsoft\OneDrive",
"$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
)
Remove-Item -Path $Path -Recurse -Force -ErrorAction Ignore
}
"Install"
{
$OneDrive = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if (-not $OneDrive)
if ($OneDrive)
{
if (Test-Path -Path $env:SystemRoot\SysWOW64\OneDriveSetup.exe)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveInstalling -Verbose
return
}
Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe
}
else
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
{
try
{
try
# Check the internet connection
$Parameters = @{
Uri = "https://www.google.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
# Check the internet connection
$Parameters = @{
Uri = "https://www.google.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
$OneDriveURL = ($OneDriveXML).root.update.amd64binary.url
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$DownloadsFolder\OneDriveSetup.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
$OneDriveURL = ($OneDriveXML).root.update.amd64binary.url
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$DownloadsFolder\OneDriveSetup.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
Start-Process -FilePath "$DownloadsFolder\OneDriveSetup.exe" -Wait
Start-Process -FilePath "$DownloadsFolder\OneDriveSetup.exe" -Wait
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line) -ErrorAction SilentlyContinue
}
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line) -ErrorAction SilentlyContinue
}
}
# Save screenshots by pressing Win+PrtScr in the Pictures folder
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction Ignore
# Save screenshots by pressing Win+PrtScr in the Pictures folder
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction Ignore
Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask
}
Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask
}
}
}

10
src/Sophia_Script_for_Windows_10/Sophia.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
Default preset file for "Sophia Script for Windows 10"
Version: v5.15.0
Version: v5.15.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -70,7 +70,7 @@ param
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.15.0 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.15.1 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force
@ -98,8 +98,8 @@ if ($Functions)
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
exit
}
@ -1485,7 +1485,7 @@ UseStoreOpenWith -Hide
Перезапустить меню "Пуск"
Пожалуйста, не комментируйте данную функцию
#>
RefreshEnvironment
PostActions
<#
Errors output

8
src/Sophia_Script_for_Windows_10_LTSC_2019/Functions.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
The TAB completion for functions and their arguments
Version: v5.5.0
Version: v5.5.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -44,13 +44,13 @@ function Sophia
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
}
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.5.0 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows 10 | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.5.1 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows 10 | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

2
src/Sophia_Script_for_Windows_10_LTSC_2019/Manifest/Sophia.psd1

@ -1,6 +1,6 @@
@{
RootModule = '..\Module\Sophia.psm1'
ModuleVersion = '5.5.0'
ModuleVersion = '5.5.1'
GUID = 'a36a65ca-70f9-43df-856c-3048fc5e7f01'
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014—2023 farag & Inestic. All rights reserved'

2
src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1

@ -2,7 +2,7 @@
.SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version: v5.5.0
Version: v5.5.1
Date: 30.01.2023
Copyright (c) 20142023 farag

10
src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
Default preset file for "Sophia Script for Windows 10 LTSC 2019"
Version: v5.5.0
Version: v5.5.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -70,7 +70,7 @@ param
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.5.0 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.5.1 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force
@ -98,8 +98,8 @@ if ($Functions)
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
exit
}
@ -1137,7 +1137,7 @@ MultipleInvokeContext -Enable
Перезапустить меню "Пуск"
Пожалуйста, не комментируйте данную функцию
#>
RefreshEnvironment
PostActions
<#
Errors output

8
src/Sophia_Script_for_Windows_10_LTSC_2021/Functions.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
The TAB completion for functions and their arguments
Version: v5.15.0
Version: v5.15.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -44,13 +44,13 @@ function Sophia
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
}
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2021 v5.15.0 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2021 v5.15.1 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

2
src/Sophia_Script_for_Windows_10_LTSC_2021/Manifest/Sophia.psd1

@ -1,6 +1,6 @@
@{
RootModule = '..\Module\Sophia.psm1'
ModuleVersion = '5.15.0'
ModuleVersion = '5.15.1'
GUID = '109cc881-c42b-45af-a74a-550781989d6a'
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014—2023 farag & Inestic. All rights reserved'

2
src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1

@ -2,7 +2,7 @@
.SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version: v5.15.0
Version: v5.15.1
Date: 30.01.2023
Copyright (c) 20142023 farag

10
src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
Default preset file for "Sophia Script for Windows 10 LTSC 2021"
Version: v5.15.0
Version: v5.15.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -70,7 +70,7 @@ param
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2021 v5.15.0 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2021 v5.15.1 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force
@ -98,8 +98,8 @@ if ($Functions)
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
exit
}
@ -1284,7 +1284,7 @@ MultipleInvokeContext -Enable
Перезапустить меню "Пуск"
Пожалуйста, не комментируйте данную функцию
#>
RefreshEnvironment
PostActions
<#
Errors output

8
src/Sophia_Script_for_Windows_10_PowerShell_7/Functions.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
The TAB completion for functions and their arguments
Version: v5.15.0
Version: v5.15.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -44,13 +44,13 @@ function Sophia
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
}
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.15.0 (PowerShell 7) | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.15.1 (PowerShell 7) | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

2
src/Sophia_Script_for_Windows_10_PowerShell_7/Manifest/Sophia.psd1

@ -1,6 +1,6 @@
@{
RootModule = '..\Module\Sophia.psm1'
ModuleVersion = '5.15.0'
ModuleVersion = '5.15.1'
GUID = 'aa0b47a7-1770-4b5d-8c9f-cc6c505bcc7a'
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014—2023 farag & Inestic. All rights reserved'

309
src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1

@ -2,7 +2,7 @@
.SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version: v5.15.0
Version: v5.15.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -4440,39 +4440,56 @@ function OneDrive
[xml]$Uninstall = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -ErrorAction Ignore | ForEach-Object -Process {$_.SwidTagText}
[xml]$Uninstall = $Uninstall.SoftwareIdentity.InnerXml
[string]$UninstallString = $Uninstall.Meta.UninstallString
if ($UninstallString)
if (-not $UninstallString)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveUninstalling -Verbose
# OneDrive is not installed
return
}
# Check if script was launched from OneDrive folder and preset file has function to uninstall OneDrive
# Check how the script was invoked: via a preset or Function.ps1
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and ($_.Text -eq "OneDrive -Uninstall") -or ($_.Text -match "Invoke-Expression")
}
# Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($PresetName -and $UserEmail)
{
# Exit if user accidentelly set function in preset to uninstall but he's logged into the app
return
}
Stop-Process -Name OneDrive, OneDriveSetup, FileCoAuth -Force -ErrorAction Ignore
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveUninstalling -Verbose
# Getting link to the OneDriveSetup.exe and its' argument(s)
[string[]]$OneDriveSetup = ($UninstallString -Replace("\s*/", ",/")).Split(",").Trim()
if ($OneDriveSetup.Count -eq 2)
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..1] -Wait
}
else
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..2] -Wait
}
Stop-Process -Name OneDrive, OneDriveSetup, FileCoAuth -Force -ErrorAction Ignore
# Get the OneDrive user folder path and remove it if it doesn't contain any user files
if (Test-Path -Path $env:OneDrive)
# Getting link to the OneDriveSetup.exe and its' argument(s)
[string[]]$OneDriveSetup = ($UninstallString -Replace("\s*/", ",/")).Split(",").Trim()
if ($OneDriveSetup.Count -eq 2)
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..1] -Wait
}
else
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..2] -Wait
}
# Get the OneDrive user folder path and remove it if it doesn't contain any user files
if (Test-Path -Path $env:OneDrive)
{
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -eq 0)
{
if ((Get-ChildItem -Path $env:OneDrive | Measure-Object).Count -eq 0)
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Ignore
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa
# 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"
MemberDefinition = @"
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Ignore
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa
# 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"
MemberDefinition = @"
public enum MoveFileFlags
{
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004
@ -4486,162 +4503,156 @@ public static bool MarkFileDelete (string sourcefile)
return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
}
"@
}
# If there are some files or folders left in %OneDrive%
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
try
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Stop
}
catch
{
# If files are in use remove them at the next boot
Get-ChildItem -Path $env:OneDrive -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
}
else
{
Start-Process -FilePath explorer -ArgumentList $env:OneDrive
}
}
Remove-ItemProperty -Path HKCU:\Environment -Name OneDrive, OneDriveConsumer -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
$OneDriveFolder = Split-Path -Path (Split-Path -Path $OneDriveSetup[0] -Parent)
# Save all opened folders in order to restore them after File Explorer restarting
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke()
# Terminate the File Explorer process
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 0 -Force
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 1 -Force
# Attempt to unregister FileSyncShell64.dll and remove
$FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\FileSyncShell64.dll" -Force
foreach ($FileSyncShell64dll in $FileSyncShell64dlls.FullName)
{
Start-Process -FilePath regsvr32.exe -ArgumentList "/u /s $FileSyncShell64dll" -Wait
Remove-Item -Path $FileSyncShell64dll -Force -ErrorAction Ignore
if (Test-Path -Path $FileSyncShell64dll)
# If there are some files or folders left in %OneDrive%
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
# If files are in use remove them at the next boot
Get-ChildItem -Path $FileSyncShell64dll -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
try
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Stop
}
catch
{
# If files are in use remove them at the next boot
Get-ChildItem -Path $env:OneDrive -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
}
else
{
Start-Process -FilePath explorer -ArgumentList $env:OneDrive
}
}
Start-Sleep -Seconds 1
Remove-ItemProperty -Path HKCU:\Environment -Name OneDrive, OneDriveConsumer -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
# Start the File Explorer process
Start-Process -FilePath explorer
# Getting the OneDrive folder path
$OneDriveFolder = Split-Path -Path (Split-Path -Path $OneDriveSetup[0] -Parent)
# Terminate the File Explorer process
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 0 -Force
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 1 -Force
# Restoring closed folders
foreach ($OpenedFolder in $OpenedFolders)
# Attempt to unregister FileSyncShell64.dll and remove
$FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\FileSyncShell64.dll" -Force
foreach ($FileSyncShell64dll in $FileSyncShell64dlls.FullName)
{
Start-Process -FilePath regsvr32.exe -ArgumentList "/u /s $FileSyncShell64dll" -Wait
Remove-Item -Path $FileSyncShell64dll -Force -ErrorAction Ignore
if (Test-Path -Path $FileSyncShell64dll)
{
if (Test-Path -Path $OpenedFolder)
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Start-Process -FilePath explorer -ArgumentList $OpenedFolder
Add-Type @Signature
}
}
Remove-Item -Path $OneDriveFolder, $env:LOCALAPPDATA\OneDrive, $env:LOCALAPPDATA\Microsoft\OneDrive, "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Recurse -Force -ErrorAction Ignore
# If files are in use remove them at the next boot
Get-ChildItem -Path $FileSyncShell64dll -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
Start-Sleep -Seconds 1
# Start the File Explorer process
Start-Process -FilePath explorer
$Path = @(
$OneDriveFolder,
"$env:LOCALAPPDATA\OneDrive",
"$env:LOCALAPPDATA\Microsoft\OneDrive",
"$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
)
Remove-Item -Path $Path -Recurse -Force -ErrorAction Ignore
}
"Install"
{
$OneDrive = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if (-not $OneDrive)
if ($OneDrive)
{
if (Test-Path -Path $env:SystemRoot\SysWOW64\OneDriveSetup.exe)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveInstalling -Verbose
return
}
Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe
}
else
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
{
try
{
try
# Check the internet connection
$Parameters = @{
Uri = "https://www.google.com"
Method = "Head"
SslProtocol = "Tls12"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
# Check the internet connection
$Parameters = @{
Uri = "https://www.google.com"
Method = "Head"
SslProtocol = "Tls12"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
SslProtocol = "Tls12"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
SslProtocol = "Tls12"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
$OneDriveURL = ($OneDriveXML).root.update.amd64binary.url
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$DownloadsFolder\OneDriveSetup.exe"
SslProtocol = "Tls12"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
$OneDriveURL = ($OneDriveXML).root.update.amd64binary.url
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$DownloadsFolder\OneDriveSetup.exe"
SslProtocol = "Tls12"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
Start-Process -FilePath "$DownloadsFolder\OneDriveSetup.exe" -Wait
Start-Process -FilePath "$DownloadsFolder\OneDriveSetup.exe" -Wait
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line) -ErrorAction SilentlyContinue
}
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line) -ErrorAction SilentlyContinue
}
}
# Save screenshots by pressing Win+PrtScr in the Pictures folder
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction Ignore
# Save screenshots by pressing Win+PrtScr in the Pictures folder
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction Ignore
Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask
}
Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask
}
}
}

10
src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
Default preset file for "Sophia Script for Windows 10 (PowerShell 7)"
Version: v5.15.0
Version: v5.15.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -70,7 +70,7 @@ param
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.15.0 (PowerShell 7) | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.15.1 (PowerShell 7) | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force
@ -107,8 +107,8 @@ if ($Functions)
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
exit
}
@ -1494,7 +1494,7 @@ UseStoreOpenWith -Hide
Перезапустить меню "Пуск"
Пожалуйста, не комментируйте данную функцию
#>
RefreshEnvironment
PostActions
<#
Errors output

8
src/Sophia_Script_for_Windows_11/Functions.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
The TAB completion for functions and their arguments
Version: v6.3.0
Version: v6.3.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -44,13 +44,13 @@ function Sophia
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
}
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.3.0 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.3.1 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

2
src/Sophia_Script_for_Windows_11/Manifest/Sophia.psd1

@ -1,6 +1,6 @@
@{
RootModule = '..\Module\Sophia.psm1'
ModuleVersion = '6.3.0'
ModuleVersion = '6.3.1'
GUID = '109cc881-c42b-45af-a74a-550781989d6a'
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014—2023 farag & Inestic. All rights reserved'

303
src/Sophia_Script_for_Windows_11/Module/Sophia.psm1

@ -2,7 +2,7 @@
.SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version: v6.3.0
Version: v6.3.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -3916,39 +3916,56 @@ function OneDrive
"Uninstall"
{
[string]$UninstallString = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -ErrorAction Ignore | ForEach-Object -Process {$_.Meta.Attributes["UninstallString"]}
if ($UninstallString)
if (-not $UninstallString)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveUninstalling -Verbose
# OneDrive is not installed
return
}
Stop-Process -Name OneDrive, OneDriveSetup, FileCoAuth -Force -ErrorAction Ignore
# Check if script was launched from OneDrive folder and preset file has function to uninstall OneDrive
# Check how the script was invoked: via a preset or Function.ps1
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and ($_.Text -eq "OneDrive -Uninstall") -or ($_.Text -match "Invoke-Expression")
}
# Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($PresetName -and $UserEmail)
{
# Exit if user accidentelly set function in preset to uninstall but he's logged into the app
return
}
# Getting link to the OneDriveSetup.exe and its' argument(s)
[string[]]$OneDriveSetup = ($UninstallString -Replace("\s*/", ",/")).Split(",").Trim()
if ($OneDriveSetup.Count -eq 2)
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..1] -Wait
}
else
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..2] -Wait
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveUninstalling -Verbose
# Get the OneDrive user folder path and remove it if it doesn't contain any user files
if (Test-Path -Path $env:OneDrive)
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()
if ($OneDriveSetup.Count -eq 2)
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..1] -Wait
}
else
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..2] -Wait
}
# Get the OneDrive user folder path and remove it if it doesn't contain any user files
if (Test-Path -Path $env:OneDrive)
{
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -eq 0)
{
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -eq 0)
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Ignore
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa
# 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"
MemberDefinition = @"
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Ignore
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa
# 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"
MemberDefinition = @"
public enum MoveFileFlags
{
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004
@ -3962,159 +3979,153 @@ public static bool MarkFileDelete (string sourcefile)
return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
}
"@
}
# If there are some files or folders left in %OneDrive%
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
try
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Stop
}
catch
{
# If files are in use remove them at the next boot
Get-ChildItem -Path $env:OneDrive -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
}
else
{
Start-Process -FilePath explorer -ArgumentList $env:OneDrive
}
}
Remove-ItemProperty -Path HKCU:\Environment -Name OneDrive, OneDriveConsumer -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
$OneDriveFolder = Split-Path -Path (Split-Path -Path $OneDriveSetup[0] -Parent)
# Save all opened folders in order to restore them after File Explorer restarting
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke()
# Terminate the File Explorer process
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 0 -Force
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 1 -Force
# Attempt to unregister FileSyncShell64.dll and remove
$FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\FileSyncShell64.dll" -Force
foreach ($FileSyncShell64dll in $FileSyncShell64dlls.FullName)
{
Start-Process -FilePath regsvr32.exe -ArgumentList "/u /s $FileSyncShell64dll" -Wait
Remove-Item -Path $FileSyncShell64dll -Force -ErrorAction Ignore
if (Test-Path -Path $FileSyncShell64dll)
# If there are some files or folders left in %OneDrive%
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
# If files are in use remove them at the next boot
Get-ChildItem -Path $FileSyncShell64dll -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
try
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Stop
}
catch
{
# If files are in use remove them at the next boot
Get-ChildItem -Path $env:OneDrive -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
}
else
{
Start-Process -FilePath explorer -ArgumentList $env:OneDrive
}
}
Start-Sleep -Seconds 1
Remove-ItemProperty -Path HKCU:\Environment -Name OneDrive, OneDriveConsumer -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
$OneDriveFolder = Split-Path -Path (Split-Path -Path $OneDriveSetup[0] -Parent)
# Start the File Explorer process
Start-Process -FilePath explorer
# Terminate the File Explorer process
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 0 -Force
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 1 -Force
# Attempt to unregister FileSyncShell64.dll and remove
$FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\FileSyncShell64.dll" -Force
foreach ($FileSyncShell64dll in $FileSyncShell64dlls.FullName)
{
Start-Process -FilePath regsvr32.exe -ArgumentList "/u /s $FileSyncShell64dll" -Wait
Remove-Item -Path $FileSyncShell64dll -Force -ErrorAction Ignore
# Restoring closed folders
foreach ($OpenedFolder in $OpenedFolders)
if (Test-Path -Path $FileSyncShell64dll)
{
if (Test-Path -Path $OpenedFolder)
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Start-Process -FilePath explorer -ArgumentList $OpenedFolder
Add-Type @Signature
}
}
Remove-Item -Path $OneDriveFolder, $env:LOCALAPPDATA\OneDrive, $env:LOCALAPPDATA\Microsoft\OneDrive, "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Recurse -Force -ErrorAction Ignore
# If files are in use remove them at the next boot
Get-ChildItem -Path $FileSyncShell64dll -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
Start-Sleep -Seconds 1
# Start the File Explorer process
Start-Process -FilePath explorer
$Path = @(
$OneDriveFolder,
"$env:LOCALAPPDATA\OneDrive",
"$env:LOCALAPPDATA\Microsoft\OneDrive",
"$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
)
Remove-Item -Path $Path -Recurse -Force -ErrorAction Ignore
}
"Install"
{
$OneDrive = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if (-not $OneDrive)
if ($OneDrive)
{
if (Test-Path -Path $env:SystemRoot\SysWOW64\OneDriveSetup.exe)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveInstalling -Verbose
return
}
Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe
}
else
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
{
try
{
try
# Check the internet connection
$Parameters = @{
Uri = "https://www.google.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
# Check the internet connection
$Parameters = @{
Uri = "https://www.google.com"
Method = "Head"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
$OneDriveURL = ($OneDriveXML).root.update.amd64binary.url
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$DownloadsFolder\OneDriveSetup.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
$OneDriveURL = ($OneDriveXML).root.update.amd64binary.url
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$DownloadsFolder\OneDriveSetup.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
Start-Process -FilePath "$DownloadsFolder\OneDriveSetup.exe" -Wait
Start-Process -FilePath "$DownloadsFolder\OneDriveSetup.exe" -Wait
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line) -ErrorAction SilentlyContinue
}
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line) -ErrorAction SilentlyContinue
}
}
# Save screenshots by pressing Win+PrtScr in the Pictures folder
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction Ignore
# Save screenshots by pressing Win+PrtScr in the Pictures folder
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction Ignore
Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask
}
Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask
}
}
}

10
src/Sophia_Script_for_Windows_11/Sophia.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
Default preset file for "Sophia Script for Windows 11"
Version: v6.3.0
Version: v6.3.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -69,7 +69,7 @@ param
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.3.0 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.3.1 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force
@ -97,8 +97,8 @@ if ($Functions)
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
exit
}
@ -1401,7 +1401,7 @@ Windows10ContextMenu -Disable
Перезапустить меню "Пуск"
Пожалуйста, не комментируйте данную функцию
#>
RefreshEnvironment
PostActions
<#
Errors output

8
src/Sophia_Script_for_Windows_11_PowerShell_7/Functions.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
The TAB completion for functions and their arguments
Version: v6.3.0
Version: v6.3.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -44,13 +44,13 @@ function Sophia
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
}
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.3.0 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.3.1 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

2
src/Sophia_Script_for_Windows_11_PowerShell_7/Manifest/Sophia.psd1

@ -1,6 +1,6 @@
@{
RootModule = '..\Module\Sophia.psm1'
ModuleVersion = '6.3.0'
ModuleVersion = '6.3.1'
GUID = '109cc881-c42b-45af-a74a-550781989d6a'
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014—2023 farag & Inestic. All rights reserved'

309
src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

@ -2,7 +2,7 @@
.SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version: v6.3.0
Version: v6.3.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -3920,39 +3920,56 @@ function OneDrive
[xml]$Uninstall = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -ErrorAction Ignore | ForEach-Object -Process {$_.SwidTagText}
[xml]$Uninstall = $Uninstall.SoftwareIdentity.InnerXml
[string]$UninstallString = $Uninstall.Meta.UninstallString
if ($UninstallString)
if (-not $UninstallString)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveUninstalling -Verbose
# OneDrive is not installed
return
}
Stop-Process -Name OneDrive, OneDriveSetup, FileCoAuth -Force -ErrorAction Ignore
# Check if script was launched from OneDrive folder and preset file has function to uninstall OneDrive
# Check how the script was invoked: via a preset or Function.ps1
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and ($_.Text -eq "OneDrive -Uninstall") -or ($_.Text -match "Invoke-Expression")
}
# Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($PresetName -and $UserEmail)
{
# Exit if user accidentelly set function in preset to uninstall but he's logged into the app
return
}
# Getting link to the OneDriveSetup.exe and its' argument(s)
[string[]]$OneDriveSetup = ($UninstallString -Replace("\s*/", ",/")).Split(",").Trim()
if ($OneDriveSetup.Count -eq 2)
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..1] -Wait
}
else
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..2] -Wait
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveUninstalling -Verbose
# Get the OneDrive user folder path and remove it if it doesn't contain any user files
if (Test-Path -Path $env:OneDrive)
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()
if ($OneDriveSetup.Count -eq 2)
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..1] -Wait
}
else
{
Start-Process -FilePath $OneDriveSetup[0] -ArgumentList $OneDriveSetup[1..2] -Wait
}
# Get the OneDrive user folder path and remove it if it doesn't contain any user files
if (Test-Path -Path $env:OneDrive)
{
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -eq 0)
{
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -eq 0)
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Ignore
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa
# 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"
MemberDefinition = @"
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Ignore
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa
# 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"
MemberDefinition = @"
public enum MoveFileFlags
{
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004
@ -3966,162 +3983,156 @@ public static bool MarkFileDelete (string sourcefile)
return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
}
"@
}
# If there are some files or folders left in %OneDrive%
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
try
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Stop
}
catch
{
# If files are in use remove them at the next boot
Get-ChildItem -Path $env:OneDrive -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
}
else
{
Start-Process -FilePath explorer -ArgumentList $env:OneDrive
}
}
Remove-ItemProperty -Path HKCU:\Environment -Name OneDrive, OneDriveConsumer -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
$OneDriveFolder = Split-Path -Path (Split-Path -Path $OneDriveSetup[0] -Parent)
# Save all opened folders in order to restore them after File Explorer restarting
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke()
# Terminate the File Explorer process
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 0 -Force
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 1 -Force
# Attempt to unregister FileSyncShell64.dll and remove
$FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\FileSyncShell64.dll" -Force
foreach ($FileSyncShell64dll in $FileSyncShell64dlls.FullName)
{
Start-Process -FilePath regsvr32.exe -ArgumentList "/u /s $FileSyncShell64dll" -Wait
Remove-Item -Path $FileSyncShell64dll -Force -ErrorAction Ignore
if (Test-Path -Path $FileSyncShell64dll)
# If there are some files or folders left in %OneDrive%
if ((Get-ChildItem -Path $env:OneDrive -ErrorAction Ignore | Measure-Object).Count -ne 0)
{
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Add-Type @Signature
}
# If files are in use remove them at the next boot
Get-ChildItem -Path $FileSyncShell64dll -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
try
{
Remove-Item -Path $env:OneDrive -Recurse -Force -ErrorAction Stop
}
catch
{
# If files are in use remove them at the next boot
Get-ChildItem -Path $env:OneDrive -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
}
else
{
Start-Process -FilePath explorer -ArgumentList $env:OneDrive
}
}
Start-Sleep -Seconds 1
Remove-ItemProperty -Path HKCU:\Environment -Name OneDrive, OneDriveConsumer -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
$OneDriveFolder = Split-Path -Path (Split-Path -Path $OneDriveSetup[0] -Parent)
# Start the File Explorer process
Start-Process -FilePath explorer
# Terminate the File Explorer process
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 0 -Force
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -PropertyType DWord -Value 1 -Force
# Attempt to unregister FileSyncShell64.dll and remove
$FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\FileSyncShell64.dll" -Force
foreach ($FileSyncShell64dll in $FileSyncShell64dlls.FullName)
{
Start-Process -FilePath regsvr32.exe -ArgumentList "/u /s $FileSyncShell64dll" -Wait
Remove-Item -Path $FileSyncShell64dll -Force -ErrorAction Ignore
# Restoring closed folders
foreach ($OpenedFolder in $OpenedFolders)
if (Test-Path -Path $FileSyncShell64dll)
{
if (Test-Path -Path $OpenedFolder)
if (-not ("WinAPI.DeleteFiles" -as [type]))
{
Start-Process -FilePath explorer -ArgumentList $OpenedFolder
Add-Type @Signature
}
}
Remove-Item -Path $OneDriveFolder, $env:LOCALAPPDATA\OneDrive, $env:LOCALAPPDATA\Microsoft\OneDrive, "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Recurse -Force -ErrorAction Ignore
# If files are in use remove them at the next boot
Get-ChildItem -Path $FileSyncShell64dll -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)}
}
}
Start-Sleep -Seconds 1
# Start the File Explorer process
Start-Process -FilePath explorer
$Path = @(
$OneDriveFolder,
"$env:LOCALAPPDATA\OneDrive",
"$env:LOCALAPPDATA\Microsoft\OneDrive",
"$env:APPDATA\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"
)
Remove-Item -Path $Path -Recurse -Force -ErrorAction Ignore
}
"Install"
{
$OneDrive = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if (-not $OneDrive)
if ($OneDrive)
{
if (Test-Path -Path $env:SystemRoot\SysWOW64\OneDriveSetup.exe)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveInstalling -Verbose
return
}
Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe
}
else
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
{
try
{
try
# Check the internet connection
$Parameters = @{
Uri = "https://www.google.com"
Method = "Head"
SslProtocol = "Tls13"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
# Check the internet connection
$Parameters = @{
Uri = "https://www.google.com"
Method = "Head"
SslProtocol = "Tls13"
DisableKeepAlive = $true
UseBasicParsing = $true
}
if (-not (Invoke-WebRequest @Parameters).StatusDescription)
{
return
}
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message $Localization.OneDriveDownloading -Verbose
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
SslProtocol = "Tls13"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
SslProtocol = "Tls13"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
$OneDriveURL = ($OneDriveXML).root.update.amd64binary.url
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$DownloadsFolder\OneDriveSetup.exe"
SslProtocol = "Tls13"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
$OneDriveURL = ($OneDriveXML).root.update.amd64binary.url
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$DownloadsFolder\OneDriveSetup.exe"
SslProtocol = "Tls13"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
Start-Process -FilePath "$DownloadsFolder\OneDriveSetup.exe" -Wait
Start-Process -FilePath "$DownloadsFolder\OneDriveSetup.exe" -Wait
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization.NoInternetConnection
Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line) -ErrorAction SilentlyContinue
}
Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line) -ErrorAction SilentlyContinue
}
}
# Save screenshots by pressing Win+PrtScr in the Pictures folder
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction Ignore
# Save screenshots by pressing Win+PrtScr in the Pictures folder
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -Force -ErrorAction Ignore
Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask
}
Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask
}
}
}

10
src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
Default preset file for "Sophia Script for Windows 11 (PowerShell 7)"
Version: v6.3.0
Version: v6.3.1
Date: 30.01.2023
Copyright (c) 20142023 farag
@ -69,7 +69,7 @@ param
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.3.0 (PowerShell 7) | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.3.1 (PowerShell 7) | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force
@ -106,8 +106,8 @@ if ($Functions)
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
# The "PostActions" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {PostActions; Errors}
exit
}
@ -1410,7 +1410,7 @@ Windows10ContextMenu -Disable
Перезапустить меню "Пуск"
Пожалуйста, не комментируйте данную функцию
#>
RefreshEnvironment
PostActions
<#
Errors output

Loading…
Cancel
Save