-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMasterScript.ps1
More file actions
546 lines (471 loc) · 16.9 KB
/
MasterScript.ps1
File metadata and controls
546 lines (471 loc) · 16.9 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
<#
.SYNOPSIS
Overview of script is to create Menu with sub menu then selection of action
.DESCRIPTION
Brief description of script, based on selection this script will exectute and do it's task, then returns back to Menu selection
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
At the moment there are not parameter set for this script
.INPUTS
Inputs are required by user based on selection to take action on
.OUTPUTS
Outputs at moment there are not logs created
.NOTES
Version: 1.0
Author: Ramnik Sanariya
Creation Date: 3/2/2023
Purpose/Change: Initial script development to learn and grow on day to day task
.EXAMPLE
Selection 1
action for selection 1
#>
cls
function startOver{
Clear-Host
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx This script is used for users and Admins xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-Host ' ' This script will execute 1 or more action based on selections, just be careful on your selections -ForegroundColor Yellow
$text=@"
$ver
__ __ _ _____ _____ _ _ _
| \/ | | | | __ \ / ____|| | | || |
| \ / | __ _ ___ | |_ ___ _ __ | |__) |___ __ __ ___ _ __| (___ | |__ ___ | || |
| |\/| | / _` |/ __|| __|/ _ \| '__| | ___// _ \\ \ /\ / // _ \| '__|\___ \ | '_ \ / _ \| || |
| | | || (_| |\__ \| |_| __/| | | | | (_) |\ V V /| __/| | ____) || | | || __/| || |
|_| |_| \__,_||___/ \__|\___||_| |_| \___/ \_/\_/ \___||_| |_____/ |_| |_| \___||_||_|
_____ _ _
/ ____| (_) | |
| (___ ___ _ __ _ _ __ | |_
\___ \ / __|| '__|| || '_ \ | __|
____) || (__ | | | || |_) || |_
|_____/ \___||_| |_|| .__/ \__|
| |
|_|
"@
$text
Write-Host ' Note: This Script AS IS, please use it with caustion' -ForegroundColor Red
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Start of checking Admin mode #######################################################
Write-Host ' '
Write-Host "Testing if the signed in user has local admin permissions..." -ForegroundColor Yellow
$LocalAdminGroup=(whoami /groups | Select-String 'S-1-5-32-544')
if ($LocalAdminGroup){
Write-Host "Test passed: the signed in user has local admin permissions" -ForegroundColor Green
}else{
Write-Host "Test failed: the signed in user does NOT have local admin permissions" -ForegroundColor Red
# Write-Log -Message "Test failed: the signed in user does NOT have local admin permissions" -Level ERROR
Write-Host ''
Write-Host "Recommended action: sign in with a user that has local admin permissions" -ForegroundColor Yellow
Write-Host ''
Write-Host ''
Write-Host "Script Ended" -ForegroundColor Green
Write-Host ''
Write-Host ''
#break
}
# End of checking Admin mode #######################################################
# To see what's set to:
$CurrentExecutionPolicy = Get-ExecutionPolicy
Write-Host "Currently execution Policy is set to: " $CurrentExecutionPolicy
$CurrentLoginName=whoami
Write-Host 'You are logged in as: ' $CurrentLoginName -ForegroundColor Green
$CurrentComputerName = $env:COMPUTERNAME
Write-Host 'Your Current computer name: ' $CurrentComputerName -ForegroundColor Green
MainMenu
}
function exitScript{
Clear-Host
Write-Host 'You Selected to Exit the Script'
exit
}
function ClearScreen{
cls
Write-Host "Please wait this may take few seconds"
}
function MainMenu{ # Start of Main Menu
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-Host ' Main Menu ' -ForegroundColor Green
Write-Host ' '
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-Host ' 0 To Exit' -ForegroundColor Yellow
$menu = @"
1. Get Information only
2. Setup Computer
3. Install Application(s)
4. Troubleshooting Tools
Make a selection:
"@
$userChoice = Read-Host $menu
# Using a switch statement to perform different actions based on the selected option
switch ($userChoice){
"0" {
exitScript
}
"1" { # Launch subMenu1 Get Information only
subMenu1
}
"2" { # Launch submenu2 Setup Computer
subMenu2
}
"3" { # Submenu3 Install Application(s)
subMenu3
}
"4"{ # Submenu4 Troubleshooting Tools
subMenu4
}
default {
Clear-Host
Write-Host 'Invalid selection please make selection'
MainMenu
}
}
} # End of Main Menu
function subMenu1{ # Start of Sub Menu 1
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-Host ' Get Information only' -ForegroundColor Green
Write-Host ' '
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-host ' 0 To Exit' -ForegroundColor Yellow
Write-host ' B To Go Back' -ForegroundColor Yellow
Write-host ' S Start Over' -ForegroundColor Yellow
$submenu1 = @"
1. Get name of your Computer
2. Find out whom you are logged in as
3. Get List of Printers
4. Get Windows Version
5. Get Your IP address info
6. Get List of Programs and it's Locations
7. Find out which version of MS office 32bit or 64bit
Make a selection:
"@
$userChoice = Read-Host -Prompt $submenu1
# Using a switch statement to perform different actions based on the selected option
switch ($userChoice){
"0" {
exitScript
}
"B" {
Clear-Host
MainMenu
}
"S" {
startOver
}
"1" {
Clear-Host
Write-Host 'Your Computer Name is: ' -NoNewline
HOSTNAME
''
subMenu1
}
"2" {
Clear-Host
$CurrentLoginName=whoami
Write-Host 'You are logged in as: ' $CurrentLoginName -ForegroundColor Green
''
subMenu1
}
"3" {
Clear-Host
Write-Host 'Your Computer have following printers installed:'
Write-Host ' '
Get-Printer | Format-Table
''
subMenu1
}
"4" {
Clear-Host
'Checking please wait'
Write-Host 'Your Windows Version is: '
$WindowVersion=(Get-WmiObject -class Win32_OperatingSystem).Caption + ' '+ (Get-CimInstance Win32_OperatingSystem).Version
Write-Host $WindowVersion -ForegroundColor Green
''
subMenu1
}
"5" {
Clear-Host
'Your IP address info listed below: '
Get-NetIPConfiguration | Format-List
''
subMenu1
}
"6"{
Clear-host
Write-Host 'Your Computer have following Programs installed: '
try {
if ($IsLinux) {
& snap list
} else {
Get-AppxPackage | Format-Table -property Name,Version,Architecture,Status,InstallLocation -autoSize
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName,Publisher,DisplayVersion,InstallLocation,UninstallString | Format-Table -AutoSize
sleep 1
}
''
subMenu1
} catch {
"Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
}
"7"{
ClearScreen
Write-Host 'Checking Which version of MS office is installed'
# To check MS office version, if it's 32bit or 64bit
$officeCheck = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration").platform
if($officeCheck -eq 'x64'){
Write-Host "Your computer have MS Office 64 bit" -ForegroundColor Green
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration" | Select-Object Platform,ProductReleaseIds,InstallationPath | Format-List
}
else{
Write-Host "Your computer have MS Office 32 bit." -ForegroundColor Green
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration" | Select-Object Platform,ProductReleaseIds,InstallationPath | Format-List
}
}
default {
Clear-Host
Write-Host 'Invalid selection please make another selection'
subMenu1
}
}
}# End of Sub Menu 1
function subMenu2{ # Start of Sub Menu 2
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-Host ' Setup Computer' -ForegroundColor Green
Write-Host ' '
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-host ' 0 To Exit' -ForegroundColor Yellow
Write-host ' B To Go Back' -ForegroundColor Yellow
Write-host ' S Start Over' -ForegroundColor Yellow
$submenu2 = @"
1. Rename Computer
2. Join to Domain
3. Add user to LocalAdmin
Make a selection:
"@
$userChoice = Read-Host -Prompt $submenu2
# Use a switch statement to perform different actions based on the selected option
switch ($userChoice){
"0" {
exitScript
}
"B" {
Write-Host "You selected to goback"
Clear-Host
MainMenu
}
"S" {
startOver
}
"1" { ClearScreen
"Renaming Computer"
$CurrentComputerName = $env:COMPUTERNAME
$NewComputerName = Read-Host "Enter the new computer name:"
Rename-Computer -NewName $NewComputerName -Restart -Force
if ($env:COMPUTERNAME -eq $NewComputerName) {
Write-Host "Successfully renamed the computer from $CurrentComputerName to $NewComputerName."
} else {
Write-Host "Failed to rename the computer."
}
''
subMenu2
}
"2" { ClearScreen
'Joining compter to Domain'
$cred = Get-Credential
$YourDomainName = Read-Host "Enter your Domain name:"
Add-Computer -DomainName $YourDomainName -Credential $cred
''
subMenu2
}
"3" { ClearScreen
'To Add user to Local Admin Group'
$UserName = Read-Host "Enter username to add to Local admin Group as domain\userName"
$LocalAdminGroup=Get-LocalGroupMember -Group 'Administrators' -Member $UserName -ErrorAction SilentlyContinue
if ($LocalAdminGroup){
Write-Host "$UserName is a member of the local administrator group."
}
else {
Write-Host "$UserName is not a member of the local administrator group. Adding now"
Add-LocalGroupMember -Group 'Administrators' -Member $UserName
}
''
subMenu2
}
default {
Clear-Host
Write-Host 'Invalid selection please make another selection'
subMenu2
}
}
} # End of Sub Menu 2
function subMenu3{ # Start of Sub Menu 3
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-Host ' Application Install' -ForegroundColor Green
Write-Host ' '
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-host ' 0 To Exit' -ForegroundColor Yellow
Write-host ' B To Go Back' -ForegroundColor Yellow
Write-host ' S Start Over' -ForegroundColor Yellow
$submenu3 = @"
1. Adobe Reader
2. Chrome browser
Make a selection:
"@
$userChoice = Read-Host -Prompt $submenu3
switch ($userChoice){
"0" {
exitScript
}
"B" {
Write-Host "You selected to goback"
Clear-Host
MainMenu
}
"S" {
startOver
}
"1" { ClearScreen
'Installing Adobe Reader'
Write-Host ""
Write-Host ' '
Write-Host 'Adobe Reader Installing please wait ... ' -ForegroundColor Yellow
$url= "https://ardownload2.adobe.com/pub/adobe/reader/win/AcrobatDC/2200320322/AcroRdrDC2200320322_en_US.exe"
$outpath = "$env:USERPROFILE\downloads\AcroRdrDC2200320322_en_US.exe"
Invoke-WebRequest -Uri $url -OutFile $outpath
Start-Process $outpath
''
subMenu3
}
"2" {ClearScreen
Write-Host 'Please wait while Chrome browser is installing'
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
$Path = $env:TEMP;
$Installer = "chrome_installer.exe"
Invoke-WebRequest "http://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $Path\$Installer
Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait
Remove-Item $Path\$Installer
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"Installed Google Chrome in $Elapsed sec"
subMenu3
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
''
subMenu3
}
default {
Clear-Host
Write-Host 'Invalid selection please make another selection'
subMenu3
}
}
} # End of Sub Menu 3
function subMenu4{ # Start of Sub Menu 4
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-Host ' Troubleshooting Tools ' -ForegroundColor Green
Write-Host ' '
Write-Host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Write-Host ' '
Write-host ' 0 To Exit' -ForegroundColor Yellow
Write-host ' B To Go Back' -ForegroundColor Yellow
Write-host ' S Start Over' -ForegroundColor Yellow
$submenu4 = @"
1. Close Microsoft Edge
2. Close Google Chrome
3. Open Task Manager
4. Open Control Pannel
5. Open Programs and Features
6. Restart Print spooler to help clear jam print job
7. Open System Properties
Make a selection:
"@
$userChoice = Read-Host -Prompt $submenu4
switch ($userChoice){
"0" {
exitScript
}
"b" {
Write-Host "You selected to goback"
Clear-Host
MainMenu
}
"S" {
startOver
}
"1" { ClearScreen
TaskKill /im msedge.exe /f /t
if ($lastExitCode -ne "0") {
Write-Host "Sorry, Microsoft Edge isn't running." -ForegroundColor Red
subMenu4
}
Write-Host ' '
Write-Host 'Microsoft Edge is closed' -ForegroundColor Green
''
subMenu4
}
"2" { ClearScreen
TaskKill /im chrome.exe /f /t
if ($lastExitCode -ne "0") {
Write-Host "Sorry, Google Chrome isn't running." -ForegroundColor Red
subMenu4
}
Write-Host ' '
Write-Host 'Google Chrome is closed' -ForegroundColor Green
''
subMenu4
}
"3" { ClearScreen
Write-Host ' '
Write-Host 'Opening Task Manager' -ForegroundColor Green
taskmgr
''
subMenu4
}
"4" { ClearScreen
Write-Host ' '
Write-Host 'Opening Control Pannel' -ForegroundColor Green
control
''
subMenu4
}
"5" { ClearScreen
Write-Host ' '
Write-Host 'Opening Programs and Features' -ForegroundColor Green
control
''
subMenu4
}
"6" { ClearScreen
Write-Host ' '
Write-Host 'Restarting Print spooler' -ForegroundColor Green
Restart-Service Spooler
''
subMenu4
}
"7"{ClearScreen
Write-Host ' '
Write-Host 'Opening System Properties'
sysdm.cpl
''
subMenu4
}
default {
Clear-Host
Write-Host 'Invalid selection please make selection'
subMenu4
}
}
} # End of Sub Menu 4
startOver
mainMenu