-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun-All-Work-Scripts.ps1
More file actions
195 lines (171 loc) · 8.36 KB
/
Copy pathRun-All-Work-Scripts.ps1
File metadata and controls
195 lines (171 loc) · 8.36 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#Requires -RunAsAdministrator
<#
.SYNOPSIS
A master script to orchestrate the setup of a Windows environment by running a series of configuration,
software update, and drive mapping scripts from the workScripts GitHub repository.
.DESCRIPTION
This script performs the following actions in sequence:
1. Verifies it is running with Administrator privileges.
2. Executes Windows setup scripts (Enable Admin, System Settings, Google Credentials).
3. Runs the script to clone Egnyte drives.
4. Runs the script to update the Egnyte client.
5. Conditionally runs the software installation script from C:\Archive. It checks if C:\Archive
exists and contains more than 10 files. If not, it prompts the user to add the files
and provides an option to re-check and continue or to exit.
.NOTES
Author: Jevon Thompson (Created by Gemini)
Date: 2024-07-22
Version: 1.0
#>
#====================================================================================================
# SCRIPT START
#====================================================================================================
param(
[switch]$NonInteractive,
[switch]$SkipArchiveInstall,
[switch]$SkipRmmInstall,
[int]$MinArchiveFileCount = 10,
[string]$RmmTargetDirectory = "C:\Archive\rmm",
[int]$RmmSelection = 1
)
# Step 0: Initial Setup and Administrator Check
#----------------------------------------------------------------------------------------------------
Write-Host "===========================================================" -ForegroundColor Cyan
Write-Host " STARTING MASTER WORK SCRIPT AUTOMATION"
Write-Host "===========================================================" -ForegroundColor Cyan
Write-Host ""
# Verify the script is running in an elevated (Administrator) session.
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "This script requires Administrator privileges. Please re-launch in an elevated PowerShell session."
# Pause for 5 seconds before exiting to allow user to read the message.
if (-not $NonInteractive) {
Start-Sleep -Seconds 5
}
exit
}
else {
Write-Host "[OK] Administrator privileges confirmed." -ForegroundColor Green
}
# Bypass execution policy for the current process to ensure remote scripts can run.
try {
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
Write-Host "[OK] Execution policy set to 'Bypass' for the current session." -ForegroundColor Green
Write-Host ""
}
catch {
Write-Error "[ERROR] Failed to set execution policy. Halting script."
Start-Sleep -Seconds 5
exit
}
# Step 1: Running Windows Setup Scripts
#----------------------------------------------------------------------------------------------------
Write-Host "STEP 1: Running Windows Setup Scripts..." -ForegroundColor Cyan
try {
Write-Host " -> Enabling Administrator Account..."
& ([scriptblock]::Create((irm "https://github.com/JevonThompsonx/workScripts/raw/refs/heads/main/Accounts/enable_admin.bat")))
Write-Host " -> Configuring Windows Settings (Dark Mode, Power Plan, UAC)..."
if ($NonInteractive) {
& ([scriptblock]::Create((irm "https://github.com/JevonThompsonx/workScripts/raw/refs/heads/main/Configuration/setup_scriptv1.5.ps1"))) -NoPause
}
else {
& ([scriptblock]::Create((irm "https://github.com/JevonThompsonx/workScripts/raw/refs/heads/main/Configuration/setup_scriptv1.5.ps1")))
}
Write-Host " -> Applying Google Credentials Provider settings..."
& ([scriptblock]::Create((irm "https://raw.githubusercontent.com/JevonThompsonx/workScripts/refs/heads/main/Archive/AllowGoogleCredentials.ps1")))
Write-Host "[OK] STEP 1 Complete: Windows Setup Scripts executed successfully." -ForegroundColor Green
Write-Host ""
}
catch {
Write-Error "[ERROR] An error occurred during Windows Setup. Please check the output above."
}
# Step 2: Cloning Egnyte Drives
#----------------------------------------------------------------------------------------------------
Write-Host "STEP 2: Running Egnyte Drive Cloning Script..." -ForegroundColor Cyan
try {
& ([scriptblock]::Create((irm "https://raw.githubusercontent.com/JevonThompsonx/workScripts/refs/heads/main/Networking/cloneDrives.ps1")))
Write-Host "[OK] STEP 2 Complete: Egnyte Drive Cloning script executed." -ForegroundColor Green
Write-Host ""
}
catch {
Write-Error "[ERROR] An error occurred while cloning Egnyte drives."
}
# Step 3: Updating Egnyte Software
#----------------------------------------------------------------------------------------------------
Write-Host "STEP 3: Running Egnyte Software Update Script..." -ForegroundColor Cyan
try {
if ($NonInteractive) {
& ([scriptblock]::Create((irm "https://raw.githubusercontent.com/JevonThompsonx/workScripts/refs/heads/main/Install/updatingSoftware/Update-Egnyte-v1.5.ps1"))) -NoPause
}
else {
& ([scriptblock]::Create((irm "https://raw.githubusercontent.com/JevonThompsonx/workScripts/refs/heads/main/Install/updatingSoftware/Update-Egnyte-v1.5.ps1")))
}
Write-Host "[OK] STEP 3 Complete: Egnyte Update script executed." -ForegroundColor Green
Write-Host ""
}
catch {
Write-Error "[ERROR] An error occurred while updating Egnyte."
}
# Step 4: Install Software from C:\Archive (Conditional)
#----------------------------------------------------------------------------------------------------
Write-Host "STEP 4: Installing Software from C:\Archive..." -ForegroundColor Cyan
$archivePath = "C:\Archive"
$minFileCount = $MinArchiveFileCount
$installScriptUrl = "https://github.com/JevonThompsonx/workScripts/raw/refs/heads/main/Install/installAllArchiveSoftwarev2.6.ps1"
function Run-Archive-Install {
try {
Write-Host " -> Running software installation script..." -ForegroundColor Green
if ($NonInteractive) {
& ([scriptblock]::Create((irm $installScriptUrl))) -SkipDebloatPrompt -NoPause
}
else {
& ([scriptblock]::Create((irm $installScriptUrl)))
}
Write-Host "[OK] STEP 4 Complete: Software installation script executed." -ForegroundColor Green
}
catch {
Write-Error "[ERROR] An error occurred during the software installation."
}
}
# Check if the archive folder exists and has more than the minimum number of files
if ($SkipArchiveInstall) {
Write-Host " -> Skipping archive software installation as requested." -ForegroundColor Yellow
}
elseif ((Test-Path -Path $archivePath) -and ((Get-ChildItem -Path $archivePath).Count -gt $minFileCount)) {
Write-Host " -> Archive folder found with more than $minFileCount files. Proceeding with installation."
Run-Archive-Install
}
else {
Write-Host " -> The C:\Archive folder does not exist or has 10 or fewer files." -ForegroundColor Yellow
if ($NonInteractive) {
Write-Host " -> Non-interactive mode: skipping archive software installation." -ForegroundColor Yellow
}
else {
# Loop to prompt the user for action
while ($true) {
$choice = Read-Host " -> Please add files to C:\Archive now. Press 'y' to continue with installation, or 'n' to exit the script"
if ($choice -eq 'y') {
# Re-check the condition after user intervention
if ((Test-Path -Path $archivePath) -and ((Get-ChildItem -Path $archivePath).Count -gt $minFileCount)) {
Write-Host " -> Condition now met. Proceeding with installation." -ForegroundColor Green
Run-Archive-Install
break # Exit the while loop
}
else {
Write-Warning " -> The archive folder is still not ready. Exiting script."
break # Exit the while loop
}
}
elseif ($choice -eq 'n') {
Write-Host " -> Exiting script as requested. The software installation was skipped." -ForegroundColor Yellow
break # Exit the while loop
}
else {
Write-Warning " -> Invalid input. Please press 'y' to continue or 'n' to exit."
}
}
}
}
# Pause at the end to allow the user to review the output.
if (-not $NonInteractive) {
Read-Host "Press Enter to close this window..."
}