Guest User

windowsPostInstall.ps1

a guest
Jan 9th, 2026
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. #### START ELEVATE TO ADMIN #####
  2. param(
  3. [Parameter(Mandatory=$false)]
  4. [switch]$shouldAssumeToBeElevated,
  5.  
  6. [Parameter(Mandatory=$false)]
  7. [String]$workingDirOverride
  8. )
  9.  
  10. # If parameter is not set, we are propably in non-admin execution. We set it to the current working directory so that
  11. # the working directory of the elevated execution of this script is the current working directory
  12. if(-not($PSBoundParameters.ContainsKey('workingDirOverride')))
  13. {
  14. $workingDirOverride = (Get-Location).Path
  15. }
  16.  
  17. function Test-Admin {
  18. $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
  19. $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
  20. }
  21.  
  22. # If we are in a non-admin execution. Execute this script as admin
  23. if ((Test-Admin) -eq $false) {
  24. if ($shouldAssumeToBeElevated) {
  25. Write-Output "Elevating did not work :("
  26.  
  27. } else {
  28. # vvvvv add `-noexit` here for better debugging vvvvv
  29. Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -file "{0}" -shouldAssumeToBeElevated -workingDirOverride "{1}"' -f ($myinvocation.MyCommand.Definition, "$workingDirOverride"))
  30. }
  31. exit
  32. }
  33.  
  34. Set-Location "$workingDirOverride"
  35. ##### END ELEVATE TO ADMIN #####
  36.  
  37. # Add actual commands to be executed in elevated mode here:
  38. Write-Output "I got executed in an admin PowerShell"
  39.  
  40. Write-Host "Installing NuGet MinimumVersion 2.8.5.201"
  41. Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
  42.  
  43. Write-Host "Installing PowerShell Windows Update Module"
  44. Install-Module PSWindowsUpdate -Force
  45. Import-Module PSWindowsUpdate
  46.  
  47.  
  48. # Set Computer And User Language
  49. $Lang = "sv-SE"
  50.  
  51. Write-Host "Installing Language Pack for: $Lang"
  52. Install-Language -CopyToSettings -Language $Lang -ExcludeFeatures
  53. Write-Host "Installing Language Pack for: $Lang completed."
  54.  
  55. Write-Host "Setting Windows Preferred UI Language: $Lang"
  56. Set-SystemPreferredUILanguage -Language $Lang
  57. Write-Host "Windows override language: $Lang"
  58. Set-WinUILanguageOverride -Language $Lang
  59. Write-Host "Setting Windows System Locale to $Lang"
  60. Set-WinSystemLocale $Lang
  61. Write-Host "Setting WinUserLanguageList to $Lang"
  62. Set-WinUserLanguageList $Lang -Force
  63.  
  64. #Windows Update
  65. Write-Host "Windows Update.."
  66. Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -IgnoreReboot -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
  67.  
  68.  
  69.  
  70. # Set Default password & No password expiring
  71.  
  72. $Username="default"
  73. $PassRaw="default"
  74. $Password= ConvertTo-SecureString $PassRaw -AsPlainText -Force
  75.  
  76. Set-LocalUser -Name $Username -Password $Password
  77. Set-LocalUser -Name $Username -PasswordNeverExpires $true
  78.  
  79. # Set automatic logon for default user
  80. #autologon $Username $Env:COMPUTERNAME $Password
  81. $dir = (Get-Item .).FullName
  82. $prg = "$dir\Autologon.exe"
  83. Write-Host "AutoLogon exe: $prg"
  84. Test-Path -Path $prg
  85. Start-Process -FilePath "$dir\Autologon.exe" -ArgumentList "$Username $Env:COMPUTERNAME $PassRaw /accepteula" -Wait
  86.  
  87. #$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
  88. #Set-ItemProperty $RegistryPath 'AutoAdminLogon' -Value "1" -Type String
  89. #Set-ItemProperty $RegistryPath 'DefaultUsername' -Value "$Username" -type String
  90. #Set-ItemProperty $RegistryPath 'DefaultPassword' -Value "$Password" -type String
  91.  
  92.  
  93. # Install winget
  94. Install-Script -Name winget-install -Force
  95. winget-install
  96. winget-install -CheckForUpdate
  97.  
  98. # Install usefull programs
  99. Write-Host "Installing 7-Zip"
  100. "Y" | winget install -e --id 7zip.7zip --silent --accept-source-agreements --accept-package-agreements
  101.  
  102. #Write-Host "Installing Foxit PDF Reader"
  103. #"Y" | winget install -e --id Foxit.FoxitReader --silent --accept-source-agreements --accept-package-agreements
  104.  
  105.  
  106. Write-Host "Setting Power Plan to balanced!"
  107. powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e
  108. powercfg /change monitor-timeout-ac 0
  109. powercfg /change standby-timeout-ac 0
  110.  
  111. Write-Host "Removing Meet Now"
  112. Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "HideSCAMeetNow" -Value 1
  113.  
  114.  
  115. Write-Host "Remove 3D Viewer"
  116. Get-AppxPackage Microsoft.Microsoft3DViewer -AllUsers | Remove-AppxPackage
  117.  
  118. Write-Host "Remove Alarms & Clock"
  119. Get-AppxPackage Microsoft.WindowsAlarms -AllUsers | Remove-AppxPackage
  120.  
  121. Write-Host "Remove Camera"
  122. Get-AppxPackage Microsoft.WindowsCamera -AllUsers | Remove-AppxPackage
  123.  
  124. Write-Host "Remove Feedback Hub"
  125. Get-AppxPackage Microsoft.WindowsFeedbackHub -AllUsers | Remove-AppxPackage
  126.  
  127. Write-Host "Remove Groove Music"
  128. Get-AppxPackage Microsoft.ZuneMusic -AllUsers | Remove-AppxPackage
  129.  
  130. Write-Host "Remove Mail and Calendar"
  131. Get-AppxPackage microsoft.windowscommunicationsapps -AllUsers | Remove-AppxPackage
  132.  
  133. Write-Host "Remove Maps"
  134. Get-AppxPackage Microsoft.WindowsMaps -AllUsers | Remove-AppxPackage
  135.  
  136. Write-Host "Remove Microsoft Solitaire Collection"
  137. Get-AppxPackage Microsoft.MicrosoftSolitaireCollection -AllUsers | Remove-AppxPackage
  138.  
  139. Write-Host "Remove Mixed Reality Portal"
  140. Get-AppxPackage Microsoft.MixedReality.Portal -AllUsers | Remove-AppxPackage
  141.  
  142. Write-Host "Remove Groove music"
  143. Get-AppxPackage Microsoft.ZuneMusic -AllUsers | Remove-AppxPackage
  144.  
  145. Write-Host "Remove Xbox and Xbox Game Bar apps"
  146. Get-AppxPackage Microsoft.XboxApp -AllUsers | Remove-AppxPackage
  147. Get-AppxPackage Microsoft.XboxGamingOverlay -AllUsers | Remove-AppxPackage
  148.  
  149. Write-Host "Remove Movies & TV"
  150. Get-AppxPackage Microsoft.ZuneVideo | Remove-AppxPackage
  151.  
  152. Write-Host 'Removing Cortana from system'
  153. Get-AppxPackage -allusers Microsoft.549981C3F5F10 | Remove-AppxPackage
  154.  
  155. Write-Host 'Removing News Widget'
  156. Get-AppxPackage -AllUsers MicrosoftWindows.Client.WebExperience |
  157. Remove-AppxPackage -AllUsers
  158.  
  159. Write-Host 'Removing News Weather App'
  160. Get-AppxPackage Microsoft.BingWeather | Remove-AppxPackage
  161. #Disable News and Interests
  162. Reg Add "$reglocation\Software\Microsoft\Windows\CurrentVersion\Feeds" /T REG_DWORD /V "ShellFeedsTaskbarViewMode" /D 2 /F
  163.  
  164.  
  165. #Write-Host 'Disabling Websearch in start menu'
  166. #Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name "BingSearchEnabled" -Value 1 -Type DWord
  167. #if( -not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer)){
  168. #New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer
  169. #}
  170. #Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name "DisableSearchBoxSuggestions" -Value 1 -Type DWORD
  171. #
  172. #Write-Host 'Disabling Cortana'
  173. #Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name "AllowCortana " -Value 0 -Type DWord
  174. #if( -not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer)){
  175. #New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer
  176. #}
  177. #Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name "AllowCortana " -Value 0 -Type DWORD
  178.  
  179.  
  180. Write-Host 'Restarting the computer in 30 seconds'
  181.  
  182. #Add-Type -AssemblyName PresentationFramework
  183. #[System.Windows.MessageBox]::Show('The computer will restart in 5 minutes. Please save your work.', 'Restart Warning', 'OK', 'Warning')
  184. Start-Sleep -Seconds 30
  185. Restart-Computer
  186.  
  187. Restart-Computer -Force
  188.  
  189.  
  190.  
Advertisement
Add Comment
Please, Sign In to add comment