Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### START ELEVATE TO ADMIN #####
- param(
- [Parameter(Mandatory=$false)]
- [switch]$shouldAssumeToBeElevated,
- [Parameter(Mandatory=$false)]
- [String]$workingDirOverride
- )
- # If parameter is not set, we are propably in non-admin execution. We set it to the current working directory so that
- # the working directory of the elevated execution of this script is the current working directory
- if(-not($PSBoundParameters.ContainsKey('workingDirOverride')))
- {
- $workingDirOverride = (Get-Location).Path
- }
- function Test-Admin {
- $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
- $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
- }
- # If we are in a non-admin execution. Execute this script as admin
- if ((Test-Admin) -eq $false) {
- if ($shouldAssumeToBeElevated) {
- Write-Output "Elevating did not work :("
- } else {
- # vvvvv add `-noexit` here for better debugging vvvvv
- Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -file "{0}" -shouldAssumeToBeElevated -workingDirOverride "{1}"' -f ($myinvocation.MyCommand.Definition, "$workingDirOverride"))
- }
- exit
- }
- Set-Location "$workingDirOverride"
- ##### END ELEVATE TO ADMIN #####
- # Add actual commands to be executed in elevated mode here:
- Write-Output "I got executed in an admin PowerShell"
- Write-Host "Installing NuGet MinimumVersion 2.8.5.201"
- Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
- Write-Host "Installing PowerShell Windows Update Module"
- Install-Module PSWindowsUpdate -Force
- Import-Module PSWindowsUpdate
- # Set Computer And User Language
- $Lang = "sv-SE"
- Write-Host "Installing Language Pack for: $Lang"
- Install-Language -CopyToSettings -Language $Lang -ExcludeFeatures
- Write-Host "Installing Language Pack for: $Lang completed."
- Write-Host "Setting Windows Preferred UI Language: $Lang"
- Set-SystemPreferredUILanguage -Language $Lang
- Write-Host "Windows override language: $Lang"
- Set-WinUILanguageOverride -Language $Lang
- Write-Host "Setting Windows System Locale to $Lang"
- Set-WinSystemLocale $Lang
- Write-Host "Setting WinUserLanguageList to $Lang"
- Set-WinUserLanguageList $Lang -Force
- #Windows Update
- Write-Host "Windows Update.."
- Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -IgnoreReboot -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
- # Set Default password & No password expiring
- $Username="default"
- $PassRaw="default"
- $Password= ConvertTo-SecureString $PassRaw -AsPlainText -Force
- Set-LocalUser -Name $Username -Password $Password
- Set-LocalUser -Name $Username -PasswordNeverExpires $true
- # Set automatic logon for default user
- #autologon $Username $Env:COMPUTERNAME $Password
- $dir = (Get-Item .).FullName
- $prg = "$dir\Autologon.exe"
- Write-Host "AutoLogon exe: $prg"
- Test-Path -Path $prg
- Start-Process -FilePath "$dir\Autologon.exe" -ArgumentList "$Username $Env:COMPUTERNAME $PassRaw /accepteula" -Wait
- #$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
- #Set-ItemProperty $RegistryPath 'AutoAdminLogon' -Value "1" -Type String
- #Set-ItemProperty $RegistryPath 'DefaultUsername' -Value "$Username" -type String
- #Set-ItemProperty $RegistryPath 'DefaultPassword' -Value "$Password" -type String
- # Install winget
- Install-Script -Name winget-install -Force
- winget-install
- winget-install -CheckForUpdate
- # Install usefull programs
- Write-Host "Installing 7-Zip"
- "Y" | winget install -e --id 7zip.7zip --silent --accept-source-agreements --accept-package-agreements
- #Write-Host "Installing Foxit PDF Reader"
- #"Y" | winget install -e --id Foxit.FoxitReader --silent --accept-source-agreements --accept-package-agreements
- Write-Host "Setting Power Plan to balanced!"
- powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e
- powercfg /change monitor-timeout-ac 0
- powercfg /change standby-timeout-ac 0
- Write-Host "Removing Meet Now"
- Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "HideSCAMeetNow" -Value 1
- Write-Host "Remove 3D Viewer"
- Get-AppxPackage Microsoft.Microsoft3DViewer -AllUsers | Remove-AppxPackage
- Write-Host "Remove Alarms & Clock"
- Get-AppxPackage Microsoft.WindowsAlarms -AllUsers | Remove-AppxPackage
- Write-Host "Remove Camera"
- Get-AppxPackage Microsoft.WindowsCamera -AllUsers | Remove-AppxPackage
- Write-Host "Remove Feedback Hub"
- Get-AppxPackage Microsoft.WindowsFeedbackHub -AllUsers | Remove-AppxPackage
- Write-Host "Remove Groove Music"
- Get-AppxPackage Microsoft.ZuneMusic -AllUsers | Remove-AppxPackage
- Write-Host "Remove Mail and Calendar"
- Get-AppxPackage microsoft.windowscommunicationsapps -AllUsers | Remove-AppxPackage
- Write-Host "Remove Maps"
- Get-AppxPackage Microsoft.WindowsMaps -AllUsers | Remove-AppxPackage
- Write-Host "Remove Microsoft Solitaire Collection"
- Get-AppxPackage Microsoft.MicrosoftSolitaireCollection -AllUsers | Remove-AppxPackage
- Write-Host "Remove Mixed Reality Portal"
- Get-AppxPackage Microsoft.MixedReality.Portal -AllUsers | Remove-AppxPackage
- Write-Host "Remove Groove music"
- Get-AppxPackage Microsoft.ZuneMusic -AllUsers | Remove-AppxPackage
- Write-Host "Remove Xbox and Xbox Game Bar apps"
- Get-AppxPackage Microsoft.XboxApp -AllUsers | Remove-AppxPackage
- Get-AppxPackage Microsoft.XboxGamingOverlay -AllUsers | Remove-AppxPackage
- Write-Host "Remove Movies & TV"
- Get-AppxPackage Microsoft.ZuneVideo | Remove-AppxPackage
- Write-Host 'Removing Cortana from system'
- Get-AppxPackage -allusers Microsoft.549981C3F5F10 | Remove-AppxPackage
- Write-Host 'Removing News Widget'
- Get-AppxPackage -AllUsers MicrosoftWindows.Client.WebExperience |
- Remove-AppxPackage -AllUsers
- Write-Host 'Removing News Weather App'
- Get-AppxPackage Microsoft.BingWeather | Remove-AppxPackage
- #Disable News and Interests
- Reg Add "$reglocation\Software\Microsoft\Windows\CurrentVersion\Feeds" /T REG_DWORD /V "ShellFeedsTaskbarViewMode" /D 2 /F
- #Write-Host 'Disabling Websearch in start menu'
- #Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name "BingSearchEnabled" -Value 1 -Type DWord
- #if( -not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer)){
- #New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer
- #}
- #Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name "DisableSearchBoxSuggestions" -Value 1 -Type DWORD
- #
- #Write-Host 'Disabling Cortana'
- #Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name "AllowCortana " -Value 0 -Type DWord
- #if( -not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer)){
- #New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer
- #}
- #Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name "AllowCortana " -Value 0 -Type DWORD
- Write-Host 'Restarting the computer in 30 seconds'
- #Add-Type -AssemblyName PresentationFramework
- #[System.Windows.MessageBox]::Show('The computer will restart in 5 minutes. Please save your work.', 'Restart Warning', 'OK', 'Warning')
- Start-Sleep -Seconds 30
- Restart-Computer
- Restart-Computer -Force
Advertisement
Add Comment
Please, Sign In to add comment