This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_Install_Chocolatey.ps1
48 lines (39 loc) 路 1.83 KB
/
1_Install_Chocolatey.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
#############################################
# 2. Install Chocolatey
# by Josh Cooper
#############################################
Write-Host "Installing Chocolatey..." -ForegroundColor Black -BackgroundColor Yellow
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator and continue."
$length = 5
for ($i = 1; $i -le $length; $i++) {
$j = $length - $i
Write-Host "Elevating in $j seconds..." -ForegroundColor white -BackgroundColor darkred
Start-Sleep 1
}
Write-Host #ends the line after loop
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs;
exit
}
#no errors throughout
$ErrorActionPreference = 'silentlycontinue'
$LogFolder = "C:\Temp\SetupScripts\choco"
If (Test-Path $LogFolder) {
Write-Output "$LogFolder exists. Skipping."
}
Else {
Write-Output "The folder '$LogFolder' doesn't exist. This folder will be used for storing logs created after the script runs. Creating now."
Start-Sleep 1
New-Item -Path "$LogFolder" -ItemType Directory
Write-Output "The folder $LogFolder was successfully created."
}
Start-Transcript -OutputDirectory "$LogFolder"
Function InstallChoco {
Write-Host "Installing Chocolate for Windows..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
Set-ExecutionPolicy Bypass -Scope Process -Force;
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
Write-Host "Installing Choco..." -BackgroundColor Magenta -ForegroundColor White
InstallChoco
Start-Sleep 1