-
-
Save jenyayel/971c220438e50809073785caf856a7e0 to your computer and use it in GitHub Desktop.
(In Progress) PowerShell Script I use to customize my machines in the same way for privacy, search, UI, etc.
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
export CLICOLOR=1 | |
source ~/.git-completion.sh | |
PS1='\[\033[37m\]\W\[\033[0m\]$(__git_ps1 " (\[\033[35m\]%s\[\033[0m\])") \$ ' | |
GIT_PS1_SHOWDIRTYSTATE=1 | |
GIT_PS1_SHOWSTASHSTATE=1 | |
GIT_PS1_SHOWUNTRACKEDFILES=1 | |
GIT_PS1_SHOWUPSTREAM="auto" |
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
# Enable mouse control (clickable windows, panes, resizable panes) | |
set -g mouse on | |
set -g default-terminal "screen-256color" |
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
function Set-RegValue { | |
param( | |
[Parameter(Mandatory=$true)] | |
[string] | |
$path, | |
[Parameter(Mandatory=$true)] | |
[string] | |
$name, | |
[Parameter(Mandatory=$true)] | |
[int32] | |
$value | |
) | |
If (-Not (Test-Path $path)) { | |
New-Item -Path $path | Out-Null | |
} | |
Set-ItemProperty -Path $path -Name $name -Type Dword -Value $value | |
} | |
function Write-Step { | |
param( | |
[Parameter(Mandatory=$true)] | |
[string] | |
$stepName | |
) | |
$host.ui.rawui.BackgroundColor = $OrigBgColor | |
$host.ui.rawui.ForegroundColor = $OrigFgColor | |
Write-Host "`n* Starting '$stepName'" | |
Write-Host "*************************************************" | |
} | |
function Set-PrivacySettings { | |
Write-Step "Privacy Settings" | |
# Privacy: Let apps use my advertising ID: Disable | |
Set-RegValue "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo" "Enabled" 0 | |
# Privacy: SmartScreen Filter for Store Apps: Disable | |
Set-RegValue "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppHost" "EnableWebContentEvaluation" 0 | |
# WiFi Sense: HotSpot Sharing: Disable | |
Set-RegValue "HKLM:\Software\Microsoft\PolicyManager\default\WiFi\AllowWiFiHotSpotReporting" "value" 0 | |
# WiFi Sense: Shared HotSpot Auto-Connect: Disable | |
Set-RegValue "HKLM:\Software\Microsoft\PolicyManager\default\WiFi\AllowAutoConnectToWiFiSenseHotspots" "value" 0 | |
# Start Menu: Disable Bing Search Results | |
Set-RegValue "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" "BingSearchEnabled" 0 | |
# Disable Telemetry | |
Set-RegValue "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" "AllowTelemetry" 0 | |
Get-Service DiagTrack, Dmwappushservice | Stop-Service | Set-Service -StartupType Disabled | |
} | |
function Set-UIPreferences { | |
Write-Step "UI Preferences" | |
# Change Explorer home screen back to "This PC" | |
Set-RegValue "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" "LaunchTo" 1 | |
# Disable Quick Access: Recent Files | |
Set-RegValue "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" "ShowRecent" 0 | |
# Disable Quick Access: Frequent Folders | |
Set-RegValue "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" "ShowFrequent" 0 | |
# Disable the Lock Screen (the one before password prompt - to prevent dropping the first character) | |
Set-RegValue "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" "NoLockScreen" 1 | |
# Remove Cortana search from taskbar | |
Set-RegValue "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" "SearchboxTaskbarMode" 0 | |
# Dark Theme for Windows | |
Set-RegValue "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" "AppsUseLightTheme" 0 | |
Set-RegValue "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" "AppsUseLightTheme" 0 | |
} | |
function Remove-MetroApps { | |
Write-Step "Windows Store Apps" | |
$apps = @( | |
"king.com.CandyCrushSodaSaga", | |
"Microsoft.WindowsAlarms", | |
"Microsoft.BingWeather", | |
"Microsoft.BingNews", | |
"Microsoft.BingSports", | |
"Microsoft.BingFinance", | |
"Microsoft.XboxApp", | |
"Microsoft.WindowsPhone", | |
"Microsoft.MicrosoftSolitaireCollection", | |
"Microsoft.People", | |
"Microsoft.ZuneMusic", | |
"Microsoft.ZuneVideo", | |
"Microsoft.Windows.Photos", | |
"Microsoft.WindowsSoundRecorder", | |
"microsoft.windowscommunicationsapps", | |
"Microsoft.SkypeApp", | |
"Microsoft.WindowsCamera", | |
"Microsoft.Wallet", | |
"Microsoft.MicrosoftStickyNotes", | |
"Microsoft.GetHelp", | |
"A278AB0D.DisneyMagicKingdoms", | |
"A278AB0D.MarchofEmpires", | |
"Microsoft.Getstarted", | |
"Microsoft.WindowsMaps", | |
"Microsoft.Messaging", | |
"Microsoft.XboxSpeechToTextOverlay", | |
"Microsoft.MicrosoftOfficeHub") | |
Foreach ($appName in $apps) { | |
$app = Get-AppxPackage $appName | |
if ($app -ne $null) { | |
Try { | |
Remove-AppxPackage $app | |
Write-Host "Removed $appName" | |
} | |
Catch { | |
Write-Warning "Failed to remove $appName due to ""$_""`n" | |
} | |
} | |
} | |
} | |
function Set-WindowsFeatures { | |
Write-Step "Windows Features" | |
$features = @( | |
@("Microsoft-Windows-Subsystem-Linux", $true), | |
@("Microsoft-Hyper-V-All", $true), | |
@("TelnetClient", $true), | |
@("WindowsMediaPlayer", $false), | |
@("MediaPlayback", $false)) | |
$restart = $false | |
Foreach ($feature in $features) { | |
Try { | |
If ($feature[1]) { | |
$restart = $restart -or (Enable-WindowsOptionalFeature -Online -FeatureName $feature[0] -All -NoRestart).RestartNeeded | |
} | |
Else { | |
$restart = $restart -or (Disable-WindowsOptionalFeature -Online -FeatureName $feature[0] -NoRestart).RestartNeeded | |
} | |
} | |
Catch { | |
Write-Warning ("Failed to " + (&{If($feature[1]) {"enable"} Else {"disable"}}) + "$feature due to ""$_""`n") | |
} | |
} | |
return $restart | |
} | |
function Set-CoreConfigurations { | |
param( | |
[Parameter] | |
[string] | |
$computerName | |
) | |
Write-Step "Core Configurations" | |
# Change Windows Updates to "Notify to schedule restart" | |
Set-RegValue "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" "UxOption" 1 | |
# Disable P2P Update downlods outside of local network | |
Set-RegValue "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" "DODownloadMode" 1 | |
Set-RegValue "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization" "SystemSettingsDownloadMode" 3 | |
# Rename PC | |
If ($computerName -ne $null -and $env:computername -ne $computerName){ | |
Rename-Computer -NewName $computerName -Force -Passthru | |
return $true | |
} | |
return $false | |
} | |
function Set-ChocoAndPackages { | |
Write-Step "Chocolatey and packages" | |
# Install Chocolatey this requires admin rights | |
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString("https://chocolatey.org/install.ps1")) | |
# reload shell | |
& $profile | |
# Install packages | |
choco install googlechrome -y | |
choco install firefox -y | |
choco install git.install -y | |
choco install docker -y | |
choco install javaruntime -y | |
choco install dbeaver -y | |
choco install keeweb -y | |
choco install visualstudiocode -y | |
choco install whatsapp -y | |
choco install vlc -y | |
choco install skype -y | |
} | |
function Set-PowerShellPreferences { | |
Write-Step "Powershell preferences" | |
Set-PSRepository -InstallationPolicy Trusted -Name PSGallery | |
# Autocomplition for Git | |
Install-Module posh-git -Scope CurrentUser | |
Add-Content -LiteralPath $profile -Value "`nImport-Module posh-git" -Encoding UTF8 | |
# Autocomplition for Docker | |
Install-Module posh-docker -Scope CurrentUser | |
Add-Content -LiteralPath $profile -Value "`nImport-Module posh-docker" -Encoding UTF8 | |
# https://github.com/dahlbyk/posh-git/issues/583#issuecomment-402711469 | |
Add-Content -LiteralPath $profile -Value "[System.Environment]::SetEnvironmentVariable(`"SSH_AUTH_SOCK`", $null)" -Encoding UTF8 | |
Add-Content -LiteralPath $profile -Value "[System.Environment]::SetEnvironmentVariable(`"SSH_AGENT_PID`", $null)" -Encoding UTF8 | |
} | |
function IsAdmin { | |
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) | |
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
} | |
function Main { | |
If (-Not (IsAdmin)) { | |
Write-Warning "You are not running from an elevated command shell" | |
exit 1 | |
} | |
# stop on first error | |
$ErrorActionPreference = "Stop" | |
# store original shell colors | |
$OrigBgColor = $host.ui.rawui.BackgroundColor | |
$OrigFgColor = $host.ui.rawui.ForegroundColor | |
# Add PowerShell profile file to current user | |
if (-Not (Test-Path $profile)) { | |
New-Item $profile -ItemType File -Force > $null | |
Add-Content -LiteralPath $profile -Value "`n# Autogenerated by setup script" -Encoding UTF8 | |
} | |
$restartRequired = $false | |
Set-PrivacySettings # TODO: check if at least one key was changed | |
Set-UIPreferences | |
Remove-MetroApps | |
$restartRequired = $restartRequired -or (Set-WindowsFeatures) | |
$restartRequired = $restartRequired -or (Set-CoreConfigurations) | |
Set-ChocoAndPackages | |
Set-PowerShellPreferences | |
If ($restartRequired){ | |
Write-Host "`n`n To finish configurations the PC must be rebooted. Hit an key to continue..." | |
$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') | Out-Null | |
Restart-Computer | |
} | |
Else { | |
Write-Host "`n`n Successfully finished" | |
} | |
} | |
Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment