-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs + import.ps1 + simple funcs / sophia script funcs
- Loading branch information
Showing
28 changed files
with
1,600 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
modules/Windows/Fine-tuning/Context menu/CastToDeviceContext.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |
Oops, something went wrong.