Skip to content

Commit

Permalink
docs + import.ps1 + simple funcs / sophia script funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
couleurm committed Jan 4, 2022
1 parent a282413 commit 7f27aa4
Show file tree
Hide file tree
Showing 28 changed files with 1,600 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
👋 <strong>Contributors:</strong> if you'd like to contribute, feel free to <a href="https://github.com/couleur-tweak-tips/TweakScript/issues/new/choose">make an issue </a> to suggest a relevant tweak
👋 <strong>Contributors:</strong> if you'd like to contribute, feel free to <a href="https://github.com/couleur-tweak-tips/TweakList/issues/new/choose">make an issue </a> to suggest a relevant tweak
</p>

</br>
Expand All @@ -8,36 +8,36 @@

<p align="center">
<img align=center src="https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/ps_black_64.svg?sanitize=true" alt="PS7 logo" width="75" /> </br>
<strong>Tweak Script</strong> </br>
<strong>TweakList</strong> </br>
</br>
Make your very own tweaking/debloating script, with one line per tweak </br>
<i>Tweak interpreter based in PowerShell</i></br>
<a href="#overview">Overview</a>
<a href="https://dsc.gg/ctt">Discord Server</a>
<a href="/couleur-tweak-tips/TweakScript/tree/main/Docs">Docs</a>
<a href="/couleur-tweak-tips/TweakList/tree/main/Docs">Docs</a>
</p>
<p align="center">
<a href="/couleur-tweak-tips/TweakScript">
<img src="https://img.shields.io/github/languages/code-size/couleur-tweak-tips/TweakScript.svg" alt="Code Size" />
<a href="/couleur-tweak-tips/TweakList">
<img src="https://img.shields.io/github/languages/code-size/couleur-tweak-tips/TweakList.svg" alt="Code Size" />
</a>
<a href="/couleur-tweak-tips/TweakScript">
<img src="https://img.shields.io/github/repo-size/couleur-tweak-tips/TweakScript.svg" alt="Repository size" />
<a href="/couleur-tweak-tips/TweakList">
<img src="https://img.shields.io/github/repo-size/couleur-tweak-tips/TweakList.svg" alt="Repository size" />
</a>
<a href="https://discord.com/invite/aPVMJy78Pa">
<img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
</a>
<a href="/couleur-tweak-tips/TweakScript/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/couleur-tweak-tips/TweakScript.svg" alt="License" />
<a href="/couleur-tweak-tips/TweakList/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/couleur-tweak-tips/TweakList.svg" alt="License" />
</a>

</p>
</br>

[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")"**

</br>

Expand Down
25 changes: 25 additions & 0 deletions docs/Making your own functions.MD
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.
51 changes: 51 additions & 0 deletions docs/Making your own tweakscript.MD
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
119 changes: 119 additions & 0 deletions import.ps1
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
61 changes: 61 additions & 0 deletions modules/Windows/CreateRestorePoint.ps1
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 modules/Windows/Fine-tuning/Context menu/CastToDeviceContext.ps1
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
}
}
}
Loading

0 comments on commit 7f27aa4

Please sign in to comment.