forked from Disassembler0/Win10-Initial-Setup-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Win10.ps1
59 lines (54 loc) · 2.15 KB
/
Win10.ps1
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
##########
# Win 10 / Server 2016 / Server 2019 Initial Setup Script - Main execution loop
# Author: Disassembler <disassembler@dasm.cz>
# Version: v3.10, 2020-07-15
# Source: https://github.com/Disassembler0/Win10-Initial-Setup-Script
##########
# Relaunch the script with administrator privileges
Function RequireAdmin {
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" $PSCommandArgs" -Verb RunAs
Exit
}
}
$tweaks = @()
$PSCommandArgs = @()
Function AddOrRemoveTweak($tweak) {
If ($tweak[0] -eq "!") {
# If the name starts with exclamation mark (!), exclude the tweak from selection
$script:tweaks = $script:tweaks | Where-Object { $_ -ne $tweak.Substring(1) }
} ElseIf ($tweak -ne "") {
# Otherwise add the tweak
$script:tweaks += $tweak
}
}
# Parse and resolve paths in passed arguments
$i = 0
While ($i -lt $args.Length) {
If ($args[$i].ToLower() -eq "-include") {
# Resolve full path to the included file
$include = Resolve-Path $args[++$i] -ErrorAction Stop
$PSCommandArgs += "-include `"$include`""
# Import the included file as a module
Import-Module -Name $include -ErrorAction Stop
} ElseIf ($args[$i].ToLower() -eq "-preset") {
# Resolve full path to the preset file
$preset = Resolve-Path $args[++$i] -ErrorAction Stop
$PSCommandArgs += "-preset `"$preset`""
# Load tweak names from the preset file
Get-Content $preset -ErrorAction Stop | ForEach-Object { AddOrRemoveTweak($_.Split("#")[0].Trim()) }
} ElseIf ($args[$i].ToLower() -eq "-log") {
# Resolve full path to the output file
$log = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($args[++$i])
$PSCommandArgs += "-log `"$log`""
# Record session to the output file
Start-Transcript $log
} Else {
$PSCommandArgs += $args[$i]
# Load tweak names from command line
AddOrRemoveTweak($args[$i])
}
$i++
}
# Call the desired tweak functions
$tweaks | ForEach-Object { Invoke-Expression $_ }