-
Star
(358)
You must be signed in to star a gist -
Fork
(95)
You must be signed in to fork a gist
-
-
Save mikepruett3/7ca6518051383ee14f9cf8ae63ba18a7 to your computer and use it in GitHub Desktop.
| <# | |
| .SYNOPSIS | |
| Script to Initialize my custom powershell setup. | |
| .DESCRIPTION | |
| Script uses scoop | |
| .NOTES | |
| **NOTE** Will configure the Execution Policy for the "CurrentUser" to Unrestricted. | |
| Author: Mike Pruett | |
| Date: October 18th, 2018 | |
| #> | |
| $VerbosePreference = "Continue" | |
| function Install-ScoopApp { | |
| param ( | |
| [string]$Package | |
| ) | |
| Write-Verbose -Message "Preparing to install $Package" | |
| if (! (scoop info $Package).Installed ) { | |
| Write-Verbose -Message "Installing $Package" | |
| scoop install $Package | |
| } else { | |
| Write-Verbose -Message "Package $Package already installed! Skipping..." | |
| } | |
| } | |
| function Install-WinGetApp { | |
| param ( | |
| [string]$PackageID | |
| ) | |
| Write-Verbose -Message "Preparing to install $PackageID" | |
| # Added accept options based on this issue - https://github.com/microsoft/winget-cli/issues/1559 | |
| $listApp = winget list --exact -q $PackageID --accept-source-agreements --accept-package-agreements | |
| if (!$listApp) { | |
| Write-Verbose -Message "Installing $Package" | |
| winget install --exact --silent $PackageID | |
| } else { | |
| Write-Verbose -Message "Package $PackageID already installed! Skipping..." | |
| } | |
| } | |
| function Install-ChocoApp { | |
| param ( | |
| [string]$Package | |
| ) | |
| Write-Verbose -Message "Preparing to install $Package" | |
| $listApp = choco list --local $Package | |
| if ($listApp -like "0 packages installed.") { | |
| Write-Verbose -Message "Installing $Package" | |
| Start-Process -FilePath "PowerShell" -ArgumentList "choco","install","$Package","-y" -Verb RunAs -Wait | |
| } else { | |
| Write-Verbose -Message "Package $Package already installed! Skipping..." | |
| } | |
| } | |
| function Remove-InstalledApp { | |
| param ( | |
| [string]$Package | |
| ) | |
| Write-Verbose -Message "Uninstalling: $Package" | |
| Start-Process -FilePath "PowerShell" -ArgumentList "Get-AppxPackage","-AllUsers","-Name","'$Package'" -Verb RunAs -WindowStyle Hidden | |
| } | |
| function Enable-Bucket { | |
| param ( | |
| [string]$Bucket | |
| ) | |
| if (! ($(scoop bucket list) -like "$Bucket") ) { | |
| Write-Verbose -Message "Adding Bucket $Bucket to scoop..." | |
| scoop bucket add $Bucket | |
| } else { | |
| Write-Verbose -Message "Bucket $Bucket already added! Skipping..." | |
| } | |
| } | |
| # Configure ExecutionPolicy to Unrestricted for CurrentUser Scope | |
| if ((Get-ExecutionPolicy -Scope CurrentUser) -notcontains "Unrestricted") { | |
| Write-Verbose -Message "Setting Execution Policy for Current User..." | |
| Start-Process -FilePath "PowerShell" -ArgumentList "Set-ExecutionPolicy","-Scope","CurrentUser","-ExecutionPolicy","Unrestricted","-Force" -Verb RunAs -Wait | |
| } | |
| # Install Scoop, if not already installed | |
| $scoopInstalled = Get-Command "scoop" | |
| if (!$scoopInstalled) { | |
| Write-Verbose -Message "Installing Scoop..." | |
| iex ((New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')) | |
| } | |
| # Install Chocolatey, if not already installed | |
| $chocoInstalled = Get-Command "choco" -CommandType Application -ErrorAction Ignore | |
| if (!$chocoInstalled) { | |
| Write-Verbose -Message "Installing Chocolatey..." | |
| @' | |
| [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 | |
| iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) | |
| '@ > $Env:Temp\choco.ps1 | |
| Start-Process -FilePath "PowerShell" -ArgumentList "$Env:Temp\choco.ps1" -Verb RunAs -Wait | |
| Remove-Item -Path $Env:Temp\choco.ps1 -Force | |
| } | |
| # Install WinGet, if not already installed | |
| # From crutkas's gist - https://gist.github.com/crutkas/6c2096eae387e544bd05cde246f23901 | |
| $hasPackageManager = Get-AppPackage -name "Microsoft.DesktopAppInstaller" | |
| if (!$hasPackageManager) { | |
| Write-Verbose -Message "Installing WinGet..." | |
| @' | |
| # Set URL and Enable TLSv12 | |
| $releases_url = "https://api.github.com/repos/microsoft/winget-cli/releases/latest" | |
| [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
| # Dont Think We Need This!!! | |
| #Install-PackageProvider -Name NuGet | |
| # Install Nuget as Package Source Provider | |
| Register-PackageSource -Name Nuget -Location "http://www.nuget.org/api/v2" -ProviderName Nuget -Trusted | |
| # Install Microsoft.UI.Xaml (This is not currently working!!!) | |
| Install-Package Microsoft.UI.Xaml -RequiredVersion 2.7.1 | |
| # Grab "Latest" release | |
| $releases = Invoke-RestMethod -uri $releases_url | |
| $latestRelease = $releases.assets | Where { $_.browser_download_url.EndsWith('msixbundle') } | Select -First 1 | |
| # Install Microsoft.DesktopAppInstaller Package | |
| Add-AppxPackage -Path $latestRelease.browser_download_url | |
| '@ > $Env:Temp\winget.ps1 | |
| Start-Process -FilePath "PowerShell" -ArgumentList "$Env:Temp\winget.ps1" -Verb RunAs -Wait | |
| Remove-Item -Path $Env:Temp\winget.ps1 -Force | |
| } | |
| # Configure git | |
| Install-ScoopApp -Package "git" | |
| git config --global credential.helper manager-core | |
| if (!($Env:GIT_SSH)) { | |
| Write-Verbose -Message "Setting GIT_SSH User Environment Variable" | |
| [System.Environment]::SetEnvironmentVariable('GIT_SSH', (Resolve-Path (scoop which ssh)), 'USER') | |
| } | |
| if ((Get-Service -Name ssh-agent).Status -ne "Running") { | |
| Start-Process -FilePath "PowerShell" -ArgumentList "Set-Service","ssh-agent","-StartupType","Manual" -Verb RunAs -Wait -WindowStyle Hidden | |
| } | |
| # Only install OpenSSH Package, if not on Windows 10 | |
| if ([Environment]::OSVersion.Version.Major -lt 10) { | |
| Install-ScoopApp -Package "openssh" | |
| } | |
| # Configure Aria2 Download Manager | |
| Install-ScoopApp -Package "aria2" | |
| scoop config aria2-enabled true | |
| scoop config aria2-warning-enabled false | |
| @' | |
| $Action = New-ScheduledTaskAction -Execute $Env:UserProfile\scoop\apps\aria2\current\aria2c.exe -Argument "--enable-rpc --rpc-listen-all" -WorkingDirectory $Env:UserProfile\Downloads | |
| $Trigger = New-ScheduledTaskTrigger -AtStartup | |
| Register-ScheduledTask -TaskName "Aria2RPC" -Action $Action -Trigger $Trigger | |
| '@ > $Env:Temp\aria2.ps1 | |
| Start-Process -FilePath "PowerShell" -ArgumentList "$Env:Temp\aria2.ps1" -Verb RunAs -Wait -WindowStyle Hidden | |
| Remove-Item -Path $Env:Temp\aria2.ps1 -Force | |
| ## Add Buckets | |
| Enable-Bucket -Bucket "extras" | |
| Enable-Bucket -Bucket "java" | |
| scoop bucket add foosel https://github.com/foosel/scoop-bucket | |
| # UNIX Tools | |
| Write-Verbose -Message "Removing curl Alias..." | |
| if (Get-Alias -Name curl -ErrorAction SilentlyContinue) { | |
| Remove-Item alias:curl | |
| } | |
| if (!($Env:TERM)) { | |
| Write-Verbose -Message "Setting TERM User Environment Variable" | |
| [System.Environment]::SetEnvironmentVariable("TERM", "xterm-256color", "USER") | |
| } | |
| # Check if Home Workstation | |
| Remove-Variable -Name "HomeWorkstation" | |
| if ($(Read-Host -Prompt "Is this a workstation for Home use (y/n)?") -eq "y") { | |
| $HomeWorkstation = $True | |
| } else { | |
| $HomeWorkstation = $False | |
| } | |
| # Install Scoop Packages | |
| $Scoop = @( | |
| "scoop-tray", | |
| "clink", | |
| "concfg", | |
| "curl", | |
| "busybox", | |
| "fzf", | |
| "neovim", | |
| "pshazz", | |
| "cacert", | |
| "colortool", | |
| "sudo", | |
| "vscode", | |
| "openjdk", | |
| "icedtea-web", | |
| "go", | |
| "python", | |
| "gpg", | |
| "imgburn", | |
| "paint.net", | |
| "putty", | |
| "winscp", | |
| "spacesniffer", | |
| "filebot", | |
| "rufus", | |
| "etcher", | |
| "cpu-z", | |
| "gpu-z", | |
| "ssd-z", | |
| "hwmonitor", | |
| "crystaldiskmark", | |
| "powertoys", | |
| "open-log-viewer", | |
| "baretail", | |
| "bleachbit", | |
| "hosts-file-editor", | |
| "minio-client", | |
| "lessmsi", | |
| "mqtt-explorer", | |
| "sysinternals")#,"rktools2k3") | |
| foreach ($item in $Scoop) { | |
| Install-ScoopApp -Package "$item" | |
| } | |
| # Install Scoop Packages, if Home Workstation | |
| if ($HomeWorkstation) { | |
| Remove-Variable -Name "Scoop" | |
| $Scoop = @( | |
| "ffmpeg", | |
| "mpv", | |
| "vlc", | |
| "lame", | |
| "musicbee", | |
| "mp3tag", | |
| "mkvtoolnix", | |
| "obs-studio", | |
| "yt-dlp", | |
| "ocenaudio", | |
| "mediainfo", | |
| "mediainfo-gui", | |
| "cdrtools", | |
| "cuetools") | |
| foreach ($item in $Scoop) { | |
| Install-ScoopApp -Package "$item" | |
| } | |
| } | |
| # Install WinGet Packages | |
| $WinGet = @( | |
| "Microsoft.dotnetRuntime.3-x64", | |
| "Microsoft.dotnetRuntime.5-x64", | |
| "Microsoft.WindowsTerminal", | |
| "TeamViewer.TeamViewer", | |
| "Google.Chrome", | |
| "Lexikos.AutoHotkey", | |
| "SumatraPDF.SumatraPDF", | |
| "ScooterSoftware.BeyondCompare4", | |
| "Eassos.DiskGenius", | |
| "RevoUninstaller.RevoUninstaller", | |
| "ElaborateBytes.VirtualCloneDrive", | |
| "RARLab.WinRAR", | |
| "Piriform.Speccy", | |
| "Piriform.Defraggler" | |
| ) | |
| foreach ($item in $WinGet) { | |
| Install-WinGetApp -PackageID "$item" | |
| } | |
| # Install WinGet Packages, if Home Workstation | |
| if ($HomeWorkstation) { | |
| Remove-Variable -Name "WinGet" | |
| $WinGet = @( | |
| "Discord.Discord", | |
| "HandBrake.HandBrake", | |
| "AndreWiethoff.ExactAudioCopy", | |
| "clsid2.mpc-hc", | |
| "Plex.Plex", | |
| "Plex.Plexamp" | |
| ) | |
| foreach ($item in $WinGet) { | |
| Install-WinGetApp -PackageID "$item" | |
| } | |
| } | |
| # Create scoop-tray shortcut in shell:startup | |
| Write-Verbose -Message "Create scoop-tray shortcut in shell:startup..." | |
| $WSHShell = New-Object -ComObject WScript.Shell | |
| $Shortcut = $WSHShell.CreateShortcut("$Env:AppData\Microsoft\Windows\Start Menu\Programs\Startup\scoop-tray.lnk") | |
| $Shortcut.TargetPath = "$Env:UserProfile\scoop\apps\scoop-tray\current\scoop-tray.bat" | |
| $Shortcut.WindowStyle = 7 | |
| $Shortcut.IconLocation = "%USERPROFILE%\scoop\apps\scoop-tray\current\updates-available.ico" | |
| $Shortcut.Description = "scoop-tray.bat" | |
| $Shortcut.WorkingDirectory = Split-Path "$Env:UserProfile\scoop\apps\scoop-tray\current\scoop-tray.bat" -Resolve | |
| $Shortcut.Save() | |
| # Customize DOS/PowerShell Environment | |
| Write-Verbose -Message "Customize DOS/PowerShell Environment..." | |
| Start-Process -FilePath "cmd" -ArgumentList "/c","clink","autorun","install" -Wait -WindowStyle Hidden | |
| Start-Process -FilePath "cmd" -ArgumentList "/c","concfg","import","solarized-dark" -Verb RunAs -Wait | |
| # Install Visual Studio Code Integrations | |
| Write-Verbose -Message "Install Visual Studio Code Integrations..." | |
| Start-Process -FilePath "cmd" -ArgumentList "/c","reg","import","%UserProfile%\scoop\apps\vscode\current\install-context.reg" -Verb RunAs -Wait -WindowStyle Hidden | |
| Start-Process -FilePath "cmd" -ArgumentList "/c","reg","import","%UserProfile%\scoop\apps\vscode\current\nstall-associations.reg" -Verb RunAs -Wait -WindowStyle Hidden | |
| # Install syspin | |
| Write-Verbose -Message "Installing syspin..." | |
| Install-ChocoApp -Package "syspin" | |
| # Pin Run to Taskbar | |
| #Start-Process -FilePath "PowerShell" -ArgumentList "syspin","'$Env:AppData\Microsoft\Windows\Start Menu\Programs\System Tools\Run.lnk'","c:5386" -Wait -NoNewWindow | |
| # Pin Google Chrome to Taskbar | |
| Write-Verbose -Message "Pin Google Chrome to Taskbar..." | |
| Start-Process -FilePath "PowerShell" -ArgumentList "syspin","'$Env:ProgramData\Microsoft\Windows\Start Menu\Programs\Google Chrome.lnk'","c:5386" -Wait -NoNewWindow | |
| # Install my PowerShell dot files | |
| Write-Verbose -Message "Install my PowerShell dot files..." | |
| Start-Process -FilePath "PowerShell" -ArgumentList "git","clone","https://github.com/mikepruett3/dotposh.git","$Env:UserProfile\dotposh" -Wait -NoNewWindow | |
| @' | |
| New-Item -Path $Env:UserProfile\Documents\WindowsPowerShell -ItemType Directory -ErrorAction Ignore | |
| Remove-Item -Path $Env:UserProfile\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 -Force | |
| New-Item -Path $Env:UserProfile\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 -ItemType SymbolicLink -Target $Env:UserProfile\dotposh\profile.ps1 | |
| '@ > $Env:Temp\dotposh.ps1 | |
| Start-Process -FilePath "PowerShell" -ArgumentList "$Env:Temp\dotposh.ps1" -Verb RunAs -Wait -WindowStyle Hidden | |
| Remove-Item -Path $Env:Temp\dotposh.ps1 -Force | |
| @' | |
| cd $Env:UserProfile\dotposh | |
| git submodule init | |
| git submodule update | |
| '@ > $Env:Temp\submodule.ps1 | |
| Start-Process -FilePath "PowerShell" -ArgumentList "$Env:Temp\submodule.ps1" -Wait -NoNewWindow | |
| Remove-Item -Path $Env:Temp\submodule.ps1 -Force | |
| # Pin PowerShell to Taskbar | |
| Write-Verbose -Message "Pin PowerShell to Taskbar..." | |
| Start-Process -FilePath "PowerShell" -ArgumentList "syspin","'$Env:AppData\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell.lnk'","c:5386" -Wait -NoNewWindow | |
| # Install PowerShell 7 | |
| $PS7 = winget list --exact -q Microsoft.PowerShell | |
| if (!$PS7) { | |
| Write-Verbose -Message "Installing PowerShell 7..." | |
| @' | |
| iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet" | |
| '@ > $Env:Temp\ps7.ps1 | |
| Start-Process -FilePath "PowerShell" -ArgumentList "$Env:Temp\ps7.ps1" -Verb RunAs -Wait -WindowStyle Hidden | |
| Remove-Item -Path $Env:Temp\ps7.ps1 -Force | |
| } | |
| # Pin PowerShell 7 to Taskbar | |
| Write-Verbose -Message "Pin PowerShell 7 to Taskbar..." | |
| Start-Process -FilePath "PowerShell" -ArgumentList "syspin","'$Env:ProgramData\Microsoft\Windows\Start Menu\Programs\PowerShell\PowerShell 7 (x64).lnk'","c:5386" -Wait -NoNewWindow | |
| # Remove unused Packages/Applications | |
| Write-Verbose -Message "Removing Unused Applications..." | |
| $RemoveApps = @("*3DPrint*","Microsoft.MixedReality.Portal") | |
| foreach ($item in $RemoveApps) { | |
| Remove-InstalledApp -Package $item | |
| } | |
| # Install Windows SubSystems for Linux | |
| Start-Process -FilePath "PowerShell" -ArgumentList "wsl","--install" -Verb RunAs -Wait -WindowStyle Hidden | |
| Install-WinGetApp -PackageID Canonical.Ubuntu.2004 | |
| Write-Output "Install complete! Please reboot your machine/worksation!" | |
| Start-Sleep -Seconds 3 |
Love the script, nice work.
That's the most sophisticated automated setup I've seen so far for win64... Kudos.
Very nice. Very nice indeed.
Good script for software installation automation.
Is there purpose behind which packages are installed from which package manager? I'd have assumed you're taking all from scoop and falling back to the others if scoop doesn't have them, but that doesn't seem to be the case as packages like starship,openjdk,chrome are available in scoop but installed from Winget instead.
This is an incredible resource to learn how to automate installations on Windows. Thanks a lot for sharing this, and Kudos!
Is there purpose behind which packages are installed from which package manager? I'd have assumed you're taking all from scoop and falling back to the others if scoop doesn't have them, but that doesn't seem to be the case as packages like starship,openjdk,chrome are available in scoop but installed from Winget instead.
So, when I originally made this script, most of the packages I used were from scoop or chocolatey. I did this because not everything I needed was in a scoop bucket. Since Microsoft made winget available, I have mostly been migrating any application installs to use that, over scoop and chocolatey.
So no, this script does not try one package installer first, and then go try the next for the same package. I am manually updating this gist with a curated collection of packages that I need/use over time. Hope that makes sense.
Thanks all. This gist started out as a bastardized tool for me to quickly provision my laptop or desktop after re-installing windows. (Especially my work laptop, as I keep getting a new one every year or so). Please feel free to use this as a start to your own setup script... as I am sure you probably do not need all of the packages that I use. Any improvements or suggestions are more than welcome! Thanks!
Hi Mike, I really really like the script you've created here, I've gone ahead and edited your script to have an JSON configurations, tests, and more settings. I was wondering if I could publish it to my own repository with your permission, of-course giving you credit on said repo for your original work.
Absolutely! Would love to have this be a lot more stable and easy to follow. I don't know what the License is for gists, but I am totally down with this being GPLv3 at least. Free as in beer for sure! Love to see what you come up with!
Question, did you reinstall/reset your pc over and over just to test this script? If yes, what's the quickest way to reset?
@ZYinMD : you might want to test it in a virtual machine that you snapshot before executing the script. You can then restore it easily and tweak your script until you get this right. Here are some info https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/checkpoints
Question, did you reinstall/reset your pc over and over just to test this script? If yes, what's the quickest way to reset?
I have a few spare Windows Laptops lying around that I blow away the OS, and run the script on for testing. Honestly, a VM would probably be easier... but that's what I have been using for a while now.
Since Microsoft made winget available, I have mostly been migrating any application installs to use that
ExifTool is available via winget – although is there a reason you're locked at 12.41?
Since Microsoft made winget available, I have mostly been migrating any application installs to use that
ExifTool is available via winget – although is there a reason you're locked at 12.41?
Thanks for the heads up! Been a while since I have updated the script, but I have gone thru and switched out all of the scoop and custom install tasks with packages from winget.
Thanks
Happy my own ultimately unsuccessful search for a way to winget Notepad++ without admin helped someone!
Thanks
Happy my own ultimately unsuccessful search for a way to winget Notepad++ without admin helped someone!
I replaced the existing sudo command from scoop, with gsudo from gerardog recently. This works in other shells beside powershell. Not sure if that helps or not, but you can always put the gsudo before the winget command.
You can get and run the entire script on a new machine by invoking the following command.
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://gist.github.com/mikepruett3/7ca6518051383ee14f9cf8ae63ba18a7/raw/shell-setup.ps1'))"
nice script :) do you run this as admin?
gsudobefore the winget command
Many thanks for the idea, but sadly gsudo itself requires admin to install!
This looks really awesome. I haven't tried it myself yet, but one thing that could be really cool is a "manager" of package managers. This sounds overbloated, however I'd like my stuff to be maintable from one CLI tool. A script for searching packages over multiple sources and installing (or switching) between sources would be a nice addition in this regard.
Does something like this exist?
I usually just copy and paste the string into "run" from the start menu. I think on Windows 10 this automatically runs as Admin. I would try to run it that way.
Not to my knowledge. I use the scoop-tray tool from foosel for Updates to scoop packages and winget upgrade --recurse to keep the packages updated.
Maybe if I have some free time I can try and come up with something that searches all three for a package. Shouldn't be that hard, just need the cycles! 😄
This looks sick, my current setup is to use as many portable apps as possible plus a detailed setup guide in one note but this looks very tempting. I don't think I can ever get rid of all portable apps like browsers because they have like 200 tabs spanned across tens of workspaces etc. If only all these tabs and stuff sync as well.
Your browser doesn't sync workspace tabs? Huh mine does just fine. 150 or so tabs open all the time synced across 6 computers all the time. Edge syncs it just fine what browser do you use?
Really love your script, mate! Gonna use some functions in my further work, thanks!
This looks sick, my current setup is to use as many portable apps as possible plus a detailed setup guide in one note but this looks very tempting. I don't think I can ever get rid of all portable apps like browsers because they have like 200 tabs spanned across tens of workspaces etc. If only all these tabs and stuff sync as well.
So this script does install regular versions of applications as well... (mainly the winget tasks). I was a long-time user of scoop, but I found that it broke more often with the apps that I was using. Moving most of the apps I use on the regular to winget.
Really love your script, mate! Gonna use some functions in my further work, thanks!
Thanks!
You can get and run the entire script on a new machine by invoking the following command.