-
Notifications
You must be signed in to change notification settings - Fork 40
/
Automate-Module.psm1
2681 lines (2325 loc) · 132 KB
/
Automate-Module.psm1
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.SYNOPSIS
These PowerShell Functions will Install, Push, Uninstall, and Confirm ConnectWise Automate installations.
.DESCRIPTION
Functions Included:
Confirm-Automate
Uninstall-Automate
Install-Automate
Push-Automate
Show-LTErrors
Get-ADComputerNames
Scan-Network
New-IPRange
http://powershell.com/cs/media/p/9437.aspx
Invoke-Ping
https://gallery.technet.microsoft.com/scriptcenter/Invoke-Ping-Test-in-b553242a
Get-IPv4Subnet
https://github.com/briansworth/GetIPv4Address/blob/master/GetIPv4Subnet.psm1
.LINK
https://github.com/Braingears/PowerShell
.NOTES
File Name : Automate-Module.psm1
Author : Chuck Fowler (Chuck@Braingears.com)
Version : 1.0
Creation Date : 11/10/2019
Purpose/Change : Initial script development
Prerequisite : PowerShell V2
Version : 1.1
Date : 11/15/2019
Changes : Add $Automate.InstFolder and $Automate.InstRegistry and check for both to be consdered for $Automate.Installed
It was found that the Automate Uninstaller EXE is leaving behind the LabTech registry keys and it was not being detected properly.
.EXAMPLE
Confirm-Automate [-Silent]
Confirm-Automate [-Show]
.EXAMPLE
Uninstall-Automate [-Silent]
.EXAMPLE
Install-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token 'adb68881994ed93960346478303476f4' [-Show]
.Example
To push a single Automate Agent:
Push-Automate -Computer 'ComputerName' -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token 'adb68881994ed93960346478303476f4' -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd'
For multiple computers, use a | "pipe" into Push-Automate function:
$Computers | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token 'adb68881994ed93960346478303476f4' -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd'
- or -
Scan-Network | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token 'adb68881994ed93960346478303476f4' -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd'
- or -
Get-ADComputerNames | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token 'adb68881994ed93960346478303476f4' -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd'
- or -
"Computer1", "Computer2" | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token 'adb68881994ed93960346478303476f4' -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd'
#>
Function Confirm-Automate {
<#
.SYNOPSIS
This PowerShell Function will confirm if Automate is installed, services running, and checking-in.
.DESCRIPTION
This function will automatically start the Automate services (if stopped). It will collect Automate information from the registry.
.PARAMETER Raw
This will show the Automate registry entries
.PARAMETER Show
This will display $Automate object
.PARAMETER Silent
This will hide all output
.LINK
https://github.com/Braingears/PowerShell
.NOTES
Version : 1.0
Author : Chuck Fowler
Creation Date : 08/16/2019
Purpose/Change : Initial script development
Version : 1.1
Date : 11/15/2019
Changes : Add $Automate.InstFolder and $Automate.InstRegistry and check for both to be consdered for $Automate.Installed
It was found that the Automate Uninstaller EXE is leaving behind the LabTech registry keys and it was not being detected properly.
Version : 1.2
Date : 04/02/2020
Changes : Add $Automate.Service -eq $null
If the service still exists, the installation is failing with Exit Code 1638.
.EXAMPLE
Confirm-Automate [-Silent]
Confirm-Automate [-Show]
ServerAddress : https://yourserver.hostedrmm.com
ComputerID : 321
ClientID : 1
LocationID : 2
Version : 190.221
Service : Running
Online : True
LastHeartbeat : 29
LastStatus : 36
$Automate
$Global:Automate
This output will be saved to $Automate as an object to be used in other functions.
#>
[CmdletBinding(SupportsShouldProcess=$True)]
Param (
[switch]$Raw = $False,
[switch]$Show = $False,
[switch]$Silent = $False
)
$ErrorActionPreference = 'SilentlyContinue'
If ((Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").LastSuccessStatus) {
$Online = If ((Test-Path "HKLM:\SOFTWARE\LabTech\Service") -and ((Get-Service ltservice).status) -eq "Running") {((((Get-Date) - (Get-Date (Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").LastSuccessStatus)).TotalSeconds) -lt 600)} Else {Write $False}
} Else {$Online = $False}
If (Test-Path "HKLM:\SOFTWARE\LabTech\Service") {
$Global:Automate = New-Object -TypeName psobject
$Global:Automate | Add-Member -MemberType NoteProperty -Name ComputerName -Value $env:ComputerName
$Global:Automate | Add-Member -MemberType NoteProperty -Name ServerAddress -Value ((Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").'Server Address')
$Global:Automate | Add-Member -MemberType NoteProperty -Name ComputerID -Value ((Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").ID)
$Global:Automate | Add-Member -MemberType NoteProperty -Name ClientID -Value ((Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").ClientID)
$Global:Automate | Add-Member -MemberType NoteProperty -Name LocationID -Value ((Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").LocationID)
$Global:Automate | Add-Member -MemberType NoteProperty -Name Version -Value ((Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").Version)
$Global:Automate | Add-Member -MemberType NoteProperty -Name InstFolder -Value (Test-Path "$($env:windir)\ltsvc")
$Global:Automate | Add-Member -MemberType NoteProperty -Name InstRegistry -Value $True
$Global:Automate | Add-Member -MemberType NoteProperty -Name Installed -Value (Test-Path "$($env:windir)\ltsvc")
$Global:Automate | Add-Member -MemberType NoteProperty -Name Service -Value ((Get-Service LTService).Status)
$Global:Automate | Add-Member -MemberType NoteProperty -Name Online -Value $Online
If ((Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").HeartbeatLastSent) {
$Global:Automate | Add-Member -MemberType NoteProperty -Name LastHeartbeat -Value ([int]((Get-Date) - (Get-Date (Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").HeartbeatLastSent)).TotalSeconds)
}
If ((Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").LastSuccessStatus) {
$Global:Automate | Add-Member -MemberType NoteProperty -Name LastStatus -Value ([int]((Get-Date) - (Get-Date (Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service").LastSuccessStatus)).TotalSeconds)
}
Write-Verbose $Global:Automate
If ($Show) {
$Global:Automate
} Else {
If (!$Silent) {
Write "Server Address checking-in to $($Global:Automate.ServerAddress)"
Write "ComputerID: $($Global:Automate.ComputerID)"
Write "The Automate Agent Online $($Global:Automate.Online)"
Write "Last Successful Heartbeat $($Global:Automate.LastHeartbeat) seconds"
Write "Last Successful Status Update $($Global:Automate.LastStatus) seconds"
} # End Not Silent
} # End If
If ($Raw -eq $True) {Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service"}
} Else {
$Global:Automate = New-Object -TypeName psobject
$Global:Automate | Add-Member -MemberType NoteProperty -Name ComputerName -Value $env:ComputerName
$Global:Automate | Add-Member -MemberType NoteProperty -Name InstFolder -Value (Test-Path "$($env:windir)\ltsvc")
$Global:Automate | Add-Member -MemberType NoteProperty -Name InstRegistry -Value $False
$Global:Automate | Add-Member -MemberType NoteProperty -Name Installed -Value ((Test-Path "$($env:windir)\ltsvc") -and (Test-Path "HKLM:\SOFTWARE\LabTech\Service"))
$Global:Automate | Add-Member -MemberType NoteProperty -Name Service -Value ((Get-Service ltservice ).status)
$Global:Automate | Add-Member -MemberType NoteProperty -Name Online -Value $Online
Write-Verbose $Global:Automate
} #End if Registry Exists
If (!$Global:Automate.InstFolder -and !$Global:Automate.InstRegistry -and ($Global:Automate.Service -eq $Null)) {If ($Silent -eq $False) {Write "Automate is NOT Installed"}}
} #End Function Confirm-Automate
########################
Set-Alias -Name LTC -Value Confirm-Automate -Description 'Confirm if Automate is running properly'
########################
Function Uninstall-Automate {
<#
.SYNOPSIS
This PowerShell Function Uninstall Automate.
.DESCRIPTION
This function will download the Automate Uninstaller from Connectwise and completely remove the Automate / LabTech Agent.
.PARAMETER Silent
This will hide all output
.LINK
https://github.com/Braingears/PowerShell
.NOTES
Version : 1.0
Author : Chuck Fowler
Website : braingears.com
Creation Date : 8/2019
Purpose : Create initial function script
Version : 1.1
Date : 11/15/2019
Changes : Add $Automate.InstFolder and $Automate.InstRegistry and check for both to be consdered for $Automate.Installed
It was found that the Automate Uninstaller EXE is leaving behind the LabTech registry keys and it was not being detected properly.
If the LTSVC Folder or Registry keys are found after the uninstaller runs, the script now performs a manual gutting via PowerShell.
Version : 1.2
Date : 04/02/2020
Changes : Add $Automate.Service -eq $null
If the service still exists, the installation is failing with Exit Code 1638.
.EXAMPLE
Uninstall-Automate [-Silent]
#>
[CmdletBinding(SupportsShouldProcess=$True)]
Param (
[switch]$Force,
[switch]$Raw,
[switch]$Show,
[switch]$Silent = $False
)
$ErrorActionPreference = 'SilentlyContinue'
$Verbose = If ($PSBoundParameters.Verbose -eq $True) { $True } Else { $False }
$DownloadPath = "https://s3.amazonaws.com/assets-cp/assets/Agent_Uninstall.exe"
If ((([Int][System.Environment]::OSVersion.Version.Build) -gt 6000) -and ((get-host).Version.ToString() -ge 3)) {
$DownloadPath = "https://s3.amazonaws.com/assets-cp/assets/Agent_Uninstall.exe"
} Else {
$DownloadPath = "http://s3.amazonaws.com/assets-cp/assets/Agent_Uninstall.exe"
}
$SoftwarePath = "C:\Support\Automate"
$UninstallApps = @(
"ConnectWise Automate Remote Agent"
"LabTech® Software Remote Agent"
)
Write-Debug "Checking if Automate Installed"
Confirm-Automate -Silent -Verbose:$Verbose
If (($Global:Automate.InstFolder) -or ($Global:Automate.InstRegistry) -or (!($Global:Automate.Service -eq $Null)) -or ($Force)) {
$Filename = [System.IO.Path]::GetFileName($DownloadPath)
$SoftwareFullPath = "$($SoftwarePath)\$Filename"
If (!(Test-Path $SoftwarePath)) {New-Item -Path $SoftwarePath -ItemType Directory | Out-Null}
Set-Location $SoftwarePath
If ((Test-Path $SoftwareFullPath)) {Remove-Item $SoftwareFullPath | Out-Null}
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($DownloadPath, $SoftwareFullPath)
If (!$Silent) {Write-Host "Removing Existing Automate Agent..."}
Write-Verbose "Closing Open Applications and Stopping Services"
Stop-Process -Name "ltsvcmon","lttray","ltsvc","ltclient" -Force
Stop-Service ltservice,ltsvcmon -Force
$UninstallExitCode = (Start-Process "cmd" -ArgumentList "/c $($SoftwareFullPath)" -NoNewWindow -Wait -PassThru).ExitCode
If (!$Silent) {
If ($UninstallExitCode -eq 0) {
# Write-Host "The Automate Agent Uninstaller Executed Without Errors" -ForegroundColor Green
Write-Verbose "The Automate Agent Uninstaller Executed Without Errors"
} Else {
Write-Host "Automate Uninstall Exit Code: $($UninstallExitCode)" -ForegroundColor Red
Write-Verbose "Automate Uninstall Exit Code: $($UninstallExitCode)"
}
}
Write-Verbose "Checking For Removal - Loop 5X"
$Counter = 0
While ($Counter -ne 6) {
$Counter++
Start-Sleep 10
Confirm-Automate -Silent -Verbose:$Verbose
If ((!$Global:Automate.InstFolder) -and (!$Global:Automate.InstRegistry) -and ($Global:Automate.Service -eq $Null)) {
Write-Verbose "Automate Uninstaller Completed Successfully"
Break
}
}# End While
If (($Global:Automate.InstFolder) -or ($Global:Automate.InstRegistry) -or (!($Global:Automate.Service -eq $Null))) {
Write-Verbose "Uninstaller Failed"
Write-Verbose "Manually Gutting Automate..."
If (!(($Global:Automate.Service -eq $Null) -or ($Global:Automate.Service -eq "Stopped"))) {
Write-Verbose "LTService Service not Stopped. Disabling LTService Service"
Set-Service ltservice -StartupType Disabled
Stop-Service ltservice,ltsvcmon -Force
}
Stop-Process -Name "ltsvcmon","lttray","ltsvc","ltclient" -Force
Write-Verbose "Uninstalling LabTechAD Package"
$UninstallApps2 = foreach ($App in $UninstallApps) {Get-WmiObject -Class Win32_Product -ComputerName . | Where-Object -FilterScript {$_.Name -like $App} | Select-Object -ExpandProperty "Name"}
$UninstallAppsFound = $UninstallApps2 | Select-Object -Unique
foreach ($App in $UninstallAppsFound) {
$AppLocalPackage = Get-WmiObject -Class Win32_Product -ComputerName . | Where-Object -FilterScript {$_.Name -like $App} | Select-Object -ExpandProperty "LocalPackage"
If ($AppLocalPackage -eq $null) {
Write-Verbose "$($App) - Not Installed"
} Else {
Write-Verbose "Uninstalling: $($App) - msiexec /x $($AppLocalPackage) /qn /norestart"
msiexec /x $AppLocalPackage /qn /norestart
}
}
Remove-Item "$($env:windir)\ltsvc" -Recurse -Force
Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service" | Remove-Item -Recurse -Force
REG Delete HKLM\SOFTWARE\LabTech\Service /f | Out-Null
Start-Process "cmd" -ArgumentList "/c $($SoftwareFullPath)" -NoNewWindow -Wait -PassThru | Out-Null
Confirm-Automate -Silent -Verbose:$Verbose
If ($Global:Automate.InstFolder) {
If (!$Silent) {
Write-Host "Automate Uninstall Failed" -ForegroundColor Red
Write-Host "$($env:windir)\ltsvc folder still exists" -ForegroundColor Red
} Else {
Write-Verbose "Automate Uninstall Failed"
Write-Verbose "$($env:windir)\ltsvc folder still exists"
}
}
If ($Global:Automate.InstRegistry) {
If (!$Silent) {
Write-Host "Automate Uninstall Failed" -ForegroundColor Red
Write-Host "HKLM:\SOFTWARE\LabTech\Service Registry keys still exists" -ForegroundColor Red
} Else {
Write-Verbose "Automate Uninstall Failed"
Write-Verbose "HKLM:\SOFTWARE\LabTech\Service Registry keys still exists"
}
}
If (!($Global:Automate.Service -eq $Null)) {
If (!$Silent) {
Write-Host "Automate Uninstall Failed" -ForegroundColor Red
Write-Host "LTService Service still exists" -ForegroundColor Red
} Else {
Write-Verbose "Automate Uninstall Failed"
Write-Verbose "LTService Service still exists"
}
}
} Else {
If (!$Silent) {Write-Host "The Automate Agent Uninstalled Successfully" -ForegroundColor Green}
Write-Verbose "The Automate Agent Uninstalled Successfully"
}
} # If Test Install
Confirm-Automate -Silent:$Silent
} # Function Uninstall-Automate
########################
Set-Alias -Name LTU -Value Uninstall-Automate -Description 'Uninstall Automate Agent'
########################
Function Install-Automate {
<#
.SYNOPSIS
This PowerShell Function is for Automate Deployments
.DESCRIPTION
Install the Automate Agent.
This function will qualify the if another Autoamte agent is already
installed on the computer. if the existing agent belongs to dIfferent
Automate server, it will automatically "Rip & Replace" the existing
agent. This comparison is based on the server's FQDN.
This function will also verify if the existing Automate agent is
checking-in. The Confirm-Automate Function will verify the Server
address, LocationID, and Heartbeat/Check-in. If these entries are
missing or not checking-in properly; this function will automatically
attempt to restart the services, and then "Rip & Replace" the agent to
remediate the agent.
$Automate
$Global:Automate
The output will be saved to $Automate as an object to be used in other functions.
Example:
Install-Automate -Server YOURSERVER.DOMAIN.COM -LocationID 2 -Token 'adb68881994ed93960346478303476f4' -Transcript
Tested OS: Windows XP (with .Net 3.5.1 and PowerShell installed)
Windows Vista
Windows 7
Windows 8
Windows 10
Windows 2003R2
Windows 2008R2
Windows 2012R2
Windows 2016
Windows 2019
.PARAMETER Server
This is the URL to your Automate server.
Install-Automate -Server 'server.hostedrmm.com' -LocationID 2 -Token 'adb68881994ed93960346478303476f4'
.PARAMETER LocationID
Use LocationID to install the Automate Agent directly to the appropieate client's location / site.
If parameter is not specified, it will automatically assign LocationID 1 (New Computers).
.PARAMETER Token
Use Token to install the Automate Agent directly to the appropieate client's location / site.
If parameter is not specified, it will automatically attempt to use direct unauthenticated downloads.
This method in blocked after Automate v20.0.6.178 (Patch 6)
.PARAMETER Force
This will force the Automate Uninstaller prior to installation.
Essentually, this will be a fresh install and a fresh check-in to the Automate server.
Install-Automate -Server 'server.hostedrmm.com' -LocationID 2 -Token 'adb68881994ed93960346478303476f4' -Force
.PARAMETER Silent
This will hide all output (except a failed installation when Exit Code -ne 0)
The function will exit once the installer has completed.
Install-Automate -Server 'server.hostedrmm.com' -LocationID 2 -Token 'adb68881994ed93960346478303476f4' -Silent
.PARAMETER Transcript
This parameter will save the entire transcript and responsed to:
$($env:windir)\Temp\AutomateLogon.txt
Install-Automate -Server 'server.hostedrmm.com' -LocationID 2 -Token 'adb68881994ed93960346478303476f4' -Transcript -Verbose
.LINK
https://github.com/Braingears/PowerShell
.NOTES
Version : 1.0
Author : Chuck Fowler
Creation Date : 08/2019
Purpose/Change : Initial script development
Version : 1.1
Date : 11/15/2019
Changes : Add $Automate.InstFolder and $Automate.InstRegistry and check for both to be consdered for $Automate.Installed
It was found that the Automate Uninstaller EXE is leaving behind the LabTech registry keys and it was not being detected properly.
If the LTSVC Folder or Registry keys are found after the uninstaller runs, the script now performs a manual gutting via PowerShell.
Version : 1.2
Date : 02/17/2020
Changes : Add MSIEXEC Log Files to C:\Windows\Temp\Automate_Agent_(Date).log
Version : 1.3
Date : 05/26/2020
Changes : Look for and replace "Enter the server address here" with the actual Automate Server address.
Version : 1.4
Date : 06/29/2020
Changes : Added Token Parameter for Deployment
Version : 1.5
Date : 06/09/2021
Changes : Attempt to Restart the LTService prior to R&R
It was found that the Rip & Replace was being too aggressive without at least trying to restart the LTService
and waiting for it to check-in.
Version : 1.6
Date : 02/02/2022
Changes : Add -SystemPassword Parameter
There are known issues with the MSI's Digital Certificate when the web portal embeds the Server, LocationID, and System Password metadata.
When you use the -SystemPassword Parameter, a different MSI URL is used (prior to the metadata being embeded into the MSI), and the
Server Address, LocationID, and System Password is assigned as paramters in the MSIExec installation string.
Version : 1.7
Date : 08/02/2024
Changes : Change -Token download from MSI to Zip due to changes in Automate Patch v24.7
The agent download no longer embeds the Server, Location, and Password in the MSI due to breaking the MSI's Digital Certificate. The default
download is now ZIP which has to be extracted to MSI and MST.
.EXAMPLE
Install-Automate -Server 'automate.domain.com' -LocationID 42 -Token 'adb68881994ed93960346478303476f4'
This will install the LabTech agent using the provided Server URL, LocationID, and required Token.
.EXAMPLE
Install-Automate -Server 'automate.domain.com' -LocationID 42 -SystemPassword 'ABCDEF12345678'
This will install the LabTech agent using the provided Server URL, LocationID, and required System Password.
#>
[CmdletBinding(SupportsShouldProcess=$True)]
Param(
[Parameter(ValueFromPipelineByPropertyName = $True, Position=0)]
[Alias("FQDN","Srv")]
[string[]]$Server = $Null,
[Parameter(ValueFromPipelineByPropertyName = $True, Position=1)]
[AllowNull()]
[Alias('LID','Location')]
[int]$LocationID = '1',
[Parameter(ValueFromPipelineByPropertyName = $True, Position=2)]
[Alias("InstallerToken")]
[string[]]$Token = $Null,
[Parameter(ValueFromPipelineByPropertyName = $True, Position=3)]
[Alias("Password","SystemPassword","SysPass")]
[string[]]$SystemPass = $Null,
[switch]$Force,
[Parameter()]
[AllowNull()]
[switch]$Show = $False,
[switch]$Silent,
[Parameter()]
[AllowNull()]
[switch]$Transcript = $False
)
$ErrorActionPreference = 'SilentlyContinue'
$Verbose = If ($PSBoundParameters.Verbose -eq $True) { $True } Else { $False }
$Error.Clear()
If ($Transcript) {Start-Transcript -Path "$($env:windir)\Temp\Automate_Deploy.txt" -Force}
$SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol
$SoftwarePath = "C:\Support\Automate"
$Filename = "Automate_Agent.msi"
$SoftwareFullPath = "$SoftwarePath\$Filename"
$AutomateURL = "https://$($Server)"
#Check for Cisco AnyConnect VPN / Known Conflict
Write-Verbose "Checking for known conflicts"
$AnyConnectVPNInstalled = Test-Path "$(${env:ProgramFiles(x86)})\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe"
If ($AnyConnectVPNInstalled) {
Write-Host "WARNING - Cisco AnyConnect VPN has been found installed on this computer" -ForegroundColor Red
Write-Host "WARNING - This may cause multiple computers to check-in to the same ComputerID" -ForegroundColor Red
Set-Location "$(${env:ProgramFiles(x86)})\Cisco\Cisco AnyConnect Secure Mobility Client"
$AnyConnectVPNConnection = (.\vpncli.exe status)
IF ($AnyConnectVPNConnection -like "*state: Connected*") {
Write-Host "WARNING - Cisco AnyConnect VPN is ACTIVE" -ForegroundColor Red
} Else {
Write-Verbose "Cisco AnyConnect VPN is NOT ACTIVE"
}
} Else {
Write-Verbose "Cisco AnyConnect VPN is not installed"
}
Write-Verbose "Checking Operating System (WinXP and Older)"
If ([int]((Get-WmiObject Win32_OperatingSystem).BuildNumber) -lt 6000) {
$OS = ((Get-WmiObject Win32_OperatingSystem).Caption)
Write-Host "This computer is running $($OS), and is no longer officially supported by ConnectWise Automate" -ForegroundColor Red
Write-Host "https://docs.connectwise.com/ConnectWise_Automate/ConnectWise_Automate_Supportability_Statements/Supportability_Statement:_Windows_XP_and_Server_2003_End_of_Life" -ForegroundColor Red
Write-Host ""
$AutomateURL = "https://$($Server)"
}
Try {
Write-Verbose "Enabling downloads to use SSL/TLS v1.2"
[Net.ServicePointManager]::SecurityProtocol = [Enum]::ToObject([Net.SecurityProtocolType], 3072)
}
Catch {
Write-Verbose "Failed to enable SSL/TLS v1.2"
Write-Host "This computer is not configured for SSL/TLS v1.2" -ForegroundColor Red
Write-Host "https://docs.connectwise.com/ConnectWise_Automate/ConnectWise_Automate_Supportability_Statements/Supportability_Statement:_TLS_1.0_and_1.1_Protocols_Unsupported" -ForegroundColor Red
Write-Host ""
$AutomateURL = "https://$($Server)"
}
Try {
$AutomateURLTest = "$($AutomateURL)/LabTech/"
$TestURL = (New-Object Net.WebClient).DownloadString($AutomateURLTest)
Write-Verbose "$AutomateURL is Active"
}
Catch {
Write-Verbose "Could not download from $($AutomateURL). Switching to http://$($Server)"
$AutomateURL = "http://$($Server)"
}
Confirm-Automate -Silent -Verbose:$Verbose
If (($Global:Automate.Service -eq 'Stopped') -and ($Global:Automate.ServerAddress -like "*$Server*") -and !($Force)) {
Try {
Write-Verbose "LTService service is Stopped"
Write-Verbose "LTService service is Restarting"
Start-Service LTService -ErrorAction Stop
}
Catch {
Write-Verbose "LTService service Restart Failed"
}
If ((Get-Service LTService).Status -eq "Running") {
Write-Verbose "LTService was successfully Restarted"
Write-Verbose "Now waiting for the Automate Agent to attempt to check-in - Loop 10X"
$Count = 0
While ($Count -ne 10) {
$Count++
sc.exe control LTService 136 | Out-Null
Start-Sleep 6
Confirm-Automate -Silent -Verbose:$Verbose
If ($Global:Automate.Online) {
If (!$Silent) {Write-Host "LTService service was successfully Restarted"}
Break
}
}# End While
} Else {
Write-Verbose "LTService service did not return to a running status"
}
} # If LTService is Stopped
Write-Verbose "Checking if server address matches and if Automate Agent is Online"
Write-Verbose (($Global:Automate.ServerAddress -like "*$Server*") -and $Global:Automate.Online -and !$Force)
If (($Global:Automate.ServerAddress -like "*$($Server)*") -and $Global:Automate.Online -and !$Force) {
If (!$Silent) {
If ($Show) {
$Global:Automate
} Else {
Write-Host "The Automate Agent is already installed on $($Global:Automate.Computername) ($($Global:Automate.ComputerID)) and checked-in $($Global:Automate.LastStatus) seconds ago to $($Global:Automate.ServerAddress)" -ForegroundColor Green
}
}
} Else {
If (!$Silent -and $Global:Automate.Online -and (!($Global:Automate.ServerAddress -like "*$($Server)*"))) {
Write-Host "The Existing Automate Server Does Not Match The Target Automate Server." -ForegroundColor Red
Write-Host "Current Automate Server: $($Global:Automate.ServerAddress)" -ForegroundColor Red
Write-Host "New Automate Server: $($AutomateURL)" -ForegroundColor Green
} # If Different Server
Write-Verbose "Downloading Automate Agent from $($AutomateURL)"
If (!(Test-Path $SoftwarePath)) {New-Item -Path $SoftwarePath -ItemType Directory | Out-Null}
Set-Location $SoftwarePath
# If SystemPass, download MSI. If -Token, download ZIP and extract.
If ($SystemPass -ne $Null) {
$DownloadPath = "$($AutomateURL)/Labtech/Service/LabTechRemoteAgent.msi"
$Filename = "Automate_Agent.msi"
$SoftwareFullPath = "$SoftwarePath\$Filename"
If ((Test-Path $SoftwareFullPath)) {Remove-Item $SoftwareFullPath | Out-Null}
Try {
Write-Verbose "Downloading from: $($DownloadPath)"
Write-Verbose "Downloading to: $($SoftwareFullPath)"
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($DownloadPath, $SoftwareFullPath)
Write-Verbose "Download Complete"
}
Catch {
Write-Host "The Automate Server was inaccessible. Failed to Download:" -ForegroundColor Red
Write-Host $DownloadPath -ForegroundColor Red
Write-Host "Help: Get-Help Install-Automate -Full"
Write-Host "Exiting Installation..."
Break
}
} ElseIf ($Token -ne $Null) {
$DownloadPath = "$($AutomateURL)/Labtech/Deployment.aspx?InstallerToken=$Token"
$DownloadFilename = "Agent_Install.zip"
$DownloadFullPath = "$SoftwarePath\$DownloadFilename"
$Filename = "Agent_Install.msi"
$SoftwareFullPath = "$SoftwarePath\$Filename"
If ((Test-Path $DownloadFullPath)) {Remove-Item $DownloadFullPath | Out-Null}
Try {
Write-Verbose "Downloading from: $($DownloadPath)"
Write-Verbose "Downloading to: $($DownloadFullPath)"
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($DownloadPath, $DownloadFullPath)
Write-Verbose "Download Complete"
}
Catch {
Write-Host "The Automate Server was inaccessible or the Token Parameters were not entered or valid. Failed to Download:" -ForegroundColor Red
Write-Host $DownloadPath -ForegroundColor Red
Write-Host "Help: Get-Help Install-Automate -Full"
Write-Host "Exiting Installation..."
Break
}
Try {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::OpenRead($DownloadFullPath).Entries.FullName | Remove-Item -Force -ErrorAction SilentlyContinue | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory($DownloadFullPath, $SoftwarePath)
Write-Verbose "Extracting $($DownloadFilename) to $($SoftwarePath)"
}
Catch {
Write-Host "The files could not be extracted from ZIP"
Write-Host "Confirm that you've upgraded to Automate Patch 24.7"
Break
}
} Else {
Write-Verbose "A -Token <String[]> was not entered"
$DownloadPath = "$($AutomateURL)/Labtech/Deployment.aspx?Probe=1&installType=msi&MSILocations=$($LocationID)"
$Filename = "Automate_Agent.msi"
$SoftwareFullPath = "$SoftwarePath\$Filename"
Try {
Write-Verbose "Downloading from (Old): $($DownloadPath)"
Write-Verbose "Downloading to: $($SoftwareFullPath)"
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($DownloadPath, $SoftwareFullPath)
Write-Verbose "Download Complete"
}
Catch {
Write-Host "The Automate Server was inaccessible. Failed to Download:" -ForegroundColor Red
Write-Host $DownloadPath -ForegroundColor Red
Write-Host "Help: Get-Help Install-Automate -Full"
Write-Host "Exiting Installation..."
Break
}
}
Write-Verbose "Removing Existing Automate Agent"
Uninstall-Automate -Force:$Force -Silent:$Silent -Verbose:$Verbose
If (!$Silent) {Write-Host "Installing Automate Agent to $AutomateURL"}
Stop-Process -Name "ltsvcmon","lttray","ltsvc","ltclient" -Force -PassThru
$Date = (Get-Date -UFormat %Y-%m-%d_%H-%M-%S)
$LogFullPath = "$env:windir\Temp\Automate_Agent_$Date.log"
If ($SystemPass -ne $Null) {
$InstallExitCode = (Start-Process "msiexec.exe" -ArgumentList "/i $($SoftwareFullPath) /quiet /norestart LOCATION=$($LocationID) SERVERADDRESS=$($AutomateURL) SERVERPASS=$($SystemPass) /L*V $($LogFullPath)" -NoNewWindow -Wait -PassThru).ExitCode
} Else {
$InstallExitCode = (Start-Process 'msiexec.exe' -ArgumentList "/i $($SoftwareFullPath) TRANSFORMS=$($SoftwarePath)\Agent_Install.mst /quiet /norestart LOCATION=$($LocationID) SERVERADDRESS=$($AutomateURL) /L*V $($LogFullPath)" -NoNewWindow -Wait -PassThru).ExitCode
[System.IO.Compression.ZipFile]::OpenRead($DownloadFullPath).Entries.FullName | Remove-Item -Force -ErrorAction SilentlyContinue | Out-Null
}
Write-Verbose "MSIEXEC Log Files: $LogFullPath"
If ($InstallExitCode -eq 0) {
If (!$Silent) {Write-Verbose "The Automate Agent Installer Executed Without Errors"}
} Else {
Write-Host "Automate Installer Exit Code: $InstallExitCode" -ForegroundColor Red
Write-Host "Automate Installer Logs: $LogFullPath" -ForegroundColor Red
Write-Host "The Automate MSI failed. Waiting 15 Seconds..." -ForegroundColor Red
Start-Sleep -s 15
Write-Host "Installer will execute twice (KI 12002617)" -ForegroundColor Yellow
$Date = (Get-Date -UFormat %Y-%m-%d_%H-%M-%S)
$LogFullPath = "$env:windir\Temp\Automate_Agent_$Date.log"
If ($SystemPass -ne $Null) {
$InstallExitCode = (Start-Process "msiexec.exe" -ArgumentList "/i $($SoftwareFullPath) /quiet /norestart LOCATION=$($LocationID) SERVERADDRESS=$($AutomateURL) SERVERPASS=$($SystemPass) /L*V $($LogFullPath)" -NoNewWindow -Wait -PassThru).ExitCode
} Else {
$InstallExitCode = (Start-Process 'msiexec.exe' -ArgumentList "/i $($SoftwareFullPath) TRANSFORMS=$($SoftwarePath)\Agent_Install.mst /quiet /norestart LOCATION=$($LocationID) SERVERADDRESS=$($AutomateURL) /L*V $($LogFullPath)" -NoNewWindow -Wait -PassThru).ExitCode
}
Write-Host "Automate Installer Exit Code: $InstallExitCode" -ForegroundColor Yellow
Write-Host "Automate Installer Logs: $LogFullPath" -ForegroundColor Yellow
}# End Else
If ($InstallExitCode -eq 0) {
$Counter = 0
While ($Counter -ne 30) {
$Counter++
Start-Sleep 10
Confirm-Automate -Silent -Verbose:$Verbose
If ($Global:Automate.Server -like "Enter the server address here*") {
Write-Verbose "The Automate Server Address was not written properly"
Write-Verbose "Manually overwriting the Server Address to: $($AutomateURL)"
Set-ItemProperty -Path "HKLM:\SOFTWARE\LabTech\Service" -Name 'Server Address' -Value $AutomateURL -Force
Write-Verbose "Restarting LTService after correcting the Server Address"
Get-Service LTService | Where {$_.Status -eq "Running"} | Restart-Service -Force
Confirm-Automate -Silent -Verbose:$Verbose
}
$FailedSignup = Select-String -Path "$env:windir\LTSvc\LTErrors.txt" -Pattern "Failed Signup"
If ($FailedSignup -ne $Null) {
If (!$Silent) {
Write-Host "The Automate Agent FAILED SIGNUP" -ForegroundColor Red
} Else {
Write-Verbose "The Automate Agent FAILED SIGNUP"
}
Break
}
If ($Global:Automate.Online -and $Global:Automate.ComputerID -ne $Null) {
If (!$Silent) {
Write-Host "The Automate Agent Has Been Successfully Installed" -ForegroundColor Green
$Global:Automate
}#End If Silent
Break
} # End If
} # End While
} Else {
$Counter = 0
While ($Counter -ne 3) {
$Counter++
Start-Sleep 10
Confirm-Automate -Silent -Verbose:$Verbose
If ($Global:Automate.Server -like "Enter the server address here*") {
Write-Verbose "The Automate Server Address was not written properly"
Write-Verbose "Manually overwriting the Server Address to: $($AutomateURL)"
Set-ItemProperty -Path "HKLM:\SOFTWARE\LabTech\Service" -Name 'Server Address' -Value $AutomateURL -Force
Write-Verbose "Restarting LTService after correcting the Server Address"
Get-Service LTService | Where {$_.Status -eq "Running"} | Restart-Service -Force
Confirm-Automate -Silent -Verbose:$Verbose
}
If ($Global:Automate.Online -and $Global:Automate.ComputerID -ne $Null) {
If (!$Silent) {
Write-Host "The Automate Agent Has Been Successfully Installed" -ForegroundColor Green
$Global:Automate
}#End If Silent
Break
} # End If
} # End While
} # End If ExitCode 0
Confirm-Automate -Silent -Verbose:$Verbose
If (($SystemPass -ne $Null) -and ($Global:Automate.ComputerID -eq $Null)) {
If (!$Silent) {
Write-Host "The Automate Agent FAILED to Install" -ForegroundColor Red
Write-Host "Check the Automate System Password, then Uninstall / Reinstall Automate Agent again" -ForegroundColor Red
$Global:Automate
} Else {
Write-Verbose "The Automate Agent FAILED to Install"
Write-Verbose "Check the Automate System Password"
}
} ElseIf (!($Global:Automate.Online -and $Global:Automate.ComputerID -ne $Null)) {
If (!$Silent) {
Write-Host "The Automate Agent FAILED to Install" -ForegroundColor Red
$Global:Automate
} Else {
Write-Verbose "The Automate Agent FAILED to Install"
}
} # End if Not Online
} # End
If ($Transcript) {Stop-Transcript}
} # End Function Install-Automate
########################
Set-Alias -Name LTI -Value Install-Automate -Description 'Install Automate Agent'
########################
Function Push-Automate
{
<#
.SYNOPSIS
This PowerShell Function is for pushing Automate Deployments
.DESCRIPTION
Install the Automate Agent.
This function will qualify the if another Autoamte agent is already
installed on the computer. If the existing agent belongs to different
Automate server, it will automatically "Rip & Replace" the existing
agent. This comparison is based on the server's FQDN.
This function will also verify if the existing Automate agent is
checking-in. The Confirm-Automate Function will verify the Server
address, LocationID, and Heartbeat/Check-in. If these entries are
missing or not checking-in properly; this function will automatically
attempt to restart the services, and then "Rip & Replace" the agent to
remediate the agent.
$AutoResults
$Global:AutoResults
The output will be saved to $AutoResults as an object to be used in other functions.
Example:
To push a single Automate Agent:
Push-Automate -Computer 'Computername' -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token adb68881994ed93960346478303476f4 -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd'
For multiple computers, use a | "pipe" into Push-Automate function:
$Computers | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token adb68881994ed93960346478303476f4 -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd'
- or -
Get-ADComputerNames | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token adb68881994ed93960346478303476f4 -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd'
- or -
"Computer1", "Computer2" | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token adb68881994ed93960346478303476f4 -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd'
When pushing to multiple computers, use the actual computer names. If you use IP Address, it will fail when using WINRM Protocols (and use WMI/RCP instead).
.PARAMETER Server
This is the URL to your Automate server.
Install-Automate -Server 'server.hostedrmm.com' -LocationID 2
.PARAMETER LocationID
Use LocationID to install the Automate Agent directly to the appropieate client's location / site.
If parameter is not specified, it will automatically assign LocationID 1 (New Computers).
Install-Automate -Server 'server.hostedrmm.com' -LocationID 2 -Token adb68881994ed93960346478303476f4
.PARAMETER Username
Enter username with Domain Admin rights. When entering username, use 'DOMAIN\USERNAME'
The function will accept PSCredentials saved to $Credentials prior to running this function.
.PARAMETER Password
Enter Password for Domain Admin account.
The function will accept PSCredentials saved to $Credentials prior to running this function.
.PARAMETER Force
>>> This Function Is Currently Disabled <<<
This will force the Automate Uninstaller prior to installation.
Essentually, this will be a fresh install and a fresh check-in to the Automate server.
Install-Automate -Server 'server.hostedrmm.com' -LocationID 2 -Token adb68881994ed93960346478303476f4 -Force
.PARAMETER Silent
>>> This Function Is Currently Disabled <<<
This will hide all output (except a failed installation when Exit Code -ne 0)
The function will exit once the installer has completed.
Install-Automate -Server 'server.hostedrmm.com' -LocationID 2 -Token adb68881994ed93960346478303476f4 -Silent
.PARAMETER Transcript
>>> This Function Is Currently Disabled <<<
This parameter will save the entire transcript and responsed to:
$($env:windir)\Temp\AutomateLogon.txt
Install-Automate -Server 'server.hostedrmm.com' -LocationID 2 -Token adb68881994ed93960346478303476f4 -Transcript -Verbose
.LINK
https://github.com/Braingears/PowerShell
.NOTES
Version : 1.0
Author : Chuck Fowler
Creation Date : 08/2019
Purpose/Change : Initial script development
Version : 1.1
Date : 11/15/2019
Changes : Add $Automate.InstFolder and $Automate.InstRegistry and check for both to be consdered for $Automate.Installed
It was found that the Automate Uninstaller EXE is leaving behind the LabTech registry keys and it was not being detected properly.
If the LTSVC Folder or Registry keys are found after the uninstaller runs, the script now performs a manual gutting via PowerShell.
.EXAMPLE
Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd' -Token adb68881994ed93960346478303476f4 -Computer COMPUTERNAME
Use the -Computer parameter for single computers.
.EXAMPLE
$Computers | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd' -Token adb68881994ed93960346478303476f4
Use Array to pipe multiple computers into Push=Automate function.
.EXAMPLE
Get-ADComputerNames | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd' -Token adb68881994ed93960346478303476f4
Use another function to pipe multiple computers into Push=Automate function. Select only computer names.
.EXAMPLE
"Computer1", "Computer2" | Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Username 'DOMAIN\USERNAME' -Password 'Ch@ng3P@ssw0rd' -Token adb68881994ed93960346478303476f4
When pushing to multiple computers, use the actual computer names. If you use IP Address, it will fail when using WINRM Protocols (and use WMI/RCP instead).
This will install the LabTech agent using the provided Server URL, and LocationID.
.EXAMPLE
$Credential = Get-Credential
Push-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Token adb68881994ed93960346478303476f4
You can proactivly load PSCredential, then use the Push-Automate function within the same Powershell session.
#>
[CmdletBinding()]
Param
(
[Parameter(ValueFromPipeline=$True)]
[string[]]$Computer = $env:COMPUTERNAME,
[Parameter()]
[Alias("FQDN","Srv")]
[string[]]$Server = $Null,
[Parameter()]
[AllowNull()]
[Alias('LID','Location')]
[int]$LocationID = '1',
[Parameter()]
[Alias("InstallerToken")]
[string[]]$Token = $Null,
[Parameter()]
[AllowNull()]
[Alias('User')]
[string[]]$Username,
[Parameter()]
[AllowNull()]
[Alias('Pass')]
[string[]]$Password,
[Parameter()]
[AllowNull()]
[switch]$Force = $False,
[Parameter()]
[AllowNull()]
[switch]$Show = $False,
[Parameter()]
[AllowNull()]
[switch]$Silent = $False,
[Parameter()]
[AllowNull()]
[switch]$Transcript = $False
)
BEGIN
{
$ErrorActionPreference = "SilentlyContinue"
$Verbose = If ($PSBoundParameters.Verbose -eq $True) { $True } Else { $False }
$AutomateURL = "https://$($Server)"
Write-Verbose "Checking Operating System"
If ([int]((Get-WmiObject Win32_OperatingSystem).BuildNumber) -lt 6000) {
$OS = ((Get-WmiObject Win32_OperatingSystem).Caption)
Write-Host "This computer is running $($OS), and is no longer officially supported by ConnectWise Automate" -ForegroundColor Red
Write-Host "https://docs.connectwise.com/ConnectWise_Automate/ConnectWise_Automate_Supportability_Statements/Supportability_Statement:_Windows_XP_and_Server_2003_End_of_Life" -ForegroundColor Red
Write-Host ""
$AutomateURL = "https://$($Server)"
}
Try {
Write-Verbose "Enabling downloads to use SSL/TLS v1.2"
[Net.ServicePointManager]::SecurityProtocol = [Enum]::ToObject([Net.SecurityProtocolType], 3072)
}
Catch {
Write-Verbose "Failed to enable SSL/TLS v1.2"
Write-Host "This computer is not configured for SSL/TLS v1.2" -ForegroundColor Red
Write-Host "https://docs.connectwise.com/ConnectWise_Automate/ConnectWise_Automate_Supportability_Statements/Supportability_Statement:_TLS_1.0_and_1.1_Protocols_Unsupported" -ForegroundColor Red
Write-Host ""
$AutomateURL = "https://$($Server)"
}
Try {
$AutomateURLTest = "$($AutomateURL)/LabTech/"
$TestURL = (New-Object Net.WebClient).DownloadString($AutomateURLTest)
Write-Verbose "$AutomateURL is Active"
}
Catch {
Write-Verbose "Could not download from $($AutomateURL). Switching to http://$($Server)"
$AutomateURL = "http://$($Server)"
}
$DownloadPath = $null
If ($Token -ne $null) {
$DownloadPath = "$($AutomateURL)/Labtech/Deployment.aspx?InstallerToken=$Token"
Write-Verbose "Downloading from: $($DownloadPath)"
}
Else {
Write-Verbose "A -Token <String[]> was not entered"
$DownloadPath = "$($AutomateURL)/Labtech/Deployment.aspx?Probe=1&installType=msi&MSILocations=$($LocationID)"
Write-Verbose "Downloading from (Old): $($DownloadPath)"
}
$Whoami = whoami
Write-Verbose "Running Script as: $whoami"
If (($Username -eq $Null) -and ($Password -eq $Null) -and ($Credential -eq $Null) -and !((whoami) -eq 'nt authority\system'))
{$Credential = Get-Credential -Message "Enter Domain Admin Credentials for Remote Automate Push"}
If (($Username -ne $Null) -and ($Password -ne $Null)) {
$Pass = $Password | ConvertTo-SecureString -asPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential($Username,$Pass)
}
If ($Credential -eq $Null) {