From 7f27aa43a403a104fc0c1cf91a4315189722065d Mon Sep 17 00:00:00 2001 From: Couleur <82747632+couleurm@users.noreply.github.com> Date: Tue, 4 Jan 2022 21:15:56 +0100 Subject: [PATCH] docs + import.ps1 + simple funcs / sophia script funcs --- README.MD | 20 +- docs/Making your own functions.MD | 25 ++ docs/Making your own tweakscript.MD | 51 ++++ import.ps1 | 119 +++++++++ modules/Windows/CreateRestorePoint.ps1 | 61 +++++ .../Context menu/CastToDeviceContext.ps1 | 54 ++++ .../Context menu/MultipleInvokeContext.ps1 | 50 ++++ .../Fine-tuning/Context menu/ShareContext.ps1 | 54 ++++ modules/Windows/Fine-tuning/HiddenItems.ps1 | 51 ++++ .../RecycleBinDeleteConfirmation.ps1 | 54 ++++ modules/Windows/Fine-tuning/Set-DarkMode.ps1 | 9 + modules/Windows/Fine-tuning/StickyShift.ps1 | 50 ++++ .../Fine-tuning/Taskbar/PeopleTaskar.ps1 | 58 ++++ .../Fine-tuning/Taskbar/TaskViewButton.ps1 | 52 ++++ .../Fine-tuning/Taskbar/TaskbarSearch.ps1 | 69 +++++ .../Taskbar/UnpinTaskbarShortcuts.ps1 | 100 +++++++ .../Windows/Fine-tuning/UseStoreOpenWith.ps1 | 54 ++++ .../Windows/Gaming Settings/GPUScheduling.ps1 | 65 +++++ .../Windows/Gaming Settings/XboxGameTips.ps1 | 56 ++++ modules/Windows/Get-StartupServices.ps1 | 5 + modules/Windows/HiddenItems.ps1 | 36 +++ modules/Windows/OneDrive.ps1 | 247 ++++++++++++++++++ .../Privacy and telemetry/AppSuggestions.ps1 | 50 ++++ .../DiagnosticDataLevel.ps1 | 66 +++++ .../Privacy and telemetry/ErrorReporting.ps1 | 61 +++++ modules/Windows/Remove-KnownAppxPackages.ps1 | 76 ++++++ modules/Windows/Remove-UselessFiles.ps1 | 9 + .../Windows/Set-Win32PrioritySeparation.ps1 | 8 + 28 files changed, 1600 insertions(+), 10 deletions(-) create mode 100644 docs/Making your own functions.MD create mode 100644 docs/Making your own tweakscript.MD create mode 100644 import.ps1 create mode 100644 modules/Windows/CreateRestorePoint.ps1 create mode 100644 modules/Windows/Fine-tuning/Context menu/CastToDeviceContext.ps1 create mode 100644 modules/Windows/Fine-tuning/Context menu/MultipleInvokeContext.ps1 create mode 100644 modules/Windows/Fine-tuning/Context menu/ShareContext.ps1 create mode 100644 modules/Windows/Fine-tuning/HiddenItems.ps1 create mode 100644 modules/Windows/Fine-tuning/RecycleBinDeleteConfirmation.ps1 create mode 100644 modules/Windows/Fine-tuning/Set-DarkMode.ps1 create mode 100644 modules/Windows/Fine-tuning/StickyShift.ps1 create mode 100644 modules/Windows/Fine-tuning/Taskbar/PeopleTaskar.ps1 create mode 100644 modules/Windows/Fine-tuning/Taskbar/TaskViewButton.ps1 create mode 100644 modules/Windows/Fine-tuning/Taskbar/TaskbarSearch.ps1 create mode 100644 modules/Windows/Fine-tuning/Taskbar/UnpinTaskbarShortcuts.ps1 create mode 100644 modules/Windows/Fine-tuning/UseStoreOpenWith.ps1 create mode 100644 modules/Windows/Gaming Settings/GPUScheduling.ps1 create mode 100644 modules/Windows/Gaming Settings/XboxGameTips.ps1 create mode 100644 modules/Windows/Get-StartupServices.ps1 create mode 100644 modules/Windows/HiddenItems.ps1 create mode 100644 modules/Windows/OneDrive.ps1 create mode 100644 modules/Windows/Privacy and telemetry/AppSuggestions.ps1 create mode 100644 modules/Windows/Privacy and telemetry/DiagnosticDataLevel.ps1 create mode 100644 modules/Windows/Privacy and telemetry/ErrorReporting.ps1 create mode 100644 modules/Windows/Remove-KnownAppxPackages.ps1 create mode 100644 modules/Windows/Remove-UselessFiles.ps1 create mode 100644 modules/Windows/Set-Win32PrioritySeparation.ps1 diff --git a/README.MD b/README.MD index 2451966..61dbcf9 100644 --- a/README.MD +++ b/README.MD @@ -1,5 +1,5 @@
-👋 Contributors: if you'd like to contribute, feel free to make an issue to suggest a relevant tweak +👋 Contributors: if you'd like to contribute, feel free to make an issue to suggest a relevant tweak
@@ -8,7 +8,7 @@- Tweak Script + TweakList Make your very own tweaking/debloating script, with one line per tweak Tweak interpreter based in PowerShell @@ -16,20 +16,20 @@ • Discord Server • - Docs + Docs
@@ -37,7 +37,7 @@ [logo]: https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/ps_black_64.svg?sanitize=true -TweakScript is a PowerShell module aiming to regroup every impactful tweaks for fine tuning, stripping and optimizing Windows, each tweaks has it's own file **and can be put together as a [tweaklist](https://gist.github.com/couleurm/68d272edc5fb930c31b96b667813e373 "tweaklist example")** +TweakList is a PowerShell module aiming to regroup every impactful tweaks for fine tuning, stripping and optimizing Windows, each tweaks has it's own file **and can be put together as a "[TweakScript](https://gist.github.com/couleurm/68d272edc5fb930c31b96b667813e373 "TweakList example")"** diff --git a/docs/Making your own functions.MD b/docs/Making your own functions.MD new file mode 100644 index 0000000..0a19e27 --- /dev/null +++ b/docs/Making your own functions.MD @@ -0,0 +1,25 @@ +# Making your own functions + +Every code in the functions must be inside of a function declaration (so it does not run when dot-sourcing the function at import) + + +PowerShell was made to replace batch, but you can still use some batch commands in PowerShell by typing ``cmd /c`` before them + +```bat +cmd /c assoc .ps1 +``` + +assoc is a specific batch command, but a lot of other commands can be used in PowerShell as well because they're actually executables in System32 (PING.exe, tracert.exe, timeout.exe, setx.exe, shutdown.exe reg.exe, tskill.exe,) + +If you're only familiar with handling the registry in batch, you'll only have to change your fancy for and if statements, REG.EXE can be used the same way on PowerShell + +## PowerShell 5.1 alias overrides + +- 5.1 is the version of PowerShell that comes with Windows 10/11 + +Per default, curl in PowerShell is an alias for Invoke-WebRequest, if you wish to use curl in that version, make sure you specify it's .exe extension + +``` +curl.exe -L https://github.com/couleur-tweak-tips/utils/archive/refs/heads/main.zip +``` +Same thing for where.exe, which is an alias to Where-Object, just specify it's extension. \ No newline at end of file diff --git a/docs/Making your own tweakscript.MD b/docs/Making your own tweakscript.MD new file mode 100644 index 0000000..00fa508 --- /dev/null +++ b/docs/Making your own tweakscript.MD @@ -0,0 +1,51 @@ +# Making your own TweakList + +## Setting up VSCode + +If you want to make your very own list of tweaks, I strongly recommend you install [VSCode](https://code.visualstudio.com/) with the [PowerShell extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell), import the functions one time to get them loaded so you have the function's parameters' autocompletion. + +Alternatively you can use [Notepad++](https://notepad-plus-plus.org/) which have some syntax highlighting. + + +You can alternatively install it with Scoop or Chocolatey: +``` +scoop bucket add extras +scoop install vscode +``` +```ps +chocolatey install vscode -y +``` + +## The tweaklist itself + +Every tweaklist start with the following line: + +```ps +irm ts.ctt.cx | iex +``` +> If you're getting errors about a failed TLS handshake, put in ``[System.Net.ServicePointManager]::SecurityProtocol = 'Tls12'`` before (common errors on old Windows build / stripped ISOs) + +This will make sure the script is ran as admin, download and extract the repo, and import all the functions. If you already have the latest version installed it'll just directly import them. + +### The functions and their parameters + +The best way to learn how to use them is by looking at other tweaklists and the code behind the functions themselves, I've left a bunch of comments on them to make it easier to understand what's going on. + +Every parameter needs a `-` before them, example: + +```ps +FileExtensions -Show +``` +This will run the FileExtensions function with the Show parameter, it'll go in the registry and edit the value for it to show file extensions in Windows. + +This type of parameter is a ``switch``, it is declared at the start of the function as a variable with [switch] before it. When running the function with it, the variable $Show will be equal to the $true (PowerShell boolean uses variable :shrug:) + +You can also pass in strings, arrays and integers: + +```powershell +Remove-KnownAppxPackages -Exclude @('Calculator','MicrosoftStore') +``` +Strings are always surrounded by single or double strings, arrays are declared with @(), integers/floats are declared as is, as shown above you can put strings and integers in arrays. + +--- +### I'll add more to this guides as more functions and tweaklists show up and complexify themselves, that's all there is to it for now \ No newline at end of file diff --git a/import.ps1 b/import.ps1 new file mode 100644 index 0000000..c73a09a --- /dev/null +++ b/import.ps1 @@ -0,0 +1,119 @@ +<# + .SYNOPSIS + + Downloads and extracts (uses 7z if available) (or just clones with git, if available) the TweakList repo GitHub + + It starts by checking the commit count to see if it needs to update + +#> + +$FunctionTime = [System.Diagnostics.Stopwatch]::StartNew() # Makes a variable of how much time has passed since this was declared + +# Warns itself if not ran as Administrator +If (-Not([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) +{ + Write-Host "WARNING: You are not running PowerShell as an Administrator, a lot of functions may break" -ForegroundColor DarkRed + '' + Start-Sleep 3 +} + + +$org = 'couleur-tweak-tips' +$repo = 'TweakList' + + +$ParseTime = [System.Diagnostics.Stopwatch]::StartNew() + +if (Get-Command curl.exe -Ea Ignore){ # unlike Invoke-WebRequest, curl.exe does not make a flashing blue banner + + $script:API = curl.exe -s -I -k "https://api.github.com/repos/$org/$repo/commits?per_page=1" + + $CommitCount = (($API[9] -split '&page=') -split '>;')[3] + +}else{ + + $script:API = (Invoke-WebRequest -Useb "https://api.github.com/repos/$org/$repo/commits?per_page=1").RawContent + + $CommitCount = (($API -split "&page=")[2] -split '>; rel="last"')[0] + +} + +Write-Verbose "Parsed GitHub's API in $($ParseTime.Elapsed.Milliseconds)ms" -Verbose +Remove-Variable -Name ParseTime + + +if ($CommitCount -in '',$null -or $CommitCount -IsNot [int]){ + Write-Host "Failed to parse TweakList commit count" -ForegroundColor DarkRed + '' + pause + exit +} + +$folder = Join-Path $env:TEMP "$Repo-$CommitCount" + +if (Test-Path $folder){ + Write-Host "Latest TweakList version already installed (cc @ $CommitCount)" -ForegroundColor Green + +}else{ + + if (Get-Command git.exe -ErrorAction Ignore){ + + Write-Host 'Cloning with Git (faster)' -ForegroundColor Green + + git.exe clone https://github.com/$org/$repo.git "$Folder" + + }else{ + + $URL = "https://github.com/$org/$repo/archive/refs/heads/master.zip" + + $Zip = "$env:TMP\TweakList.zip" + + Invoke-WebRequest -UseBasicParsing $URL -OutFile $Zip + + if (Get-Command 7z.exe -ErrorAction Ignore){ + 7z.exe x "$ZipFile" -o"$folder" + }else{ + + try{ + Expand-Archive -LiteralPath $ZipFile -DestinationPath $Folder -Force + }catch{ + + Write-Host "Failed to extract the zip, exiting" -ForegroundColor DarkRed + '' + pause + exit + } + } + Remove-Item $ZipFile -Force -ErrorAction Inquire + } +} + +$ImportTime = [System.Diagnostics.Stopwatch]::StartNew() +Write-Host 'Importing the functions.. ' -NoNewline + +Remove-Variable -Name Functions -ErrorAction Ignore # Resets this function just incase + +Set-ExecutionPolicy Bypass -Scope Process -Force # Allows Import-Module to be used + +$Parameters = @{ + Path = $Folder + Recurse = $true + Exclude = 'import.ps1' + Include = '*.ps1' +} + +Get-ChildItem @Parameters | ForEach-Object { # Gets every function + + try{ + Write-Verbose "Importing $((Get-Item $PSItem).BaseName)" -Verbose + Import-Module $(Get-Item $PSItem).FullName + }catch{ + '' + Write-Host "Failed to Import function $((Get-Item $PSItem).BaseName)" -ForegroundColor Red + } + + $Functions++ +} + +Write-Host 'Done!' -ForegroundColor Green +Write-Verbose "Imported $Functions functions in $($ImportTime.ElapsedMilliseconds)ms, $($FunctionTime.ElapsedMilliseconds)ms in total" -Verbose diff --git a/modules/Windows/CreateRestorePoint.ps1 b/modules/Windows/CreateRestorePoint.ps1 new file mode 100644 index 0000000..05bef12 --- /dev/null +++ b/modules/Windows/CreateRestorePoint.ps1 @@ -0,0 +1,61 @@ +# Create a restore point for the system drive +function CreateRestorePoint +{ + $SystemDriveUniqueID = (Get-Volume | Where-Object -FilterScript {$_.DriveLetter -eq "$($env:SystemDrive[0])"}).UniqueID + $SystemProtection = ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SPP\Clients")."{09F7EDC5-294E-4180-AF6A-FB0E6A0E9513}") | Where-Object -FilterScript {$_ -match [regex]::Escape($SystemDriveUniqueID)} + + $ComputerRestorePoint = $false + + switch ($null -eq $SystemProtection) + { + $true + { + $ComputerRestorePoint = $true + Enable-ComputerRestore -Drive $env:SystemDrive + } + } + + # Never skip creating a restore point + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -PropertyType DWord -Value 0 -Force + + Checkpoint-Computer -Description "Sophia Script for Windows 10" -RestorePointType MODIFY_SETTINGS + + # Revert the System Restore checkpoint creation frequency to 1440 minutes + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -PropertyType DWord -Value 1440 -Force + + # Turn off System Protection for the system drive if it was turned off before without deleting the existing restore points + if ($ComputerRestorePoint) + { + Disable-ComputerRestore -Drive $env:SystemDrive + } +} +function CreateRestorePoint +{ + $SystemDriveUniqueID = (Get-Volume | Where-Object -FilterScript {$_.DriveLetter -eq "$($env:SystemDrive[0])"}).UniqueID + $SystemProtection = ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SPP\Clients")."{09F7EDC5-294E-4180-AF6A-FB0E6A0E9513}") | Where-Object -FilterScript {$_ -match [regex]::Escape($SystemDriveUniqueID)} + + $ComputerRestorePoint = $false + + switch ($null -eq $SystemProtection) + { + $true + { + $ComputerRestorePoint = $true + Enable-ComputerRestore -Drive $env:SystemDrive + } + } + + # Never skip creating a restore point + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -PropertyType DWord -Value 0 -Force + + Checkpoint-Computer -Description "Sophia Script for Windows 10" -RestorePointType MODIFY_SETTINGS + + # Revert the System Restore checkpoint creation frequency to 1440 minutes + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -PropertyType DWord -Value 1440 -Force + + # Turn off System Protection for the system drive if it was turned off before without deleting the existing restore points + if ($ComputerRestorePoint) + { + Disable-ComputerRestore -Drive $env:SystemDrive + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/Context menu/CastToDeviceContext.ps1 b/modules/Windows/Fine-tuning/Context menu/CastToDeviceContext.ps1 new file mode 100644 index 0000000..db6d386 --- /dev/null +++ b/modules/Windows/Fine-tuning/Context menu/CastToDeviceContext.ps1 @@ -0,0 +1,54 @@ +<# + .SYNOPSIS + The "Cast to Device" item in the media files and folders context menu + + .PARAMETER Hide + Hide the "Cast to Device" item from the media files and folders context menu + + .PARAMETER Show + Show the "Cast to Device" item in the media files and folders context menu + + .EXAMPLE + CastToDeviceContext -Hide + + .EXAMPLE + CastToDeviceContext -Show + + .NOTES + Current user +#> +function CastToDeviceContext +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Hide" + )] + [switch] + $Hide, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Show" + )] + [switch] + $Show + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Hide" + { + if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked")) + { + New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Force + } + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Name "{7AD84985-87B4-4a16-BE58-8B72A5B390F7}" -PropertyType String -Value "Play to menu" -Force + } + "Show" + { + Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Name "{7AD84985-87B4-4a16-BE58-8B72A5B390F7}" -Force -ErrorAction Ignore + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/Context menu/MultipleInvokeContext.ps1 b/modules/Windows/Fine-tuning/Context menu/MultipleInvokeContext.ps1 new file mode 100644 index 0000000..bea3984 --- /dev/null +++ b/modules/Windows/Fine-tuning/Context menu/MultipleInvokeContext.ps1 @@ -0,0 +1,50 @@ +<# + .SYNOPSIS + The "Open", "Print", and "Edit" items if more than 15 files selected + + .PARAMETER Enable + Enable the "Open", "Print", and "Edit" items if more than 15 files selected + + .PARAMETER Disable + Disable the "Open", "Print", and "Edit" items if more than 15 files selected + + .EXAMPLE + MultipleInvokeContext -Enable + + .EXAMPLE + MultipleInvokeContext -Disable + + .NOTES + Current user +#> +function MultipleInvokeContext +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Enable" + )] + [switch] + $Enable, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Disable" + )] + [switch] + $Disable + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Enable" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name MultipleInvokePromptMinimum -PropertyType DWord -Value 300 -Force + } + "Disable" + { + Remove-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name MultipleInvokePromptMinimum -Force -ErrorAction Ignore + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/Context menu/ShareContext.ps1 b/modules/Windows/Fine-tuning/Context menu/ShareContext.ps1 new file mode 100644 index 0000000..faf06a4 --- /dev/null +++ b/modules/Windows/Fine-tuning/Context menu/ShareContext.ps1 @@ -0,0 +1,54 @@ +<# + .SYNOPSIS + The "Share" item in the context menu + + .PARAMETER Hide + Hide the "Share" item from the context menu + + .PARAMETER Show + Show the "Share" item in the context menu + + .EXAMPLE + ShareContext -Hide + + .EXAMPLE + ShareContext -Show + + .NOTES + Current user +#> +function ShareContext +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Hide" + )] + [switch] + $Hide, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Show" + )] + [switch] + $Show + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Hide" + { + if (-not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked")) + { + New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Force + } + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Name "{E2BF9676-5F8F-435C-97EB-11607A5BEDF7}" -PropertyType String -Value "" -Force + } + "Show" + { + Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked" -Name "{E2BF9676-5F8F-435C-97EB-11607A5BEDF7}" -Force -ErrorAction Ignore + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/HiddenItems.ps1 b/modules/Windows/Fine-tuning/HiddenItems.ps1 new file mode 100644 index 0000000..8044922 --- /dev/null +++ b/modules/Windows/Fine-tuning/HiddenItems.ps1 @@ -0,0 +1,51 @@ +# Source: https://github.com/farag2/Sophia-Script-for-Windows +<# + .SYNOPSIS + Hidden files, folders, and drives + + .PARAMETER Enable + Show hidden files, folders, and drives + + .PARAMETER Disable + Do not show hidden files, folders, and drives + + .EXAMPLE + HiddenItems -Enable + + .EXAMPLE + HiddenItems -Disable + + .NOTES + Current user +#> +function HiddenItems +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Enable" + )] + [switch] + $Enable, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Disable" + )] + [switch] + $Disable + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Enable" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -PropertyType DWord -Value 1 -Force + } + "Disable" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -PropertyType DWord -Value 2 -Force + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/RecycleBinDeleteConfirmation.ps1 b/modules/Windows/Fine-tuning/RecycleBinDeleteConfirmation.ps1 new file mode 100644 index 0000000..27f36a5 --- /dev/null +++ b/modules/Windows/Fine-tuning/RecycleBinDeleteConfirmation.ps1 @@ -0,0 +1,54 @@ +<# + .SYNOPSIS + The recycle bin files delete confirmation dialog + + .PARAMETER Enable + Display the recycle bin files delete confirmation dialog + + .PARAMETER Disable + Do not display the recycle bin files delete confirmation dialog + + .EXAMPLE + RecycleBinDeleteConfirmation -Enable + + .EXAMPLE + RecycleBinDeleteConfirmation -Disable + + .NOTES + Current user +#> +function RecycleBinDeleteConfirmation +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Enable" + )] + [switch] + $Enable, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Disable" + )] + [switch] + $Disable + ) + + $ShellState = Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name ShellState + + switch ($PSCmdlet.ParameterSetName) + { + "Enable" + { + $ShellState[4] = 51 + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name ShellState -PropertyType Binary -Value $ShellState -Force + } + "Disable" + { + $ShellState[4] = 55 + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name ShellState -PropertyType Binary -Value $ShellState -Force + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/Set-DarkMode.ps1 b/modules/Windows/Fine-tuning/Set-DarkMode.ps1 new file mode 100644 index 0000000..ab24634 --- /dev/null +++ b/modules/Windows/Fine-tuning/Set-DarkMode.ps1 @@ -0,0 +1,9 @@ +function Set-DarkMode { + + @('AppsUseLightTheme','SystemUsesLightTheme') | + + ForEach-Object { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name $PSItem -PropertyType DWord -Value 0 -Force -ErrorAction Inquire + } + +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/StickyShift.ps1 b/modules/Windows/Fine-tuning/StickyShift.ps1 new file mode 100644 index 0000000..6e15260 --- /dev/null +++ b/modules/Windows/Fine-tuning/StickyShift.ps1 @@ -0,0 +1,50 @@ +<# + .SYNOPSIS + The keyboard schortcut for Stick keys + + .PARAMETER Disable + Turn off pressing the Shift key 5 times to turn Sticky keys + + .PARAMETER Enable + Turn on pressing the Shift key 5 times to turn Sticky keys + + .EXAMPLE + StickyShift -Disable + + .EXAMPLE + StickyShift -Enable + + .NOTES + Current user +#> +function StickyShift +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Disable" + )] + [switch] + $Disable, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Enable" + )] + [switch] + $Enable + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Disable" + { + New-ItemProperty -Path "HKCU:\Control Panel\Accessibility\StickyKeys" -Name Flags -PropertyType String -Value 506 -Force + } + "Enable" + { + New-ItemProperty -Path "HKCU:\Control Panel\Accessibility\StickyKeys" -Name Flags -PropertyType String -Value 510 -Force + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/Taskbar/PeopleTaskar.ps1 b/modules/Windows/Fine-tuning/Taskbar/PeopleTaskar.ps1 new file mode 100644 index 0000000..7096b0d --- /dev/null +++ b/modules/Windows/Fine-tuning/Taskbar/PeopleTaskar.ps1 @@ -0,0 +1,58 @@ +<# + .SYNOPSIS + People button on the taskbar + + .PARAMETER Hide + Hide People button on the taskbar + + .PARAMETER Show + Show People button on the taskbar + + .EXAMPLE + PeopleTaskbar -Hide + + .EXAMPLE + PeopleTaskbar -Show + + .NOTES + Current user +#> +function PeopleTaskbar +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Hide" + )] + [switch] + $Hide, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Show" + )] + [switch] + $Show + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Hide" + { + if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People)) + { + New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People -Force + } + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People -Name PeopleBand -PropertyType DWord -Value 0 -Force + } + "Show" + { + if (-not (Test-Path -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People)) + { + New-Item -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People -Force + } + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People -Name PeopleBand -PropertyType DWord -Value 1 -Force + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/Taskbar/TaskViewButton.ps1 b/modules/Windows/Fine-tuning/Taskbar/TaskViewButton.ps1 new file mode 100644 index 0000000..f5aeae0 --- /dev/null +++ b/modules/Windows/Fine-tuning/Taskbar/TaskViewButton.ps1 @@ -0,0 +1,52 @@ +# Source: https://github.com/farag2/Sophia-Script-for-Windows + +<# + .SYNOPSIS + Task view button on the taskbar + + .PARAMETER Hide + Hide the Task View button on the taskbar + + .PARAMETER Show + Show the Task View button on the taskbar + + .EXAMPLE + TaskViewButton -Hide + + .EXAMPLE + TaskViewButton -Show + + .NOTES + Current user +#> +function TaskViewButton +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Hide" + )] + [switch] + $Hide, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Show" + )] + [switch] + $Show + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Hide" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -PropertyType DWord -Value 0 -Force + } + "Show" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -PropertyType DWord -Value 1 -Force + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/Taskbar/TaskbarSearch.ps1 b/modules/Windows/Fine-tuning/Taskbar/TaskbarSearch.ps1 new file mode 100644 index 0000000..bbbfd6b --- /dev/null +++ b/modules/Windows/Fine-tuning/Taskbar/TaskbarSearch.ps1 @@ -0,0 +1,69 @@ +# Source: https://github.com/farag2/Sophia-Script-for-Windows + +<# + .SYNOPSIS + Search on the taskbar + + .PARAMETER Hide + Hide the search on the taskbar + + .PARAMETER SearchIcon + Show the search icon on the taskbar + + .PARAMETER SearchBox + Show the search box on the taskbar + + .EXAMPLE + TaskbarSearch -SearchBox + + .EXAMPLE + TaskbarSearch -SearchIcon + + .EXAMPLE + TaskbarSearch -Hide + + .NOTES + Current user +#> +function TaskbarSearch +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Hide" + )] + [switch] + $Hide, + + [Parameter( + Mandatory = $true, + ParameterSetName = "SearchIcon" + )] + [switch] + $SearchIcon, + + [Parameter( + Mandatory = $true, + ParameterSetName = "SearchBox" + )] + [switch] + $SearchBox + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Hide" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -PropertyType DWord -Value 0 -Force + } + "SearchIcon" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -PropertyType DWord -Value 1 -Force + } + "SearchBox" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -PropertyType DWord -Value 2 -Force + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/Taskbar/UnpinTaskbarShortcuts.ps1 b/modules/Windows/Fine-tuning/Taskbar/UnpinTaskbarShortcuts.ps1 new file mode 100644 index 0000000..7cd65c6 --- /dev/null +++ b/modules/Windows/Fine-tuning/Taskbar/UnpinTaskbarShortcuts.ps1 @@ -0,0 +1,100 @@ +# Source: https://github.com/farag2/Sophia-Script-for-Windows + +<# + .SYNOPSIS + Unpin shortcuts from the taskbar + + .PARAMETER Edge + Unpin the "Microsoft Edge" shortcut from the taskbar + + .PARAMETER Store + Unpin the "Microsoft Store" shortcut from the taskbar + + .PARAMETER Mail + Unpin the "Mail" shortcut from the taskbar + + .EXAMPLE + UnpinTaskbarShortcuts -Shortcuts Edge, Store, Mail + + .NOTES + Current user + + .LINK + https://github.com/Disassembler0/Win10-Initial-Setup-Script/issues/8#issue-227159084 +#> +function UnpinTaskbarShortcuts +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet("Edge", "Store", "Mail")] + [string[]] + $Shortcuts + ) + + # Extract strings from shell32.dll using its' number + $Signature = @{ + Namespace = "WinAPI" + Name = "GetStr" + Language = "CSharp" + MemberDefinition = @" +[DllImport("kernel32.dll", CharSet = CharSet.Auto)] +public static extern IntPtr GetModuleHandle(string lpModuleName); + +[DllImport("user32.dll", CharSet = CharSet.Auto)] +internal static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax); + +public static string GetString(uint strId) +{ + IntPtr intPtr = GetModuleHandle("shell32.dll"); + StringBuilder sb = new StringBuilder(255); + LoadString(intPtr, strId, sb, sb.Capacity); + return sb.ToString(); +} +"@ + } + if (-not ("WinAPI.GetStr" -as [type])) + { + Add-Type @Signature -Using System.Text + } + + # Extract the localized "Unpin from taskbar" string from shell32.dll + $LocalizedString = [WinAPI.GetStr]::GetString(5387) + + foreach ($Shortcut in $Shortcuts) + { + switch ($Shortcut) + { + Edge + { + 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).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()} + } + } + Store + { + # Start-Job is used due to that the calling this function before UninstallUWPApps breaks the retrieval of the localized UWP apps packages names + Start-Job -ScriptBlock { + $Apps = (New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() + ($Apps | Where-Object -FilterScript {$_.Name -eq "Microsoft Store"}).Verbs() | Where-Object -FilterScript {$_.Name -eq $Using:LocalizedString} | ForEach-Object -Process {$_.DoIt()} + } | Receive-Job -Wait -AutoRemoveJob + } + Mail + { + # Start-Job is used due to that the calling this function before UninstallUWPApps breaks the retrieval of the localized UWP apps packages names + if (Get-AppxPackage -Name microsoft.windowscommunicationsapps) + { + Start-Job -ScriptBlock { + $Apps = (New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() + ($Apps | Where-Object -FilterScript {$_.Path -eq "microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.mail"}).Verbs() | Where-Object -FilterScript {$_.Name -eq $Using:LocalizedString} | ForEach-Object -Process {$_.DoIt()} + } | Receive-Job -Wait -AutoRemoveJob + } + } + } + } +} \ No newline at end of file diff --git a/modules/Windows/Fine-tuning/UseStoreOpenWith.ps1 b/modules/Windows/Fine-tuning/UseStoreOpenWith.ps1 new file mode 100644 index 0000000..b8251cf --- /dev/null +++ b/modules/Windows/Fine-tuning/UseStoreOpenWith.ps1 @@ -0,0 +1,54 @@ +<# + .SYNOPSIS + The "Look for an app in the Microsoft Store" item in the "Open with" dialog + + .PARAMETER Hide + Hide the "Look for an app in the Microsoft Store" item in the "Open with" dialog + + .PARAMETER Show + Show the "Look for an app in the Microsoft Store" item in the "Open with" dialog + + .EXAMPLE + UseStoreOpenWith -Hide + + .EXAMPLE + UseStoreOpenWith -Show + + .NOTES + Current user +#> +function UseStoreOpenWith +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Hide" + )] + [switch] + $Hide, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Show" + )] + [switch] + $Show + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Hide" + { + if (-not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer)) + { + New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Force + } + New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -PropertyType DWord -Value 1 -Force + } + "Show" + { + Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name NoUseStoreOpenWith -Force -ErrorAction Ignore + } + } +} \ No newline at end of file diff --git a/modules/Windows/Gaming Settings/GPUScheduling.ps1 b/modules/Windows/Gaming Settings/GPUScheduling.ps1 new file mode 100644 index 0000000..b10272f --- /dev/null +++ b/modules/Windows/Gaming Settings/GPUScheduling.ps1 @@ -0,0 +1,65 @@ +<# + .SYNOPSIS + Hardware-accelerated GPU scheduling + + .PARAMETER Enable + Enable hardware-accelerated GPU scheduling + + .PARAMETER Disable + Disable hardware-accelerated GPU scheduling + + .EXAMPLE + GPUScheduling -Enable + + .EXAMPLE + GPUScheduling -Disable + + .NOTES + Only with a dedicated GPU and WDDM verion is 2.7 or higher. Restart needed + + .NOTES + Current user +#> +function GPUScheduling +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Enable" + )] + [switch] + $Enable, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Disable" + )] + [switch] + $Disable + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Enable" + { + if (Get-CimInstance -ClassName CIM_VideoController | Where-Object -FilterScript {($_.AdapterDACType -ne "Internal") -and ($null -ne $_.AdapterDACType)}) + { + # Determining whether an OS is not installed on a virtual machine + if ((Get-CimInstance -ClassName CIM_ComputerSystem).Model -notmatch "Virtual") + { + # Checking whether a WDDM verion is 2.7 or higher + $WddmVersion_Min = Get-ItemPropertyValue -Path HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\FeatureSetUsage -Name WddmVersion_Min + if ($WddmVersion_Min -ge 2700) + { + New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers" -Name HwSchMode -PropertyType DWord -Value 2 -Force + } + } + } + } + "Disable" + { + New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers" -Name HwSchMode -PropertyType DWord -Value 1 -Force + } + } +} \ No newline at end of file diff --git a/modules/Windows/Gaming Settings/XboxGameTips.ps1 b/modules/Windows/Gaming Settings/XboxGameTips.ps1 new file mode 100644 index 0000000..3e3b9cb --- /dev/null +++ b/modules/Windows/Gaming Settings/XboxGameTips.ps1 @@ -0,0 +1,56 @@ +<# + .SYNOPSIS + Xbox Game Bar tips + + .PARAMETER Disable + Disable Xbox Game Bar tips + + .PARAMETER Enable + Enable Xbox Game Bar tips + + .EXAMPLE + XboxGameTips -Disable + + .EXAMPLE + XboxGameTips -Enable + + .NOTES + Current user +#> +function XboxGameTips +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Disable" + )] + [switch] + $Disable, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Enable" + )] + [switch] + $Enable + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Disable" + { + if ((Get-AppxPackage -Name Microsoft.XboxGamingOverlay) -or (Get-AppxPackage -Name Microsoft.GamingApp)) + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\GameBar -Name ShowStartupPanel -PropertyType DWord -Value 0 -Force + } + } + "Enable" + { + if ((Get-AppxPackage -Name Microsoft.XboxGamingOverlay) -or (Get-AppxPackage -Name Microsoft.GamingApp)) + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\GameBar -Name ShowStartupPanel -PropertyType DWord -Value 1 -Force + } + } + } +} \ No newline at end of file diff --git a/modules/Windows/Get-StartupServices.ps1 b/modules/Windows/Get-StartupServices.ps1 new file mode 100644 index 0000000..8e483a5 --- /dev/null +++ b/modules/Windows/Get-StartupServices.ps1 @@ -0,0 +1,5 @@ +function Get-StartupServices { + +Get-Service | Where-Object -FilterScript { $_.StartType -EQ 'Automatic' } | Format-List + +} \ No newline at end of file diff --git a/modules/Windows/HiddenItems.ps1 b/modules/Windows/HiddenItems.ps1 new file mode 100644 index 0000000..a58be83 --- /dev/null +++ b/modules/Windows/HiddenItems.ps1 @@ -0,0 +1,36 @@ +<# + .SYNOPSIS + Set weither to show or hide files, folders, and drives + +#> +function HiddenItems +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Shown" + )] + [switch] + $Shown, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Hidden" + )] + [switch] + $Hidden + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Shown" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -PropertyType DWord -Value 1 -Force + } + "Hidden" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -PropertyType DWord -Value 2 -Force + } + } +} \ No newline at end of file diff --git a/modules/Windows/OneDrive.ps1 b/modules/Windows/OneDrive.ps1 new file mode 100644 index 0000000..c906009 --- /dev/null +++ b/modules/Windows/OneDrive.ps1 @@ -0,0 +1,247 @@ +function OneDrive +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Uninstall" + )] + [switch] + $Uninstall, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Install" + )] + [switch] + $Install + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Uninstall" + { + [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 + Stop-Process -Name OneDriveSetup -Force -ErrorAction Ignore + Stop-Process -Name 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) + { + 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 +} + +[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] +static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags dwFlags); + +public static bool MarkFileDelete (string sourcefile) +{ + return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT); +} +"@ + } + + # If there are some files or folders left in %LOCALAPPDATA%\Temp + 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 + { + # Invoke-Item doesn't work + 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 -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 + 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 -Value 0 -Force + Stop-Process -Name explorer -Force + + Start-Sleep -Seconds 3 + + # Restoring closed folders + foreach ($Script:OpenedFolder in $Script:OpenedFolders) + { + if (Test-Path -Path $Script:OpenedFolder) + { + Invoke-Item -Path $Script:OpenedFolder + } + } + + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoRestartShell -Value 1 -Force + + # Attempt to unregister FileSyncShell64.dll and remove + $FileSyncShell64dlls = Get-ChildItem -Path "$OneDriveFolder\*\amd64\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 (-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)} + } + } + + Start-Sleep -Seconds 1 + + # Start the File Explorer process + Start-Process -FilePath explorer + + # Restoring closed folders + foreach ($OpenedFolder in $OpenedFolders) + { + if (Test-Path -Path $OpenedFolder) + { + # Invoke-Item doesn't work + Start-Process -FilePath explorer -ArgumentList $OpenedFolder + } + } + + 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 + } + } + "Install" + { + $OneDrive = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore + if (-not $OneDrive) + { + 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 + { + # Check the internet connection + $Parameters = @{ + Uri = "https://www.google.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true + } + if (-not (Invoke-WebRequest @Parameters).StatusDescription) + { + return + } + + # 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/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 = $OneDriveURL + OutFile = "$DownloadsFolder\OneDriveSetup.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + 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 + + 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 + + Get-ScheduledTask -TaskName "Onedrive* Update*" | Enable-ScheduledTask + Get-ScheduledTask -TaskName "Onedrive* Update*" | Start-ScheduledTask + } + } + } +} \ No newline at end of file diff --git a/modules/Windows/Privacy and telemetry/AppSuggestions.ps1 b/modules/Windows/Privacy and telemetry/AppSuggestions.ps1 new file mode 100644 index 0000000..20bbd87 --- /dev/null +++ b/modules/Windows/Privacy and telemetry/AppSuggestions.ps1 @@ -0,0 +1,50 @@ +<# + .SYNOPSIS + App suggestions in the Start menu + + .PARAMETER Hide + Hide app suggestions in the Start menu + + .PARAMETER Show + Show app suggestions in the Start menu + + .EXAMPLE + AppSuggestions -Hide + + .EXAMPLE + AppSuggestions -Show + + .NOTES + Current user +#> +function AppSuggestions +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Hide" + )] + [switch] + $Hide, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Show" + )] + [switch] + $Show + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Hide" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-338388Enabled -PropertyType DWord -Value 0 -Force + } + "Show" + { + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager -Name SubscribedContent-338388Enabled -PropertyType DWord -Value 1 -Force + } + } +} \ No newline at end of file diff --git a/modules/Windows/Privacy and telemetry/DiagnosticDataLevel.ps1 b/modules/Windows/Privacy and telemetry/DiagnosticDataLevel.ps1 new file mode 100644 index 0000000..c192f55 --- /dev/null +++ b/modules/Windows/Privacy and telemetry/DiagnosticDataLevel.ps1 @@ -0,0 +1,66 @@ +<# + .SYNOPSIS + Diagnostic data + + .PARAMETER Minimal + Set the diagnostic data collection to minimum + + .PARAMETER Default + Set the diagnostic data collection to default + + .EXAMPLE + DiagnosticDataLevel -Minimal + + .EXAMPLE + DiagnosticDataLevel -Default + + .NOTES + Machine-wide +#> +function DiagnosticDataLevel +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Minimal" + )] + [switch] + $Minimal, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Default" + )] + [switch] + $Default + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Minimal" + { + if (Get-WindowsEdition -Online | Where-Object -FilterScript {$_.Edition -like "Enterprise*" -or $_.Edition -eq "Education"}) + { + # Security level + New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 0 -Force + } + else + { + # Required diagnostic data + New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 1 -Force + } + New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 1 -Force + + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 1 -Force + } + "Default" + { + # Optional diagnostic data + New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 3 -Force + New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 3 -Force + + New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 3 -Force + } + } +} diff --git a/modules/Windows/Privacy and telemetry/ErrorReporting.ps1 b/modules/Windows/Privacy and telemetry/ErrorReporting.ps1 new file mode 100644 index 0000000..3d8d4d0 --- /dev/null +++ b/modules/Windows/Privacy and telemetry/ErrorReporting.ps1 @@ -0,0 +1,61 @@ +<# + .SYNOPSIS + Windows Error Reporting + + .PARAMETER Disable + Turn off Windows Error Reporting + + .PARAMETER Enable + Turn on Windows Error Reporting + + .EXAMPLE + ErrorReporting -Disable + + .EXAMPLE + ErrorReporting -Enable + + .NOTES + Current user +#> +function ErrorReporting +{ + param + ( + [Parameter( + Mandatory = $true, + ParameterSetName = "Disable" + )] + [switch] + $Disable, + + [Parameter( + Mandatory = $true, + ParameterSetName = "Enable" + )] + [switch] + $Enable + ) + + switch ($PSCmdlet.ParameterSetName) + { + "Disable" + { + if ((Get-WindowsEdition -Online).Edition -notmatch "Core") + { + Get-ScheduledTask -TaskName QueueReporting | Disable-ScheduledTask + New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name Disabled -PropertyType DWord -Value 1 -Force + } + + Get-Service -Name WerSvc | Stop-Service -Force + Get-Service -Name WerSvc | Set-Service -StartupType Disabled + } + "Enable" + { + Get-ScheduledTask -TaskName QueueReporting | Enable-ScheduledTask + Remove-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Force -ErrorAction Ignore + + Get-Service -Name WerSvc | Set-Service -StartupType Manual + Get-Service -Name WerSvc | Start-Service + } + } +} \ No newline at end of file diff --git a/modules/Windows/Remove-KnownAppxPackages.ps1 b/modules/Windows/Remove-KnownAppxPackages.ps1 new file mode 100644 index 0000000..3fd9b38 --- /dev/null +++ b/modules/Windows/Remove-KnownAppxPackages.ps1 @@ -0,0 +1,76 @@ +<# + +List of commonly used Appx packages: + +Windows.PrintDialog +Microsoft.WindowsCalculator +Microsoft.ZuneVideo +Microsoft.Windows.Photos + +I did not add them, but you can opt in by calling the function, e.g: + + Remove-KnownAppxPackages -Add @('Windows.PrintDialog','Microsoft.WindowsCalculator') + +Don't forget to surround them by a ' so PowerShell considers them as a string + +#> + +function Remove-KnownAppxPackages ([array]$Add,[array]$Exclude) { + + $AppxPackages = @( + "Microsoft.Windows.NarratorQuickStart" + "Microsoft.Wallet" + "3DBuilder" + "Microsoft.Microsoft3DViewer" + "WindowsAlarms" + "BingSports" + "WindowsCommunicationsapps" + "WindowsCamera" + "Feedback" + "Microsoft.GetHelp" + "GetStarted" + "ZuneMusic" + "WindowsMaps" + "Microsoft.Messaging" + "Microsoft.MixedReality.Portal" + "Microsoft.OneConnect" + "BingFinance" + "Microsoft.MSPaint" + "People" + "WindowsPhone" + "Microsoft.YourPhone" + "Microsoft.Print3D" + "Microsoft.ScreenSketch" + "Microsoft.MicrosoftStickyNotes" + "SoundRecorder" + + ) | Where-Object { $_ -notin $Exclude } + + $AppxPackages += $Add # Appends the Appx packages given by the user (if any) + + if (-Not($KeepXboxPackages)){ + $AppxPackages += @( + "XboxApp" + "Microsoft.XboxGameOverlay" + "Microsoft.XboxGamingOverlay" + "Microsoft.XboxSpeechToTextOverlay" + "Microsoft.XboxIdentityProvider" + "Microsoft.XboxGameCallableUI" + ) + } + + + ForEach ($Package in $AppxPackages){ + + if ($PSVersionTable.PSEdition -eq 'Core'){ # Newer PowerShell versions don't have Appx cmdlets, manually calling PowerShell to + + powershell.exe -command "Get-AppxPackage `"*$Package*`" | Remove-AppxPackage" + + }else{ + Get-AppxPackage "*$Package*" | Remove-AppxPackage + } + + } + +} + diff --git a/modules/Windows/Remove-UselessFiles.ps1 b/modules/Windows/Remove-UselessFiles.ps1 new file mode 100644 index 0000000..dbde33f --- /dev/null +++ b/modules/Windows/Remove-UselessFiles.ps1 @@ -0,0 +1,9 @@ +function Remove-UselessFiles { + + @( + "$env:TEMP" + "$env:WINDIR\TEMP" + "$env:HOMEDRIVE\TEMP" + ) | ForEach-Object { Remove-Item (Convert-Path $_\*) -Force -ErrorAction SilentlyContinue } + +} \ No newline at end of file diff --git a/modules/Windows/Set-Win32PrioritySeparation.ps1 b/modules/Windows/Set-Win32PrioritySeparation.ps1 new file mode 100644 index 0000000..c062f41 --- /dev/null +++ b/modules/Windows/Set-Win32PrioritySeparation.ps1 @@ -0,0 +1,8 @@ +function Set-Win32ProritySeparation ([int]$Value){ + + $Path = 'REGISTRY::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\PriorityControl' + $current = (Get-ItemProperty $Path).Win32PrioritySeparation + Set-ItemProperty -Path $Path -Value $Value -Type DWord -Force -ErrorAction Inquire + Write-Verbose "Set-Win32ProritySeparation: Changed from $current to $((Get-ItemProperty $Path).Win32PrioritySeparation)"-Verbose + +} \ No newline at end of file