You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DevelopmentAndDebugging.md
+34-6Lines changed: 34 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Development and Debugging
2
2
## Overview
3
-
The PowerShell version of the InstallAgent package is uses highly structured, robust code with validation and logging at every step, these characteristics make it suitable for use in broad rollouts from small to enterprise businesses.
3
+
The PowerShell version of the InstallAgent package uses a highly structured, robust coding methodology with validation and logging at every step, these characteristics make it suitable for use in broad rollouts from small to enterprise businesses.
4
4
5
5
While it has many positive attributes it can be difficult to approach when re-developing or debugging. So let's provide a high level view of how the script would run under normal circumstances and highlighting the important parts:
6
6
@@ -11,7 +11,7 @@ While this doesn't represent all the functions inside of the InstallAgent-Core.p
11
11
## Challenges and starting debugging
12
12
There are a number of challenges that you can run into when developing code for the InstallAgent package:
13
13
* The Installagent.ps1 and the folder structure is intended to self delete after running, as it's intended to be run temporarily from C:\Windows\Temp\AGPO after the LaunchInstaller.bat/ps1 copies it there from the Netlogon/Source folder.
14
-
* Functions in InstallAgent-Core.psm1 depend upon variables declared in InstallAgent.ps1 that exist in Script scope, this is opposed to functions that is passed parameters and all variables are private to it's scope
14
+
* Functions in InstallAgent-Core.psm1 depend upon variables declared in InstallAgent.ps1 that exist in Script scope, this is opposed to functions that are passed passed parameters and all variables are private to it's scope
15
15
* Functions will populate a number of variables with hashtables, their fields names and types are not declared anywhere in code.
16
16
17
17
The latter challanges are necessary artifacts caused by the constraints in PowerShell 2.0, to debug this code efficiently and cross reference variables it is necessary to use an IDE like Visual Studio Code or PowerShell ISE.
@@ -20,7 +20,7 @@ A point to set a debug point to see all the variables/tables populated and in a
20
20
21
21
Next either populate the PartnerConfig as outlined in the ReadMe.md and/or run the InstallAgent.ps1 with CustomerID/Token parameters, it's important to run the script with the dot source operator (period) and run it inside the [current session scope](https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode-and-the-dot-source-operator/)
Also make sure the LauncherPath parameter has a trailing \ otherwise it will cause issues. Once done you can explore all the variables in memory, and run some of the built in debug commands that provide a Gridview of useful tables:
26
26
* DebugGetMethods
@@ -171,10 +171,38 @@ The first thing we should note here is this is an `else`, not an `elseif` so we'
171
171
* the value is not a CustomerID, followed by a pipe, then no token, again an artifact of constructing the `CustomerID|Token` that is later used in the `InstallAgent` function for Registration Key methods
172
172
173
173
## DiagnoseAgent function
174
+
The DiagnoseAgent function is one of the larger and more complicated functions so we'll provide a high level overview of how this works:
175
+
* It initialises the `$Agent.Appliance` which holds the current appliance health and the `$Agent.Docs` variables where de-serialized versions of the ApplianceConfig.xml, the Install Log and a copy of the Agent install registry keys are placed while they are parsed and the health of the Agent determined.
176
+
* As the files and registry are loaded into the `$Agent.Docs` they are validated against regex expressions found under the `$SC.Validation` variable declared in the InstallAgent.ps1 file. If any part of the agent documents fail the regex test, the script will halt later on and provide information on the failed document.
177
+
* The next section then builds the Activation Key/Appliance ID from available parts if they're available, by building the activation key we can perform ugprades on existing installs while specify the appliance ID, reducing the chance of generic installs resulting in a database mismatch.
178
+
* The agent history file is updated with the token data and the health of the agent services are checked
179
+
* The ApplianceID and version of the agent is checked, if the agent version is less than the target version then it is flagged for an update
180
+
* Connectivity to the Partner N-Central server is checked, if it isn't available only limited repairs can be done as a connection to the N-Central server is required for installs or upgrades.
181
+
* A summary of the Agent health is placed in a hash table inside teh $Agent.Health.AgentStatus variable
182
+
* The agent status is logged for the final event log output
183
+
* If the agent is healthy and there is nothing to be done, the script ends, otherwise it proceeds to the next phases of repair or re-install
184
+
174
185
## RequestAzWebProxyToken function
175
-
## Discussion of important tables and what they do
176
-
## Discussion about Custom Modules
177
-
## Debug Commands and what they do
186
+
RequestAzWebProxyToken is new to 6.0.0 and leverages Kelvin Tegelaar's AzNableProxy to retrieve the registration token securely from your on N-Central server without exposing API keys.
187
+
188
+
To retrieve this token the function will:
189
+
* Create a URI from the partner configured values in the variables `$Config.AznableProxyUri` and `$Config.AzNableAuthCode`
190
+
* A PowerShell 3.0 Invoke-Webrequest method is called to retrieve the registration token. While technically the script is meant to be PowerShell 2.0 compatible there is a broader discussion on the security of PowerShell 2.0 and the age of the OS being used if it is 2.0. While it is possible to use a `[System.Net.WebClient]` method to download the registration token, that would be associated with TLS1.0 and you would need to make a concious security decision to use that legacy protocol.
191
+
* The retrieved token is checked to determine if it is a valid GUID
192
+
* If the chosen install method is of a type that requests converting to an encoded install key, it is created, otherwise the token is provided raw to the `$Install.ChosenMethod.Value`
193
+
## Custom Modules
194
+
The default InstallAgent-Core.psm1 module provides the default behaviors, and now includes AzNableProxy token lookup by default.
195
+
196
+
By using custom modules that override default functions you can achieve most any features you need for edge case deployments. This works because of the order in which the modules are loaded, for example the new `RequestAzWebProxyToken` has certain default behaviors that may not be suitable for your environment, by loading a custom module after the inital InstallAgent-Core.psm1 that has a function with the same name, the custom module you created will supercede the default `RequestAzWebProxyToken`
197
+
198
+
Once you've created your new module/files, place it in the Agent\Lib folder and update the $SC.Names.LibraryFiles array in the InstallAgent.ps1 file.
199
+
200
+
Examples of what can be achieved is illustrated with the following files within the Custom Library folder:
201
+
202
+
GetCustomInstallMethodExamples.psm1 - Demonstrates how you can provide a custom Install Method information back to the correct Hashtable
203
+
CustomOverrideExample.psm1 - Demonstrates how you can
204
+
Add additional telemetry when calling the AzNableProxy GET function with a few extra lines of code
205
+
Deliver detailed telemetry on Exit or Failure with a few extra lines of code
178
206
## Appendices: Detail on example tables of importance
179
207
### $Config
180
208
The `$Config` table is the variable to which the values of the **PartnerConfig.xml** is assigned, this is a 1:1 mapping of the Keys and Values.
0 commit comments