-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprovision-base.ps1
142 lines (120 loc) · 5.86 KB
/
provision-base.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
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
param(
[string]$extraHosts
)
# set the extra hosts.
Add-Content -Encoding ascii c:\windows\system32\drivers\etc\hosts $extraHosts
# expand the C drive when there is disk available.
$partition = Get-Partition -DriveLetter C
$partitionSupportedSize = Get-PartitionSupportedSize -DriveLetter C
# calculate the maximum size (1MB aligned).
# NB when running in the hyperv hypervisor, the size must be must multiple of
# 1MB, otherwise, it fails with:
# The size of the extent is less than the minimum of 1MB.
$sizeMax = $partitionSupportedSize.SizeMax - ($partitionSupportedSize.SizeMax % (1*1024*1024))
if ($partition.Size -lt $sizeMax) {
Write-Host "Expanding the C: partition from $($partition.Size) to $sizeMax bytes..."
Resize-Partition -DriveLetter C -Size $sizeMax
}
# set keyboard layout.
# NB you can get the name from the list:
# [Globalization.CultureInfo]::GetCultures('InstalledWin32Cultures') | Out-GridView
Set-WinUserLanguageList pt-PT -Force
# set the date format, number format, etc.
Set-Culture pt-PT
# set the welcome screen culture and keyboard layout.
# NB the .DEFAULT key is for the local SYSTEM account (S-1-5-18).
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null
'Control Panel\International','Keyboard Layout' | ForEach-Object {
Remove-Item -Path "HKU:.DEFAULT\$_" -Recurse -Force
Copy-Item -Path "HKCU:$_" -Destination "HKU:.DEFAULT\$_" -Recurse -Force
}
Remove-PSDrive HKU
# set the timezone.
# use Get-TimeZone -ListAvailable to list the available timezone ids.
Set-TimeZone -Id 'GMT Standard Time'
# show window content while dragging.
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name DragFullWindows -Value 1
# show hidden files.
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -Value 1
# show protected operating system files.
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowSuperHidden -Value 1
# show file extensions.
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideFileExt -Value 0
# cleanup the taskbar by removing the existing buttons and unpinning all applications; once the user logs on.
# NB the shell executes these RunOnce commands about ~10s after the user logs on.
[IO.File]::WriteAllText(
"$env:USERPROFILE\ConfigureDesktop.ps1",
@'
# unpin all applications from the taskbar.
# NB this can only be done in a logged on session.
$pinnedTaskbarPath = "$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
(New-Object -Com Shell.Application).NameSpace($pinnedTaskbarPath).Items() `
| ForEach-Object {
$unpinVerb = $_.Verbs() | Where-Object { $_.Name -eq 'Unpin from tas&kbar' }
if ($unpinVerb) {
$unpinVerb.DoIt()
} else {
$shortcut = (New-Object -Com WScript.Shell).CreateShortcut($_.Path)
if (!$shortcut.TargetPath -and ($shortcut.IconLocation -eq '%windir%\explorer.exe,0')) {
Remove-Item -Force $_.Path
}
}
}
Get-Item HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband `
| Set-ItemProperty -Name Favorites -Value 0xff `
| Set-ItemProperty -Name FavoritesResolve -Value 0xff `
| Set-ItemProperty -Name FavoritesVersion -Value 3 `
| Set-ItemProperty -Name FavoritesChanges -Value 1 `
| Set-ItemProperty -Name FavoritesRemovedChanges -Value 1
# hide the search button.
Set-ItemProperty -Path HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -Value 0
# hide the task view button.
Set-ItemProperty -Path HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -Value 0
# never combine the taskbar buttons.
# possibe values:
# 0: always combine and hide labels (default)
# 1: combine when taskbar is full
# 2: never combine
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarGlomLevel -Value 2
# remove default or uneeded files.
@(
"$env:USERPROFILE\Desktop\desktop.ini"
"$env:USERPROFILE\Desktop\*.lnk"
"$env:USERPROFILE\Desktop\*.url"
"$env:PUBLIC\Desktop\desktop.ini"
"$env:PUBLIC\Desktop\*.lnk"
"$env:PUBLIC\Desktop\*.url"
) | Remove-Item -Force
# execute hooks.
Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1
Get-ChildItem "$PSScriptRoot\ConfigureDesktop-*.ps1" `
| Sort-Object -Property Name `
| ForEach-Object { &$_ }
# restart explorer to apply the changed settings.
(Get-Process explorer).Kill()
'@)
New-Item -Path HKCU:Software\Microsoft\Windows\CurrentVersion\RunOnce -Force `
| New-ItemProperty -Name ConfigureDesktop -Value 'PowerShell -WindowStyle Hidden -File "%USERPROFILE%\ConfigureDesktop.ps1"' -PropertyType ExpandString `
| Out-Null
# set default Explorer location to This PC.
Set-ItemProperty -Path HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name LaunchTo -Value 1
# display full path in the title bar.
New-Item -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState -Force `
| New-ItemProperty -Name FullPath -Value 1 -PropertyType DWORD `
| Out-Null
# install Google Chrome.
# see https://www.chromium.org/administrators/configuring-other-preferences
choco install -y --ignore-checksums googlechrome
$chromeLocation = 'C:\Program Files\Google\Chrome\Application'
cp -Force GoogleChrome-external_extensions.json (Resolve-Path "$chromeLocation\*\default_apps\external_extensions.json")
cp -Force GoogleChrome-master_preferences.json "$chromeLocation\master_preferences"
cp -Force GoogleChrome-master_bookmarks.html "$chromeLocation\master_bookmarks.html"
# set the default browser.
choco install -y SetDefaultBrowser
SetDefaultBrowser HKLM "Google Chrome"
# install useful applications.
choco install -y 7zip
choco install -y notepad3
choco install -y vscode
choco install -y carbon
choco install -y nssm