Skip to content

Commit 022407c

Browse files
authored
Windows11 update (#21)
* Configure Touchpad * Fix repo not found in VSCode * Clean up apps not used * Include VS2022 * Clone a user's repositories * Configure PowerShell by default * Better Azure CLI extension management
1 parent ea809cc commit 022407c

File tree

6 files changed

+135
-23
lines changed

6 files changed

+135
-23
lines changed

common/common_setup.ps1

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ param (
1111
[parameter(Mandatory=$false)][switch]$NoPackages=$false
1212
)
1313

14+
$scriptDirectory = (Split-Path -Parent -Path $MyInvocation.MyCommand.Path)
15+
16+
# Load Functions
17+
. (Join-Path (Join-Path $scriptDirectory functions) functions.ps1)
18+
1419
# Set up PowerShell Core (modules, profile)
15-
& (Join-Path (Split-Path -parent -Path $MyInvocation.MyCommand.Path) "bootstrap_pwsh.ps1") -NoPackages:$NoPackages
20+
& (Join-Path $scriptDirectory "bootstrap_pwsh.ps1") -NoPackages:$NoPackages
1621

1722
# Configure PowerShell as default shell on Linux & macOS
1823
if ($IsLinux -or $IsMacos) {
@@ -28,7 +33,7 @@ if ($IsLinux -or $IsMacos) {
2833
}
2934

3035
# Set up dotfiles
31-
& (Join-Path (Split-Path -parent -Path $MyInvocation.MyCommand.Path) "create_dotfiles.ps1")
36+
& (Join-Path $scriptDirectory "create_dotfiles.ps1")
3237

3338
# Configure Git
3439
$settingsFile = (Join-Path $PSScriptRoot settings.json)
@@ -52,8 +57,21 @@ if (-not $NoPackages) {
5257
# Azure CLI extensions
5358
if (Get-Command az -ErrorAction SilentlyContinue) {
5459
Write-Host "`nUpdating Azure CLI extensions..."
55-
az extension add -n azure-devops --upgrade -y 2>&1
56-
az extension add -n azure-firewall --upgrade -y 2>&1
57-
az extension add -n resource-graph --upgrade -y 2>&1
60+
az extension list --query "[].name" -o tsv | Set-Variable azExtensions
61+
foreach ($azExtension in $azExtensions) {
62+
Write-Host "Updating Azure CLI extension '$azExtension'..."
63+
az extension update -n $azExtension --only-show-errors
64+
}
65+
66+
Compare-Object -ReferenceObject $azExtensions `
67+
-DifferenceObject @('azure-devops', `
68+
'azure-firewall', `
69+
'resource-graph') | Where-Object -Property SideIndicator -eq '=>' `
70+
| ForEach-Object {
71+
Write-Host "Adding Azure CLI extension '$($_.InputObject)'..."
72+
az extension add -n $_.InputObject --only-show-errors
73+
}
5874
}
59-
}
75+
}
76+
77+
Clone-GitHubRepositories

common/functions/functions.ps1

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,73 @@ function AddorUpdateModule (
5050
}
5151
}
5252
}
53+
54+
function Clone-GitHubRepositories (
55+
[parameter(Mandatory=$false)][string]$User,
56+
[parameter(Mandatory=$false)][switch]$OpenFolder
57+
) {
58+
Write-Host ""
59+
if (!(Get-Command git -ErrorAction SilentlyContinue)) {
60+
Write-Warning "git not found, no repositories to clone"
61+
return
62+
}
63+
64+
# Fugure out who the GH user is
65+
if (!$User) { # User of the cloned repo
66+
$ghUser = ((git config --get remote.origin.url) -replace '^https://(?<host>[\w\.]+)/(?<user>\w+)/([\w\-]+)(\.git)?$' , '${user}')
67+
if ($ghUser) {
68+
$User = $ghUser
69+
}
70+
}
71+
if (!$User -and (Get-Command gh -ErrorAction SilentlyContinue)) { # Logged-in GH user
72+
gh api user 2>$null | ConvertFrom-Json -AsHashtable | Set-Variable ghUserResponse
73+
$ghUser = $ghUserResponse["login"]
74+
if ($ghUser) {
75+
$User = $ghUser
76+
}
77+
}
78+
if (!$User) {
79+
Write-Warning "Unable to determine GitHub user name"
80+
return
81+
}
82+
83+
# Set repo root
84+
if ($IsWindows) {
85+
$repoRoot = "~\Source\GitHub\${User}"
86+
} else {
87+
$repoRoot = "~/src/github/${User}"
88+
}
89+
$repoRoot = (Resolve-Path $repoRoot).Path
90+
New-Item -ItemType Directory -Force -Path $repoRoot | Out-Null
91+
Push-Location $repoRoot
92+
93+
# Retrieve repositories for user
94+
Write-Host "Looking for GitHub repositories for user '${User}'..."
95+
Invoke-RestMethod https://api.github.com/users/${User}/repos | Set-Variable repos
96+
97+
# Clone repositories
98+
$printMessage = $true
99+
foreach ($repo in $repos) {
100+
Join-Path $repoRoot $repo.name | Set-Variable repoDirectory
101+
if (Test-Path $repoDirectory) {
102+
Write-Verbose "Repo '$($repo.html_url)' already exists locally in '$repoDirectory'"
103+
} else {
104+
if ($printMessage) {
105+
Write-Host "Cloning GitHub repositories for user '${User}' into '$repoRoot'..."
106+
$printMessage = $false
107+
}
108+
Write-Host "`nCloning '$($repo.html_url)' into '$repoDirectory'..."
109+
git clone https://github.com/${User}/$($repo.name)
110+
}
111+
}
112+
if ($printMessage) {
113+
Write-Host "Nothing (more) to clone for user '${User}'"
114+
}
115+
if ($OpenFolder) {
116+
Invoke-Item $repoRoot
117+
}
118+
}
119+
53120
function Import-InstalledModule (
54121
[parameter(Mandatory=$true)][string]$ModuleName
55122
) {
@@ -323,13 +390,14 @@ function LinkDirectory (
323390
if ($link.Target) {
324391
Write-Host "$($link.FullName) -> $($link.Target)"
325392
} else {
326-
Write-Host "$($link.FullName) already exists as directory" -ForegroundColor Yellow
393+
Write-Warning "$($link.FullName) already exists as directory"
327394
}
328395
}
329396
function LinkFile (
330397
[parameter(Mandatory=$true)][string]$File,
331398
[parameter(Mandatory=$true)][string]$SourceDirectory,
332-
[parameter(Mandatory=$true)][string]$TargetDirectory
399+
[parameter(Mandatory=$true)][string]$TargetDirectory,
400+
[parameter(Mandatory=$false)][switch]$ReplaceEmptyFile
333401
) {
334402
# Reverse
335403
$linkSource = $(Join-Path $TargetDirectory $File)
@@ -341,10 +409,16 @@ function LinkFile (
341409
} else {
342410
$link = Get-Item $linkSource -Force
343411
}
412+
413+
if ($ReplaceEmptyFile -and [String]::IsNullOrWhiteSpace((Get-Content $link.FullName))) {
414+
Write-Warning "Replacing empty file $($link.FullName)"
415+
Remove-Item $link.FullName -Force
416+
}
417+
344418
if ($link.Target) {
345419
Write-Host "$($link.FullName) -> $($link.Target)"
346420
} else {
347-
Write-Host "$($link.FullName) already exists as file" -ForegroundColor Yellow
421+
Write-Warning "$($link.FullName) already exists as file"
348422
}
349423
}
350424

windows/bootstrap_windows.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
param (
1616
[parameter(Mandatory=$false)][switch]$All=$false,
1717
[parameter(Mandatory=$false)][ValidateSet("Desktop", "Developer", "Minimal", "None")][string[]]$Packages=@("Minimal"),
18-
[parameter(Mandatory=$false)][bool]$PowerShell=$false,
18+
[parameter(Mandatory=$false)][bool]$PowerShell=$true,
1919
[parameter(Mandatory=$false)][bool]$Settings=$true,
2020
[parameter(Mandatory=$false)][string]$Repository="https://github.com/geekzter/bootstrap-os",
2121
[parameter(Mandatory=$false)][string]$Branch=$(git -C $PSScriptRoot rev-parse --abbrev-ref HEAD 2>$null)
@@ -89,7 +89,8 @@ if ($gitPath) {
8989
if (!(Test-Path $bootstrapDirectory)) {
9090
Set-Location $repoDirectory
9191
Write-Host "Cloning $Repository into $repoDirectory..."
92-
git clone $Repository
92+
git clone $Repository
93+
git config --global --add safe.directory $bootstrapDirectory\*
9394
} else {
9495
# git update if repo already exists
9596
Set-Location $bootstrapDirectory
@@ -109,7 +110,7 @@ if (!(Test-Path $windowsBootstrapDirectory)) {
109110

110111
# Invoke next stage
111112
$userExecutionPolicy = Get-ExecutionPolicy -Scope CurrentUser
112-
if (($userExecutionPolicy -ieq "AllSigned") -or ($userExecutionPolicy -ieq "Undefined")) {
113+
if (($userExecutionPolicy -ieq "AllSigned") -or ($userExecutionPolicy -ieq "Restricted") -or ($userExecutionPolicy -ieq "Undefined")) {
113114
if ((Get-ExecutionPolicy) -ine "ByPass") {
114115
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
115116
}

windows/bootstrap_windows2.ps1

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
param (
66
[parameter(Mandatory=$false)][switch]$All=$false,
77
[parameter(Mandatory=$false)][ValidateSet("Desktop", "Developer", "Minimal", "None")][string[]]$Packages=@("Minimal"),
8-
[parameter(Mandatory=$false)][bool]$PowerShell=$false,
8+
[parameter(Mandatory=$false)][bool]$PowerShell=$true,
99
[parameter(Mandatory=$false)][bool]$Settings=$true
1010
)
1111

@@ -145,8 +145,8 @@ if ($All -or $minimal) {
145145
Get-AppxPackage -AllUsers "Microsoft.StorePurchaseApp" | ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
146146
Get-AppxPackage -AllUsers "Microsoft.WindowsStore" | ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
147147

148-
# Store Apps
149-
Get-AppxPackage -AllUsers "Microsoft.MicrosoftOfficeHub" | ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
148+
# Add Store Apps
149+
# Get-AppxPackage -AllUsers "Microsoft.MicrosoftOfficeHub" | ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
150150
Get-AppxPackage -AllUsers "Microsoft.MicrosoftPowerBIForWindows" | ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
151151
Get-AppxPackage -AllUsers "Microsoft.MSPaint" | ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
152152
Get-AppxPackage -AllUsers "Microsoft.NetworkSpeedTest" | ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
@@ -156,6 +156,19 @@ if ($All -or $minimal) {
156156
Get-AppxPackage -AllUsers "Microsoft.RemoteDesktop" | ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
157157
Get-AppxPackage -AllUsers "Microsoft.Whiteboard" | ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
158158

159+
# Remove bloatware
160+
Get-AppxPackage -AllUsers *Amazon* | Remove-AppxPackage
161+
Get-AppxPackage -AllUsers *Bing* | Remove-AppxPackage
162+
Get-AppxPackage -AllUsers *Bytedance* | Remove-AppxPackage
163+
Get-AppxPackage -AllUsers *Clipchamp* | Remove-AppxPackage
164+
Get-AppxPackage -AllUsers *Disney* | Remove-AppxPackage
165+
Get-AppxPackage -AllUsers *Facebook* | Remove-AppxPackage
166+
Get-AppxPackage -AllUsers *Instagram* | Remove-AppxPackage
167+
Get-AppxPackage -AllUsers Microsoft.Advertising* | Remove-AppxPackage
168+
Get-AppxPackage -AllUsers Microsoft.GamingApp* | Remove-AppxPackage
169+
Get-AppxPackage -AllUsers Microsoft.MicrosoftSolitaireCollection* | Remove-AppxPackage
170+
Get-AppxPackage -AllUsers *Zune* | Remove-AppxPackage
171+
159172
UpdateStoreApps
160173
}
161174

@@ -250,7 +263,7 @@ if ($All -or $Settings) {
250263
Set-WinUserLanguageList $config.UserLanguage -Force
251264
}
252265
} else {
253-
Write-Host "Settings file $settingsFile not found, skipping personalization"
266+
Write-Warning "Settings file $settingsFile not found, skipping personalization"
254267
}
255268

256269
# Disable autostarts
@@ -316,12 +329,17 @@ if ($All -or $Settings) {
316329
# Set up application settings
317330
& (Join-Path (Split-Path -parent -Path $MyInvocation.MyCommand.Path) "create_settings.ps1")
318331

319-
# Set UAC for Desktop OS
332+
# Desktop OS
320333
if ($osType -ieq "Client") {
334+
# UAC
321335
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "ConsentPromptBehaviorAdmin" -Type DWord -Value 5
322336
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "FilterAdministratorToken" -Type DWord -Value 1
323337
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "EnableLUA" -Type DWord -Value 1
324338
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "PromptOnSecureDesktop" -Type DWord -Value 1
339+
340+
# Configure Touchpad to replicate Mac behavior
341+
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PrecisionTouchPad" -Name "RightClickZoneEnabled" -Type DWord -Value 0
342+
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PrecisionTouchPad" -Name "ScrollDirection" -Type DWord -Value 0
325343
}
326344

327345
# Import GPO

windows/chocolatey-desktop.config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
<!-- package id="dropbox" / -->
55
<package id="firefox" />
66
<package id="googlechrome" />
7+
<!-- package id="icloud" / -->
78
<package id="keepassxc" />
8-
<!-- package id="microsoft-edge" /-->
9+
<!-- package id="microsoft-edge" / -->
910
<!-- package id="microsoft-teams" /-->
1011
<!-- package id="office365proplus" /-->
1112
<package id="paint.net" />
1213
<package id="powerbi" />
13-
<package id="powertoys" />
14+
<!-- package id="powertoys" / -->
1415
<package id="syspin" />
1516
<package id="winsecuritybaseline" />
1617
</packages>

windows/chocolatey-developer.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
<package id="vscode-pull-request-github" />
8787
<package id="vscode-powershell" />
8888
<package id="vscode-yaml" />
89-
<!-- package id="visualstudio2022enterprise" /-->
90-
<!-- package id="visualstudio2022-workload-azure" /-->
91-
<!-- package id="visualstudio2022-workload-netcrossplat" /-->
92-
<!-- package id="visualstudio2022-workload-netweb" /-->
89+
<package id="visualstudio2022enterprise" />
90+
<package id="visualstudio2022-workload-azure" />
91+
<package id="visualstudio2022-workload-netcrossplat" />
92+
<package id="visualstudio2022-workload-netweb" />
9393
<package id="wget" />
9494
<package id="windows-admin-center" />
9595
<!-- package id="wireshark" /-->

0 commit comments

Comments
 (0)