Last active
January 20, 2025 10:28
-
-
Save TheGU/ef3c1f2ca1e578ce461186dde7fd606f to your computer and use it in GitHub Desktop.
Auto setup new win11 pc for development.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ============= | |
| # Run terminal as admin, then run 'powershell.exe -ExecutionPolicy Unrestricted' | |
| # to start powershell session in unrestricted mode | |
| # https://learn.microsoft.com/th-th/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4 | |
| if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit } | |
| # get all input parameter | |
| $computerName = Read-Host 'Change Computer Name from [' $env:COMPUTERNAME '] to (blank to skip) ' | |
| $monitorTimeout = Read-Host 'Set monitor timeout to __ second (blank to skip) ' | |
| $enableDevMode = Read-Host 'Enable Windows 11 dev mode (Y / N or blank to skip) ' | |
| $enableRemote = Read-Host 'Enable Remote Desktop (Y / N or blank to skip) ' | |
| # === Variable ================================================== | |
| # TODO: make it a check list for user to select | |
| $Apps = @( | |
| # Basic | |
| "googlechrome", | |
| "firefox", | |
| "7zip.install", | |
| "microsoft-teams-new-bootstrapper", | |
| "irfanview", # image viewer | |
| "googledrive", | |
| "cutepdf", # pdf editor | |
| "foxitreader", # pdf reader | |
| # Utils | |
| "obsidian", # notebook | |
| "notepadplusplus.install", # better notepad | |
| "keepassxc", # password manager | |
| "vlc", # video player | |
| "mpc-hc-clsid2", # video player | |
| "powertoys", # windows tools | |
| "obs-studio", # streaming | |
| "rustdesk", # remote desktop | |
| "calibre", # ebook management | |
| # "folder_size", # disk space inspect | |
| "treesizefree", # disk space inspect | |
| "cpu-z", # hw info | |
| "handbrake.install", # video encoder | |
| "qbittorrent", # torrent | |
| "tor-browser", # hidden web | |
| # Dev | |
| # "python", | |
| "putty", | |
| "git", | |
| "vscode", | |
| "sysinternals", | |
| "postman", # http test | |
| "httpie", # http test | |
| "beyondcompare", | |
| "github-desktop", | |
| "nodejs-lts", | |
| "docker-desktop", | |
| "figma", | |
| "sourcetree", | |
| #"virtualbox", | |
| "powershell-core") | |
| $uwpRubbishApps = @( | |
| "Microsoft.Microsoft3DViewer" | |
| "Microsoft.ZuneMusic" | |
| "Microsoft.ZuneVideo" | |
| "*549981C3F5F10*" | |
| "Microsoft.WindowsSoundRecorder" | |
| "Microsoft.PowerAutomateDesktop" | |
| "Microsoft.BingWeather" | |
| "Microsoft.BingNews" | |
| "king.com.CandyCrushSaga" | |
| "Microsoft.Messaging" | |
| "Microsoft.WindowsFeedbackHub" | |
| "Microsoft.MicrosoftOfficeHub" | |
| "Microsoft.MicrosoftSolitaireCollection" | |
| "4DF9E0F8.Netflix" | |
| "Microsoft.GetHelp" | |
| "Microsoft.People" | |
| "Microsoft.YourPhone" | |
| "MicrosoftTeams" | |
| "Microsoft.Getstarted" | |
| "Microsoft.Microsoft3DViewer" | |
| "Microsoft.WindowsMaps" | |
| "Microsoft.MixedReality.Portal" | |
| "Microsoft.SkypeApp") | |
| # === Gathering Fact ============================================ | |
| Write-Host "OS Info:" -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| Get-CimInstance Win32_OperatingSystem | Format-List Name, Version, InstallDate, OSArchitecture | |
| (Get-ItemProperty HKLM:\HARDWARE\DESCRIPTION\System\CentralProcessor\0\).ProcessorNameString | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| Write-Host "Set New Computer name:" -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| Write-Host "Current computer name: " $env:COMPUTERNAME | |
| if ((-not ([string]::IsNullOrEmpty($computerName))) -and ($computerName -ne $env:COMPUTERNAME)) { | |
| Write-Host "Renaming this computer to: " $computerName -ForegroundColor Yellow | |
| Rename-Computer -NewName $computerName | |
| } | |
| else { | |
| Write-Host "Skip Rename : same name or blank input" | |
| } | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| Write-Host "Disable Sleep on AC Power..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| if ($monitorTimeout) { | |
| Write-Host "monitor-timeout-ac " $monitorTimeout | |
| Powercfg /Change monitor-timeout-ac $monitorTimeout | |
| } | |
| Write-Host "standby-timeout-ac 0" | |
| Powercfg /Change standby-timeout-ac 0 | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| Write-Host "Add 'This PC' Desktop Icon..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| $thisPCIconRegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" | |
| $thisPCRegValname = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" | |
| $item = Get-ItemProperty -Path $thisPCIconRegPath -Name $thisPCRegValname -ErrorAction SilentlyContinue | |
| if ($item) { | |
| Set-ItemProperty -Path $thisPCIconRegPath -name $thisPCRegValname -Value 0 | |
| } | |
| else { | |
| New-ItemProperty -Path $thisPCIconRegPath -Name $thisPCRegValname -Value 0 -PropertyType DWORD | Out-Null | |
| } | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| # To list all appx packages: | |
| # Get-AppxPackage | Format-Table -Property Name,Version,PackageFullName | |
| Write-Host "Removing Unwanted preinstall Universal Windows Platform (UWP)..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| function Remove-UWP { | |
| param ( | |
| [string]$name | |
| ) | |
| Write-Host "Removing UWP $name..." -ForegroundColor Yellow | |
| Get-AppxPackage $name | Remove-AppxPackage | |
| Get-AppxPackage $name | Remove-AppxPackage -AllUsers | |
| } | |
| foreach ($uwp in $uwpRubbishApps) { | |
| # Write-Host "Removing ... " $uwp | |
| Remove-UWP $uwp | |
| } | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| Write-Host "Starting UWP apps to upgrade..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| $namespaceName = "root\cimv2\mdm\dmmap" | |
| $className = "MDM_EnterpriseModernAppManagement_AppManagement01" | |
| $wmiObj = Get-WmiObject -Namespace $namespaceName -Class $className | |
| Write-Host "Get-WmiObject -Namespace " $namespaceName "-Class" $className | |
| Write-Host $wmiObj ".UpdateScanMethod()" | |
| $result = $wmiObj.UpdateScanMethod() | |
| Write-Host "Result: " $result | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| Write-Host "Enable Windows 11 Developer Mode..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| if ($enableDevMode -eq "Y") { | |
| reg add "HKEY_LOCAL_MACHNE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1" | |
| } | |
| else { | |
| Write-Host "Skip" | |
| } | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| Write-Host "Enable Remote Desktop..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| if ($enableRemote -eq "Y") { | |
| Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\" -Name "fDenyTSConnections" -Value 0 | |
| Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\" -Name "UserAuthentication" -Value 1 | |
| Enable-NetFirewallRule -DisplayGroup "Remote Desktop" | |
| } | |
| else { | |
| Write-Host "Skip" | |
| } | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| Write-Host "Install Chocolately ..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| function CheckCommand($cmdname) { | |
| return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue) | |
| } | |
| if (CheckCommand -cmdname 'choco') { | |
| Write-Host "Choco is already installed, skip installation." | |
| } | |
| else { | |
| Write-Host "" | |
| Write-Host "Installing Chocolate for Windows..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) | |
| } | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| Write-Host "Installing Applications..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| foreach ($app in $Apps) { | |
| choco install $app -y | |
| } | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- | |
| Write-Host "Set the default terminal to Powershell core ..." -ForegroundColor Green | |
| Write-Host "------------------------------------" -ForegroundColor Green | |
| # Set the default terminal to PowerShell Core | |
| $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\AppModel\TerminalDefaultPorts" | |
| $regName = "DefaultTerminal" | |
| $regValue = "pwsh" | |
| # Check if PowerShell Core is installed | |
| if (Test-Path $regPath) { | |
| # Set the default terminal to PowerShell Core | |
| Set-ItemProperty -Path $regPath -Name $regName -Value $regValue | |
| Write-Host "Default terminal set to PowerShell Core." | |
| } else { | |
| Write-Host "PowerShell Core is not installed." | |
| } | |
| Write-Host "" | |
| # ----------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment