Skip to content

Commit 6d3c5eb

Browse files
Merge pull request #41 from AngryProgrammerInside/6.0.2a
6.0.2a
2 parents 9bf04d2 + e631375 commit 6d3c5eb

File tree

7 files changed

+150
-59
lines changed

7 files changed

+150
-59
lines changed

Agent/AgentCleanup4.exe

27.5 KB
Binary file not shown.

Agent/InstallAgent.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ $Script = @{
612612
"Library" = @($SC.Paths.TempFolder, "Lib") -join '\'
613613
"PartnerFile" = @($SC.Paths.TempFolder, $SC.Names.PartnerConfig) -join '\'
614614
"TempFolder" = $SC.Paths.TempFolder
615+
"AgentCleanup" = @($SC.Paths.TempFolder, "AgentCleanup4.exe") -join '\'
615616
}
616617
"Results" = @{
617618
"EventLog" = $SC.ScriptEventLog

Agent/LaunchInstaller.ps1

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,46 +80,45 @@ if ($null -eq $p) {
8080
else {
8181
Write-Host "Successfully launched $TempFolder\InstallAgent.ps1 with $($args.Count) arguments" -ForegroundColor Green
8282
Write-EventLog -EntryType Information -EventId 10 -LogName Application -Source $LauncherScript -Message "Successfully launched $TempFolder\InstallAgent.ps1 with $($args.Count) arguments" > $null
83-
}
84-
85-
Write-Host "Launched InstallAgent with PID: $($p.Id), waiting on Exit"
86-
$RegPaths = @{
87-
Summary = "HKLM:\SOFTWARE\N-able Community\InstallAgent"
88-
Installation = "HKLM:\SOFTWARE\N-able Community\InstallAgent\Installation"
89-
Diagnosis = "HKLM:\SOFTWARE\N-able Community\InstallAgent\Diagnosis"
90-
}
9183

92-
while (-not $p.HasExited) {
9384
if ($Monitor.IsPresent) {
94-
Start-Sleep 1
95-
Clear-Host
96-
if (Test-Path $RegPaths.Summary) {
97-
Write-Host "Progress: " -ForegroundColor Green -NoNewline
98-
Get-ItemProperty $RegPaths.Summary | Select-Object * -ExcludeProperty PS* | Format-List *
85+
86+
Write-Host "Launched InstallAgent with PID: $($p.Id), waiting on Exit"
87+
$RegPaths = @{
88+
Summary = "HKLM:\SOFTWARE\N-able Community\InstallAgent"
89+
Installation = "HKLM:\SOFTWARE\N-able Community\InstallAgent\Installation"
90+
Diagnosis = "HKLM:\SOFTWARE\N-able Community\InstallAgent\Diagnosis"
9991
}
100-
}
101-
else {
102-
Start-Sleep 10
103-
}
104-
}
105-
if ($p.ExitCode -eq 0) {
106-
Write-Host "Script ran successfully, displaying registry results:" -ForegroundColor Green
107-
$RegPaths.Keys | ForEach-Object {
108-
if (Test-Path $RegPaths[$_]) {
109-
Write-Host "$($_): " -ForegroundColor Green -NoNewline;
110-
Get-ItemProperty $RegPaths[$_] | Select-Object * -ExcludeProperty PS* | Format-List *
92+
93+
while (-not $p.HasExited) {
94+
Start-Sleep 1
95+
Clear-Host
96+
if (Test-Path $RegPaths.Summary) {
97+
Write-Host "Progress: " -ForegroundColor Green -NoNewline
98+
Get-ItemProperty $RegPaths.Summary | Select-Object * -ExcludeProperty PS* | Format-List *
99+
}
111100
}
112-
}
113-
Write-Host "Check logs for additional details"
114-
}
115-
else {
116-
Write-Host "Script ran successfully, displaying registry results:"
117-
$RegPaths.Keys | ForEach-Object {
118-
if (Test-Path $RegPaths[$_]) {
119-
Write-Host "$($_): " -ForegroundColor Green -NoNewline;
120-
Get-ItemProperty $RegPaths[$_] | Select-Object * -ExcludeProperty PS* | Format-List *
101+
if ($p.ExitCode -eq 0) {
102+
Write-Host "Script ran successfully, displaying registry results:" -ForegroundColor Green
103+
$RegPaths.Keys | ForEach-Object {
104+
if (Test-Path $RegPaths[$_]) {
105+
Write-Host "$($_): " -ForegroundColor Green -NoNewline;
106+
Get-ItemProperty $RegPaths[$_] | Select-Object * -ExcludeProperty PS* | Format-List *
107+
}
108+
}
109+
Write-Host "Check logs for additional details"
121110
}
111+
else {
112+
Write-Host "Script ran successfully, displaying registry results:"
113+
$RegPaths.Keys | ForEach-Object {
114+
if (Test-Path $RegPaths[$_]) {
115+
Write-Host "$($_): " -ForegroundColor Green -NoNewline;
116+
Get-ItemProperty $RegPaths[$_] | Select-Object * -ExcludeProperty PS* | Format-List *
117+
}
118+
}
119+
Write-Host "Check logs for additional details"
120+
Write-EventLog -EntryType Error -EventId 13 -LogName Application -Source $LauncherScript -Message "$SetupScript encountered an error starting the launcher" > $null
121+
}
122+
122123
}
123-
Write-Host "Check logs for additional details"
124-
Write-EventLog -EntryType Error -EventId 13 -LogName Application -Source $LauncherScript -Message "$SetupScript encountered an error starting the launcher" > $null
125124
}

Agent/Lib/InstallAgent-Core.psm1

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,9 @@ function ValidatePartnerConfig {
678678
$Config.NETFile = $InstallInfo.NETFileName
679679
$Config.NETVersion = $InstallInfo.NETVersion
680680
$Config.NETFileVersion = $InstallInfo.NETFileVersion
681-
$Config.EnforceBehaviorPolicy = $Partner.Config.ServiceBehavior.EnforcePolicy
681+
$Config.EnforceBehaviorPolicy = if ($Partner.Config.ServiceBehavior.EnforcePolicy -like "True") {$true} else {$false}
682+
$Config.ForceAgentCleanup = if ($Partner.Config.ScriptBehavior.ForceAgentCleanup -like "True") {$true} else {$false}
683+
$Config.UseWSDLVerifcation = if ($Partner.Config.ScriptBehavior.UseWSDLVerification -like "True") {$true} else {$false}
682684

683685
### Function Body
684686
###############################
@@ -1595,6 +1597,25 @@ function TestNCServer {
15951597
}
15961598
}
15971599
# Check if Agent has Connectivity to Server in Partner Configuration
1600+
1601+
if ($Config.UseWSDLVerifcation -and $NCResult -eq $false) {
1602+
$client = New-Object System.Net.WebClient
1603+
try {
1604+
$response = $client.DownloadString("https://$($Config.NCServerAddress)/dms2/services2/ServerEI2?wsdl")
1605+
$xmlResponse = [xml]$response
1606+
if ($xmlResponse.definitions.service.port.address.location -eq "https://$($Config.NCServerAddress)/dms2/services2/ServerEI2") {
1607+
$Flag = "W"
1608+
$Out = ("Device failed ping test, but succeeded on WSDL verification method for " + $NC.Products.NCServer.Name + ", script will proceed with online activities")
1609+
Log $Flag 0 $Out
1610+
}
1611+
}
1612+
catch {
1613+
$Flag = "W"
1614+
$Out = ("WSDL verification method for " + $NC.Products.NCServer.Name + "failed, Offline Repairs will be performed possible until connectivity is restored.")
1615+
Log $Flag 0 $Out
1616+
}
1617+
}
1618+
15981619
$Install.NCServerAccess =
15991620
if ($null -ne $Flag)
16001621
{ $true } else { $false }
@@ -2982,13 +3003,40 @@ function RemoveAgent {
29823003
# Verify Removal was Successful
29833004
DiagnoseAgent -NoLog -NoServerCheck
29843005
if ($Agent.Health.Installed -eq $true) {
2985-
# Exit - Agent Removal Failed
2986-
FixServices -Restart
2987-
$Out = (
2988-
"MSI Removal of the existing " + $NC.Products.Agent.Name + " failed. " +
2989-
"Manual forcible removal is required for the Script to continue."
2990-
)
2991-
Log E 11 $Out -Exit
3006+
3007+
#If the forced removal of the agent is enabled
3008+
if ($Config.ForceAgentCleanup) {
3009+
$FAC = New-Object System.Diagnostics.ProcessStartInfo ($env:windir + "\system32\cmd.exe")
3010+
$FAC.UseShellExecute = $false
3011+
$FAC.CreateNoWindow = $true
3012+
$FAC.Arguments = ('/C "' + $Script.Path.AgentCleanup + '"')
3013+
# Run the forced cleanup
3014+
[System.Diagnostics.Process]::Start($FAC).WaitForExit() >$null
3015+
3016+
# Verify Removal was Successful again
3017+
DiagnoseAgent -NoLog -NoServerCheck
3018+
3019+
if ($Agent.Health.Installed -eq $true) {
3020+
# Exit - Agent Removal Failed
3021+
FixServices -Restart
3022+
$Out = (
3023+
"Forced and MSI Removal of the existing " + $NC.Products.Agent.Name + " failed. " +
3024+
"Manual forcible removal is required for the Script to continue."
3025+
)
3026+
Log E 11 $Out -Exit
3027+
}
3028+
}
3029+
else {
3030+
# Exit - Agent Removal Failed
3031+
FixServices -Restart
3032+
$Out = (
3033+
"MSI Removal of the existing " + $NC.Products.Agent.Name + " failed. " +
3034+
"Manual forcible removal is required for the Script to continue."
3035+
)
3036+
Log E 11 $Out -Exit
3037+
}
3038+
# If forced removal successful, flag existing agent removal as true
3039+
$Install.ExistingAgentRemoved = $true
29923040
}
29933041
else
29943042
{ $Install.ExistingAgentRemoved = $true }
@@ -3082,7 +3130,7 @@ function RequestAzWebProxyToken {
30823130
$Uri = "https://$($Config.AzNableProxyUri)/api/Get?Code=$($Config.AzNableAuthCode)&ID="
30833131
try {
30843132
$Uri += "$($Install.ChosenMethod.Value)"
3085-
$Response = (Invoke-WebRequest -Method GET -Uri $Uri).Content
3133+
$Response = (Invoke-WebRequest -Method GET -Uri $Uri -UseBasicParsing).Content
30863134
}
30873135
catch {
30883136
$Out = "Error retrieving token from $Uri using $($Install.ChosenMethod.Name)"
@@ -3121,6 +3169,30 @@ function InstallAgent {
31213169
WriteKey $Script.Results.ScriptKey $Script.Execution
31223170
### Function Body
31233171
###############################
3172+
### Perform WSDL verfication before attempting any install or removal
3173+
if ($Config.UseWSDLVerifcation) {
3174+
$client = New-Object System.Net.WebClient
3175+
try {
3176+
$response = $client.DownloadString("https://$($Config.NCServerAddress)/dms2/services2/ServerEI2?wsdl")
3177+
$xmlResponse = [xml]$response
3178+
if ($xmlResponse.definitions.service.port.address.location -eq "https://$($Config.NCServerAddress)/dms2/services2/ServerEI2") {
3179+
$Flag = "I"
3180+
$Out = ("WSDL verification succeeded, proceeding with installation actions.")
3181+
Log $Flag 0 $Out
3182+
}
3183+
else {
3184+
$Flag = "E"
3185+
$Out = ("WSDL verification failed. Expected: https://$($Config.NCServerAddress)/dms2/services2/ServerEI2 Received:$($xmlResponse.definitions.service.port.address.location)")
3186+
Log $Flag 13 $Out
3187+
}
3188+
}
3189+
catch {
3190+
$Flag = "E"
3191+
$Out = ("WSDL verification method for " + $NC.Products.NCServer.Name + "failed prior to install. Terminating install.")
3192+
Log $Flag 13 $Out -Exit
3193+
}
3194+
}
3195+
31243196
### Attempt Agent Installation
31253197
for (
31263198
$Install.ChosenMethod.FailedAttempts = 0

Agent/PartnerConfig.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Required Values CANNOT be left blank (the Event Log will inform you of this). Ad
2222
and/or Recommendations may be added here with regard to new Configuration Values.
2323
-->
2424
<Config>
25-
<Version>6.0.1</Version>
25+
<Version>6.0.2</Version>
2626
<Branding>
2727
<!-- [OPTIONAL - (Business Contact Info)] Partner Contact Information to display in the Event Log
2828
when a Documented Error occurs -->
@@ -33,12 +33,14 @@ help@mymsp.com
3333
</ErrorContactInfo>
3434
</Branding>
3535
<ScriptBehavior>
36-
<!-- [RECOMMENDED - (0-60)] Amount of time (in minutes) to wait since the Last System Boot before
37-
diagnosing the Agent -->
36+
<!-- [RECOMMENDED - (0-60)] Amount of time (in minutes) to wait since the Last System Boot before diagnosing the Agent -->
3837
<BootTimeWaitPeriod>5</BootTimeWaitPeriod> <!-- Default Value is 5 -->
39-
<!-- [REQUIRED - (1-60)] Amount of time (in minutes) to wait for the Windows Installer Service
40-
while another installation is in progress -->
38+
<!-- [REQUIRED - (1-60)] Amount of time (in minutes) to wait for the Windows Installer Service while another installation is in progress -->
4139
<InstallTimeoutPeriod>5</InstallTimeoutPeriod> <!-- Default Value is 5 -->
40+
<!-- [REQUIRED - (True)] - If there are issues with the MSI uninstall of the previous version, perform a cleanup -->
41+
<ForceAgentCleanup>True</ForceAgentCleanup>
42+
<!-- [REQUIRED - (True)] - If true enables fallback from ICMP to HTTP/S lookup of the WSDL endpoint for network verification and pre-install server verification -->
43+
<UseWSDLVerification>True</UseWSDLVerification>
4244
</ScriptBehavior>
4345
<Server>
4446
<!-- [REQUIRED - (URL Without Protocol)] Your N-Central Server Address (get this from the

ReadMe.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
## Table of Contents
44
- [InstallAgent Automation Suite](#installagent-automation-suite)
5-
* [Table of Contents](#table-of-contents)
65
* [Introduction](#introduction)
7-
* [New and improved Features since AgentDeploymentPackage in 6.0.0](#new-and-improved-features-since-agentdeploymentpackage-in-600)
6+
* [Status of Suite](#status-of-suite)
7+
* [Release notes for 6.0.2](#release-notes-for-602)
8+
* [Release notes for 6.0.1](#release-notes-for-601)
9+
* [New and improved Features in AgentDeploymentPackage 6.0.0](#new-and-improved-features-in-agentdeploymentpackage-600)
810
* [Key Features](#key-features)
911
- [The "Registration Token" - Agent Deployment and Considerations](#the--registration-token----agent-deployment-and-considerations)
1012
* [History](#history)
@@ -28,6 +30,7 @@
2830
* [1a - Setup the N-Central Custom Service (Version 6.xx)](#1a---setup-the-n-central-custom-service--version-6xx-)
2931
* [1b - Setup AMP based PartnerConfiguration update amps](#1b---setup-amp-based-partnerconfiguration-update-amps)
3032
* [1c - Setup AMP based PartnerConfiguration update amps](#1c---setup-amp-based-partnerconfiguration-update-amps)
33+
* [1d - Setup AMP based monitoring of the PartnerConfig.xml file](#1d---setup-amp-based-monitoring-of-the-partnerconfigxml-file)
3134
+ [Update PartnerConfig from CP](#update-partnerconfig-from-cp)
3235
+ [Update PartnerConfig from JWT](#update-partnerconfig-from-jwt)
3336
* [2 - Review Deployment Package Results](#2---review-deployment-package-results)
@@ -48,20 +51,27 @@
4851
## Introduction
4952
This is a community-based Automation Suite intended as a replacement for the stock N-central Group Policy Installer Script as provided by N-able. It is not supported by N-able, so please do not contact their support department regarding any problems or questions about this script. In addition, please do not contact the support departments of any individual Partners in the Community regarding the Automation Suite or its components.
5053

54+
This suite is a fork of [Ryan Crowther Jr's AgentDeploymentPackage on GitHub](https://github.com/N-able/AgentDeploymentPackage/) and will soon be the future branch going forward as they have moved on to other projects.
55+
56+
If you discover a problem with any component of the Automation Suite or have ideas on how it could be improved, [post an issue on GitHub](https://github.com/AngryProgrammerInside/InstallAgent/issues). Alternatively, post on the N-Central Slack Community chat.
57+
58+
These tools are provided as-is, in the best of faith, by those Partners and Community Members involved in their development. If you use this in your environment, we would love to hear from you on GitHub!
59+
5160
## Status of Suite
5261
All scripts in the suite have been run and tested as functional. It is currently considered in a 'beta' phase while wider testing is being performed.
5362

5463
Feel free to provide feedback and lodge issues and they will be reviewed.
5564

56-
## New and improved Features in AgentDeploymentPackage 6.0.1 (Beta)
65+
## Release notes for 6.0.2
66+
* Fixed several small bugs, full [Release Notes](ReleaseNotes.md)
67+
* Added WSDL endpoint based N-Central Server verification for environments where Echo/ICMP is blocked, or where additional verification that the server N-Central is up and accessible. Enabled by setting the `<UseWSDLVerification>` attribute to **True**
68+
* Added forced removal/cleanup when bad MSI uninstall information or MSI unable to remove old/rogue agent when needed using the AgentCleanup4.exe. Enabled by setting the `<ForceAgentCleanup>` attribute to **True**
5769

58-
This script is a fork of [Ryan Crowther Jr's AgentDeploymentPackage on GitHub](https://github.com/N-able/AgentDeploymentPackage/) and will soon be the future branch going forward as they have moved on to other projects.
59-
60-
If you discover a problem with any component of the Automation Suite or have ideas on how it could be improved, [post an issue on GitHub](https://github.com/AngryProgrammerInside/InstallAgent/issues). Alternatively, post on the N-Central Slack Community chat.
61-
62-
These tools are provided as-is, in the best of faith, by those Partners and Community Members involved in their development. If you use this in your environment, we would love to hear from you on GitHub!
70+
## Release notes for 6.0.1
71+
* Fixed a large number of bugs, full [Release Notes](ReleaseNotes.md)
72+
* Added the ability enable/disable service policy enforcement with `<EnforcePolicy>` attribute for service timeouts/restarts. By default is now **False** as the service policy can get overriden by the maintenance service eventually.
6373

64-
## New and improved Features in AgentDeploymentPackage 6.0.1
74+
## New and improved Features in AgentDeploymentPackage 6.0.0
6575

6676
![](media/readme-image8.png)
6777
* Registration token install method:

ReleaseNotes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 2021-05-7 - 6.0.2
2+
* Fixed bug with Invoke-Webrequest not working due to absence of -UseBasicParsing per [#36](https://github.com/AngryProgrammerInside/InstallAgent/issues/36)
3+
* Added forced removal/cleanup when bad MSI uninstall information or MSI unable to remove old/rogue agent when needed. [#37](https://github.com/AngryProgrammerInside/InstallAgent/issues/37)
4+
* Added WSDL based server verification for environments where outbound ICMP is disabled [#38](https://github.com/AngryProgrammerInside/InstallAgent/issues/38)
5+
* Fixed bug with InstallAgent process not being spun off Async unless -Monitor flag used [#39](https://github.com/AngryProgrammerInside/InstallAgent/issues/39)
6+
* Fixed up Partner Config file validation of True/False attributes
7+
18
# 2021-04-12 - 6.0.1
29

310
## Fixes

0 commit comments

Comments
 (0)