########## # Win 10 / Server 2016 / Server 2019 Initial Setup Script - Main execution loop # Author: Disassembler # Version: v3.4, 2018-12-19 # 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 $global:tweaks = $global:tweaks | Where-Object { $_ -ne $tweak.Substring(1) } } ElseIf ($tweak -ne "") { # Otherwise add the tweak $global: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] $PSCommandArgs += "-include `"$include`"" # Import the included file as a module Import-Module -Name $include } ElseIf ($args[$i].ToLower() -eq "-preset") { # Resolve full path to the preset file $preset = Resolve-Path $args[++$i] $PSCommandArgs += "-preset `"$preset`"" # Load tweak names from the preset file Get-Content $preset -ErrorAction Stop | ForEach-Object { AddOrRemoveTweak($_.Split("#")[0].Trim()) } } Else { $PSCommandArgs += $args[$i] # Load tweak names from command line AddOrRemoveTweak($args[$i]) } $i++ } # Call the desired tweak functions $tweaks | ForEach-Object { Invoke-Expression $_ }