This repository was archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWinTweaks.psm1
154 lines (142 loc) · 5.42 KB
/
WinTweaks.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
##########
# WinTweak: command-line interface for Windows Tweaks
# Author: Andrea Brandi <[email protected]>
##########
#Requires -Version 5.1
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$modulesList = @(
'Apps',
'Explorer',
'Network',
'Privacy',
'Security',
'Server',
'Service',
'Shell',
'Unpin'
)
function GetInformation($from) {
$data = (Get-Command $from).ScriptBlock.Ast
$data.GetHelpContent().Description.Trim()
$data.Extent | Select-Object File, Text | Format-List
}
function GetDescription($from) {
$data = (Get-Command $from).ScriptBlock.Ast
$data.GetHelpContent().Description.Trim()
}
function TweakExists($name) {
Get-Command -Module $modulesList | Where { $_.Name -eq "$tweak" }
}
function ApplyTweaks($tweaks) {
foreach ($tweak in $tweaks) {
if (TweakExists $tweak) {
Write-Host "Apply tweak: $tweak" -ForegroundColor Cyan
Invoke-Expression $tweak
} else {
Write-Host "$tweak not found" -ForegroundColor Red
}
}
}
function SearchTweak($query, $modules = $modulesList) {
$results = Get-Command -Module $modules | Where { $_.Name -like "*$query*" }
$format = @{ Expression = { $_.Source }; Label = "Module" },
@{ Expression = { $_.Name}; Label = "Tweak" },
@{ Expression = { GetDescription -from $_ }; Label = "Description" };
$results | Format-Table $format
}
function WinTweaks {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[string]$command = 'help',
[parameter(Position = 1, ValueFromRemainingArguments = $true)]
[array]$options
)
switch ($command) {
{ 'Help', '--help', '/?' -contains $_ } {
switch ($options) {
{ [string]::IsNullOrWhiteSpace($_) } {
Write-Host "Usage: wintweaks <command> [<options>]`n"
Write-Host "List of available commands`n"
Write-Host "apply Apply one or more tweaks"
Write-Host "help Show help for a command"
Write-Host "info Display information about a tweak"
Write-Host "list Print a list of all available tweaks with descriptions"
Write-Host "search Search available tweaks with descriptions`n"
Write-Host "Type 'wintweaks help <commands>' to get help for a specific command."
}
{ 'apply' -eq $_ } {
Write-Host "Usage: wintweaks apply [<tweaks>]`n"
}
{ 'info' -eq $_ } {
Write-Host "Usage: wintweaks info <tweak>`n"
Write-Host "Type 'wintweaks list' to get list of all available tweaks."
Write-Host "Type 'wintweaks search <query>' to search for keywords."
}
{ 'list' -eq $_ } {
Write-Host "Usage: wintweaks list <module>`n"
Write-Host "Type 'wintweaks list modules' to get list of all available modules."
}
{ 'search' -eq $_ } {
Write-Host "Usage: wintweaks search <query>`n"
Write-Host "Searches for tweaks available to apply.`n"
Write-Host "If used with <query>, shows tweak names that match the query."
Write-Host "Without <query>, shows all the available tweaks."
}
default {
Write-Host "WinTweaks: '$options' isn't a valid command. See 'wintweaks help' for valid entries."
}
}
}
Search {
if ($results = SearchTweak $options) {
Write-Host "Search Results for '$options'"
$results
} else {
Write-Host "No results found for '$options'"
}
}
Info {
if ([string]::IsNullOrWhiteSpace($options)) {
wintweaks help info
} elseif ($results = SearchTweak $options) {
Write-Host "Information about '$options'`n"
GetInformation $options
} else {
Write-Host "No information found for '$options'"
}
}
List {
switch ($options) {
{ [string]::IsNullOrWhiteSpace($_) } {
SearchTweak ""
}
{ $modulesList -contains $_ } {
SearchTweak "" $_
}
{ 'modules' -eq $_ } {
Write-Host "List of available modules`n"
$modulesList | ForEach-Object { Write-Host $_ }
Write-Host "`nType 'wintweaks list <module>' to get module's tweaks."
}
default {
Write-Host "WinTweaks: '$options' isn't a valid module. See 'wintweaks list modules' for valid entries."
}
}
}
Apply {
switch ($options) {
{ [string]::IsNullOrWhiteSpace($_) } {
Write-Host "<tweaks> missed. See 'wintweaks help apply'" -ForegroundColor Red
}
default {
ApplyTweaks $options
}
}
}
default {
Write-Host "WinTweaks: '$command' isn't a valid command. See 'wintweaks help'."
}
}
}