Advertisement
timsstuff

Set-MyDesktopSettings.ps1

Jul 28th, 2022 (edited)
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Set-Reg {
  2.     param (
  3.         [string]$key,
  4.         [string]$name,
  5.         [string]$value,
  6.         [string]$type
  7.     )
  8.  
  9.     If ((Test-Path -Path $key) -eq $false) {
  10.         New-Item -Path $key -Force
  11.     }
  12.     $k = Get-Item -Path $key
  13.     If ($null -eq $k.GetValue($name)) {
  14.         New-ItemProperty -Path $key -Name $name -Value $value -PropertyType $type
  15.     }
  16.     else {
  17.         Set-ItemProperty -Path $key -Name $name -Value $value
  18.     }
  19. }
  20.  
  21. $Admin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
  22. If (!$Admin) {
  23.     Write-Host 'Running as non-admin, some settings won''t be applied. Please run this script with Admin privileges to apply system-wide settings.' -ForegroundColor Yellow
  24. }
  25.  
  26. #Set execution policy
  27. Set-ExecutionPolicy bypass -Scope CurrentUser -Force -Confirm:$false
  28.  
  29. #Set Windows Explorer settings
  30. $key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\'
  31. Set-Reg -key $key -name 'HideFileExt' -value 0 -type 'DWord'
  32. Set-Reg -key $key -name 'NavPaneShowAllFolders' -value 1 -type 'DWord'
  33. Set-Reg -key $key -name 'NavPaneExpandToCurrentFolder' -value 1 -type 'DWord'
  34. Set-Reg -key $key -name 'Start_NotifyNewApps' -value 0 -type 'DWord'
  35. Set-Reg -key $key -name 'Start_ShowMyComputer' -value 2 -type 'DWord'
  36. Set-Reg -key $key -name 'Start_ShowControlPanel' -value 2 -type 'DWord'
  37. Set-Reg -key $key -name 'Start_ShowRun' -value 1 -type 'DWord'
  38. Set-Reg -key $key -name 'StartMenuAdminTools' -value 2 -type 'DWord'
  39. Set-Reg -key $key -name 'DontUsePowerShellOnWinx' -value 0 -type 'DWord'
  40.  
  41. #Fix Explorer white on white issue
  42. $key = 'HKCU:\Software\Microsoft\Windows\DWM'
  43. Set-Reg -key $key -name 'ColorPrevalence' -value 1 -type 'DWord'
  44. Set-Reg -key $key -name 'AccentColor' -value D3D3D3 -type 'DWord'
  45.  
  46. #Desktop Icons
  47. $key = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel'
  48. Set-Reg -key $key -name '{20D04FE0-3AEA-1069-A2D8-08002B30309D}' -value 0 -type 'DWord'
  49. Set-Reg -key $key -name '{645FF040-5081-101B-9F08-00AA002F954E}' -value 1 -type 'DWord'
  50. Set-Reg -key $key -name '{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}' -value 0 -type 'DWord'
  51. Set-Reg -key $key -name '{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}' -value 0 -type 'DWord'
  52.  
  53. #Set cmd settings
  54. $key = 'HKCU:\Console\'
  55. Set-Reg -key $key -name 'QuickEdit' -value 1 -type 'DWord'
  56. Set-Reg -key $key -name 'ScreenBufferSize' -value 196608120 -type 'DWord'
  57. Set-Reg -key $key -name 'WindowSize' -value (65536 * 180 + 40) -type 'DWord'
  58.  
  59. #Set IE defaults
  60. Set-Reg -key 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\' -name 'IEHarden' -value 0 -type 'DWord'
  61. Set-Reg -key 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\' -name 'WarnonZoneCrossing' -value 0 -type 'DWord'
  62. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'IE8TourShown' -value 1 -type 'DWord'
  63. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'IE8RunOncePerInstallCompleted' -value 1 -type 'DWord'
  64. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'IE8TourNoShow' -value 1 -type 'DWord'
  65. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'DisableFirstRunCustomize' -value 1 -type 'DWord'
  66. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'IE9TourShown' -value 1 -type 'DWord'
  67. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'IE10TourShown' -value 1 -type 'DWord'
  68. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'IE11TourShown' -value 1 -type 'DWord'
  69. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'RunOnceComplete' -value 1 -type 'DWord'
  70. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'RunOnceHasShown' -value 1 -type 'DWord'
  71. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'Friendly http errors' -value 'no' -type 'String'
  72. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'Check_Associations' -value 'no' -type 'String'
  73. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\TabbedBrowsing\' -name 'WarnOnclose' -value 0 -type 'DWord'
  74. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\TabbedBrowsing\' -name 'OpenInForeground' -value 1 -type 'DWord'
  75. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\TabbedBrowsing\' -name 'Groups' -value 0 -type 'DWord'
  76. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\TabbedBrowsing\' -name 'NewTabNextToCurrent' -value 1 -type 'DWord'
  77. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\TabbedBrowsing\' -name 'NewTabPageShow' -value 1 -type 'DWord'
  78. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\TabbedBrowsing\' -name 'ShortcutBehavior' -value 1 -type 'DWord'
  79. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\TabbedBrowsing\' -name 'ThumbnailBehavior' -value 0 -type 'DWord'
  80. Set-Reg -key 'HKCU:\Software\Microsoft\Internet Explorer\Main\' -name 'start page' -value 'http://www.google.com' -type 'String'
  81. Set-Reg -key 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\' -name 'ConfirmFileDelete' -value 1 -type 'DWord'
  82. Set-Reg -key 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage\' -name 'OpenAtLogon' -value 0 -type 'DWord'
  83. Set-Reg -key 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\' -name 'LaunchTo' -value 1 -type 'DWord'
  84.  
  85. if ($Admin) {
  86.     #Disable Loopback Check
  87.     Set-Reg -key 'HKLM:\System\CurrentControlSet\Control\Lsa' -name 'DisableLoopbackCheck' -value 1 -type 'Dword'
  88.  
  89.     #Set Print Spooler to manual startup
  90.     #Set-Service spooler -StartupType Manual
  91.  
  92.     Stop-Process -processname explorer -confirm:$false -Force
  93. }
  94.  
  95. If ($PSVersionTable.PSVersion.Major -ge 3) {
  96.     New-item -type file -force $profile
  97.     (Invoke-WebRequest 'https://pastebin.com/Q5bPNtZf').Content | Out-File $profile
  98. } else {
  99.     Try {
  100.         $wc = New-Object System.Net.WebClient
  101.         $wc.DownloadFile('https://pastebin.com/Q5bPNtZf', $profile)
  102.     }
  103.     Catch {
  104.         Write-Host "Could not download https://pastebin.com/Q5bPNtZf, please copy manually" -ForegroundColor Red
  105.     }
  106.  
  107.     $dlnew = Read-Host "Powershell version is old, download latest? (Will require reboot)"
  108.     if ($dlnew -eq "y") {
  109.         $osver = (Get-WmiObject -Class Win32_OperatingSystem).Caption
  110.         if ($osver -like "*Server 2008 R2*" -or $osver -like "*Windows 7*") {
  111.             Write-Host "$osver detected, redirecting to Powershell 5.1" -ForegroundColor Cyan
  112.             $IE = new-object -com internetexplorer.application
  113.             $IE.navigate2("https://www.microsoft.com/en-us/download/details.aspx?id=54616")
  114.             $IE.visible = $true
  115.         }
  116.     }
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement