-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows-init.ps1
111 lines (96 loc) · 3.51 KB
/
windows-init.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
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
#Requires -RunAsAdministrator
param (
[Parameter(HelpMessage = "Enter the path of the registry values CSV file.")][string]$RegValsPath,
[Parameter(HelpMessage = "Commit registry changes")][switch]$CommitReg,
[Parameter(HelpMessage = "Enter the path of the choco packages CSV file.")][string]$ChocoPackagesPath,
[Parameter(HelpMessage = "Install choco packages")][switch]$CommitChoco
)
Set-TimeZone -Name "Cen. Australia Standard Time"
# Set Registry Entries
if ($RegValsPath -and (Test-Path $RegValsPath)) {
Import-Csv $RegValsPath -Delimiter '|' |
ForEach-Object {
if ($_.Path -and $_.Name -and $_.Value -and $_.Type) {
$registryPath = $_.Path
$name = $_.Name
$val = $_.Value
$type = $_.Type
if ($CommitReg) {
if (!(Test-Path $registryPath)) {
New-Item -Path $registryPath -Force | Out-Null
}
New-ItemProperty -Path $registryPath -Name $name -Value $val -PropertyType $type -Force | Out-Null
}
if ($_.Description) {
Write-Host $_.Description
}
else {
Write-Host "Updated $registryPath\$name with value '$val'"
}
}
}
# Restart Explorer 💣
if ($CommitReg) {
Stop-Process -ProcessName explorer
}
}
else {
Write-Host "Skipping regedit..."
}
# Choco Time 🍫
if ($ChocoPackagesPath -and (Test-Path $ChocoPackagesPath)) {
$chocoInstalled = Get-Command "choco" -errorAction SilentlyContinue
if ($CommitChoco) {
if ($chocoInstalled) {
Write-Host "Chocolatey installation found..."
$currentVer = New-Object System.Version(choco -v)
$requiredVer = New-Object System.Version("0.10.4")
if ($currentVer -lt $requiredVer) {
Write-Host "Chocolatey version $requiredVer or greater required, triggering update..."
choco upgrade chocolatey -y
}
}
else {
Write-Host "Installing Chocolatey..."
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
choco feature enable --name=useRememberedArgumentsForUpgrades
}
$installedPackages = @{ };
choco list --lo -r | ConvertFrom-Csv -Header Package, Version -Delimiter '|' |
ForEach-Object {
if ($_.Package) {
$installedPackages[$_.Package] = $_.Version
}
}
$chocoInstallCmds = @();
Import-Csv $ChocoPackagesPath -Delimiter '|' |
ForEach-Object {
if ($_.Package) {
$packName = $_.Package
$params = $_.Parameters
$currentVersion = $installedPackages[$packName]
if ($currentVersion) {
Write-Host "Package $packName ($currentVersion) is already installed, skipping install..."
}
else {
$installArgs = if ($params) { "$packName $params -y" } else { "$packName -y" }
$chocoCommand = "choco install $installArgs -r"
$chocoInstallCmds += $chocoCommand
}
}
}
$chocoInstallCmds |
ForEach-Object {
if ($CommitChoco) {
Write-Host $_
Invoke-Expression $_
}
else {
Write-Host $_
}
}
}
else {
Write-Host "Skipping choco..."
}