This post describes how to setup all the needed programms on a new computer:
<#
Script to install Various Programms
#>
#Check if Chocolatey is already installed, when not install it
function Install-Chocolatey {
<#
.SYNOPSIS
Insure Chocolatey is installed
.DESCRIPTION
Check if Chocolatey is installed. If not, then install it.
.EXAMPLE
Install-Chocolatey
#>
[CmdletBinding(SupportsShouldProcess = $True)]
param ()
$testchoco = powershell choco -v
if(-not($testchoco)){
Write-Output "Seems Chocolatey is not installed, installing now"
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
else{
Write-Output "Chocolatey Version $testchoco is already installed"
}
}
function UnInstall-Chocolatey {
<#
.SYNOPSIS
IUnintstal chocolatey
.DESCRIPTION
Check if Chocolatey is installed. If then uninstall it.
.EXAMPLE
UnInstall-Chocolatey
#>
[CmdletBinding(SupportsShouldProcess = $True)]
param ()
$testchoco = powershell choco -v
if(-not($testchoco)){
Write-Output "Chocolatey is not installed"
}
else{
$VerbosePreference = 'Continue'
if (-not $env:ChocolateyInstall) {
$message = @(
"The ChocolateyInstall environment variable was not found."
"Chocolatey is not detected as installed. Nothing to do."
) -join "`n"
Write-Warning $message
return
}
if (-not (Test-Path $env:ChocolateyInstall)) {
$message = @(
"No Chocolatey installation detected at '$env:ChocolateyInstall'."
"Nothing to do."
) -join "`n"
Write-Warning $message
return
}
<#
Using the .NET registry calls is necessary here in order to preserve environment variables embedded in PATH values;
Powershell's registry provider doesn't provide a method of preserving variable references, and we don't want to
accidentally overwrite them with absolute path values. Where the registry allows us to see "
entry, PowerShell's registry provider only sees "C:\Windows", for example.
#>
$userKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment')
$userPath = $userKey.GetValue('PATH', [string]::Empty, 'DoNotExpandEnvironmentNames').ToString()
$machineKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey('SYSTEM\ControlSet001\Control\Session Manager\Environment\')
$machinePath = $machineKey.GetValue('PATH', [string]::Empty, 'DoNotExpandEnvironmentNames').ToString()
$backupPATHs = @(
"User PATH: $userPath"
"Machine PATH: $machinePath"
)
$backupFile = "C:\PATH_backups_ChocolateyUninstall.txt"
$backupPATHs | Set-Content -Path $backupFile -Encoding UTF8 -Force
$warningMessage = @"
This could cause issues after reboot where nothing is found if something goes wrong.
In that case, look at the backup file for the original PATH values in '$backupFile'.
"@
if ($userPath -like "*$env:ChocolateyInstall*") {
Write-Verbose "Chocolatey Install location found in User Path. Removing..."
Write-Warning $warningMessage
$newUserPATH = @(
$userPath -split [System.IO.Path]::PathSeparator |
Where-Object { $_ -and $_ -ne "$env:ChocolateyInstall\bin" }
) -join [System.IO.Path]::PathSeparator
# NEVER use [Environment]::SetEnvironmentVariable() for PATH values; see https://github.com/dotnet/corefx/issues/36449
# This issue exists in ALL released versions of .NET and .NET Core as of 12/19/2019
$userKey.SetValue('PATH', $newUserPATH, 'ExpandString')
}
if ($machinePath -like "*$env:ChocolateyInstall*") {
Write-Verbose "Chocolatey Install location found in Machine Path. Removing..."
Write-Warning $warningMessage
$newMachinePATH = @(
$machinePath -split [System.IO.Path]::PathSeparator |
Where-Object { $_ -and $_ -ne "$env:ChocolateyInstall\bin" }
) -join [System.IO.Path]::PathSeparator
# NEVER use [Environment]::SetEnvironmentVariable() for PATH values; see https://github.com/dotnet/corefx/issues/36449
# This issue exists in ALL released versions of .NET and .NET Core as of 12/19/2019
$machineKey.SetValue('PATH', $newMachinePATH, 'ExpandString')
}
# Adapt for any services running in subfolders of ChocolateyInstall
$agentService = Get-Service -Name chocolatey-agent -ErrorAction SilentlyContinue
if ($agentService -and $agentService.Status -eq 'Running') {
$agentService.Stop()
}
# TODO: add other services here
Remove-Item -Path $env:ChocolateyInstall -Recurse -Force -WhatIf
'ChocolateyInstall', 'ChocolateyLastPathUpdate' | ForEach-Object {
foreach ($scope in 'User', 'Machine') {
[Environment]::SetEnvironmentVariable($_, [string]::Empty, $scope)
}
}
$machineKey.Close()
$userKey.Close()
if ($env:ChocolateyToolsLocation -and (Test-Path $env:ChocolateyToolsLocation)) {
Remove-Item -Path $env:ChocolateyToolsLocation -WhatIf -Recurse -Force
}
foreach ($scope in 'User', 'Machine') {
[Environment]::SetEnvironmentVariable('ChocolateyToolsLocation', [string]::Empty, $scope)
}
}
}
Install-Chocolatey
#Install the different apps
Write-Output "Installing apps"
#The following command this makes sure that we do not always have to type in yes (https://stackoverflow.com/questions/29873439/how-do-i-update-all-chocolatey-applications-without-confirmation)
choco feature enable -n=allowGlobalConfirmation
choco install adobereader
choco install anki
choco install beyondcompare
choco install drawio
choco install dropbox
choco install Firefox --params "/NoTaskbarShortcut /NoDesktopShortcut"
choco install foxitreader
choco install git
choco install gnucash
choco install littlebigmouse
choco install logitech-options
choco install logitechgaming
choco install miktex
choco install miniconda3
choco install mobaxterm #Used to make a remote connection to OST server
choco install nextcloud-client
choco install obs-studio.install
choco install obs-virtualcam
choco install putty.install
choco install texstudio
choco install vscode --params "/NoDesktopIcon /NoQuicklaunchIcon"
choco install vscode-codespellchecker
choco install vscode-powershell
choco install vscode-python
choco install whatsapp
choco install winrar
choco install winscp