Loading SysTrack PowerShell Module in User-Context Scripts

Prev Next

Update your automation and collection extension scripts so that they load the SysTrack PowerShell module (SysTrackPS.dll) when they run as User in version 11.7 and later. Replace a relative import path with a path that the script reads from the registry.

IMPORTANT: Starting from version 11.7, when an automation or a collection extension has Run As set to User (Windows Only), the script runs in a temporary folder under the AppData folder of the user instead of the action distribution directory. This security enhancement prevents relative paths from working reliably. If your script loads the SysTrack PowerShell module (SysTrackPS.dll) or references other files outside your action package, you must use absolute paths or registry-based path resolution.

This change does not require any updates to existing Anti-Virus Exclusions.

WARNING: SysTrack deletes the temporary folder after the run. Don't save files there that you need later.

NOTE: This change only affects scripts that run as User. Scripts that run as System continue to run in the action distribution directory. Lakeside recommends the registry-based pattern for these scripts too, for consistency.

Prerequisites

  • A PowerShell script that uses SysTrack PowerShell cmdlets, in an action that an automation or a collection extension runs.

  • Permission to change and approve that action. See Configure Action Governance Permissions.

Replace the Relative Path to SysTrackPS.dll

To load SysTrackPS.dll in a script that runs as User, replace the relative import path with the registry-based pattern:

  1. In your script, find the line that imports SysTrackPS.dll with a relative path.

    Old pattern (no longer supported in 11.7 and later):

    # This will FAIL when running as User in version 11.7+
    import-module -name "..\..\..\Utilities\SysTrackPS.dll"
  2. Replace that line with the registry-based pattern.

    New pattern (required for 11.7 and later):

    # Load SysTrackPS module.
    $node = ("WOW6432Node", "")[${env:PROCESSOR_ARCHITECTURE}.StartsWith("ARM")]
    $regPath = "HKLM:\SOFTWARE\$node\Lakeside Software\Deploy"
    $lsiPath = (Get-ItemProperty -Path $regPath).InstallDir
    $dllPath = "$lsiPath\Utilities\SysTrackPS.dll"
    if (!(Test-Path $dllPath)) { break }
    Import-Module -Name "$lsiPath\Utilities\SysTrackPS.dll"

    The registry lookup retrieves the actual installation directory of the SysTrack Agent, so the script can locate SysTrackPS.dll wherever the action runs.

  3. Save the changed script in the action. See Edit an Action.

  4. Approve the changed action. A saved action is unapproved and disabled until someone approves it again. See Approve and Enable Actions.

Check the Result

Run the automation or the collection extension on a test device with Run As set to User (Windows Only), and check that the script writes its data or returns its result. For a collection extension, run it from Resolve and check the run on the Collection Extension History tab. See Run a Collection Extension from Resolve.

Files Within Your Action Package

Relative paths between files inside your action package still work normally. For example, if your action contains MyScript.ps1 and config.txt, you can still use:

$config = Get-Content ".\config.txt"

Only references to files outside the action package (like SysTrackPS.dll) require absolute paths or registry resolution.

Troubleshooting User-Context Scripts

A Script That Runs as User Does Not Load SysTrackPS.dll

Cause: from version 11.7, a script that runs as User runs in a temporary folder. A relative path such as ..\..\..\Utilities\SysTrackPS.dll no longer points to the SysTrack Agent installation directory. In the new pattern, the Test-Path line ends the script when it cannot find SysTrackPS.dll.

Resolution: replace the relative path with the registry-based pattern in Replace the Relative Path to SysTrackPS.dll.

A File That the Script Saved Is Missing After the Run

Cause: a script that runs as User saved the file in its temporary folder, and SysTrack deletes that folder after the run.

Resolution: save files that you need later outside the temporary folder.

For automation errors, see Common Errors with Automations.