<# .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