-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-no-choco-prompts.ps1
60 lines (50 loc) · 2.03 KB
/
install-no-choco-prompts.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<#
.SYNOPSIS
Installs Chocolatey and disables confirmation prompts with a simple one-line command.
.DESCRIPTION
This PowerShell script facilitates the installation of Chocolatey and disables confirmation prompts for package installations, upgrades, and removals, with a simple one-line command.
.EXAMPLE
iwr alt.choco.run | iex
.NOTES
Version : 2.0.0
Author : asheroto
Tags : windows install command script powershell installer chocolatey choco automatic installation auto run no-prompt
.LINK
https://github.com/asheroto/choco.run
#>
# Header
Write-Output ("-" * 80)
Write-Output "choco.run says hello..."
Write-Output ("-" * 80)
Write-Output ""
# Remember the current execution policy of the current process
$originalExecutionPolicy = Get-ExecutionPolicy -Scope Process
# Set the execution policy to Unrestricted (lower than Bypass)
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force
# Set the temp dir to the system temp dir
$originalPath = Get-Location
Set-Location "$env:SystemRoot\Temp"
# Install Chocolatey
Write-Output "Installing Chocolatey..."
Write-Output ""
Write-Output ("-" * 60)
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Verify if Chocolatey is installed
$chocoCommand = Get-Command 'choco' -ErrorAction SilentlyContinue
Write-Output ("-" * 60)
if ($chocoCommand) {
Write-Output ""
Write-Output "Chocolatey has been installed!"
# Disable confirmation prompts
Write-Output "Disabling confirmation prompts..."
choco feature enable -n=allowGlobalConfirmation
Write-Output "You can now use the 'choco' command in this window!"
} else {
Write-Output "An error may have occurred. 'choco' command is not accessible."
}
Write-Output ""
# Return to the original directory
Set-Location $originalPath
# Restore the original execution policy
Set-ExecutionPolicy -ExecutionPolicy $originalExecutionPolicy -Scope Process -Force