LabTech Agent Powershell Module

This is a powershell module for the LabTech Agent. This powershell module can be used to ease management of the agent. This module should continue to improve. Please help add to this powershell module with a pull request or a comment.

**Most functions should work with PowerShell Version 2 if you have issues please update to version 3 or greater**

/LabTech-Powershell-Module


To import the module on a machine, open a powershell window and execute

[code lang=”powershell” light=”true”](new-object Net.WebClient).DownloadString(‘http://bit.ly/ltposh’) | iex[/code]

This module contains the following commandlets.

Get-LTServiceInfo
Get-LTServiceSettings
Restart-LTService
Stop-LTService
Start-LTService
Uninstall-LTService
Install-LTService
Reinstall-LTService
Get-LTError
Reset-LTService
Hide-LTAddRemove
Show-LTAddRemove
Test-LTPorts
Get-LTLogging
Set-LTLogging
Get-LTProbeErrors
New-LTServiceBackup
Get-LTServiceInfoBackup
Rename-LTAddRemove


Get-LTServiceInfo

This commandlet will pull all of the registry data from HKLM:\SOFTWARE\LabTech\Service and load it into a PoSH object.
This is helpful for getting information about your agent.

Get-LTServiceSettings

This commandlet will pull all of the registry data from HKLM:\SOFTWARE\LabTech\Service\Settings and load it into a PoSH object.
This is helpful for getting information about your agent.

Restart-LTService

This commandlet will issue a Stop-LTService then a Start-LTService

Stop-LTService

This function will issue a stop to all services. If they do not stop in a timely manner they will be killed.

Start-LTService

This function will verify that the LabTech services are present.
It will then check for any process that is using port 42000 and kill it.
Next it will start the services.

Uninstall-LTService

This function will stop all the LabTech services. It will then download the current agent install MSI and issue an uninstall command.
It will then download and run Agent_Uninstall.exe from the LabTech server. It will then scrub any remaining file/registry/service.

.PARAMETER Server
This is the URL to your LabTech server.
example: https://lt.domain.com
This is used to download the uninstallers.
If no server is provided the uninstaller will use Get-LTServiceInfo to get the server address.

.PARAMETER Backup
This will run a ‘New-LTServiceBackup’ before uninstalling.

.EXAMPLE
Uninstall-LTService
This will uninstall the LabTech agent using the server address in the registry.

.EXAMPLE
Uninstall-LTService -Server https://lt.domain.com
This will uninstall the LabTech agent using the provided server URL to download the uninstallers.

Install-LTService

This function will install the LabTech agent on the machine with the specified server/password/location.

.PARAMETER Server
This is the URL to your LabTech server.
example: https://lt.domain.com
This is used to download the uninstallers.
(Get-LTServiceInfo).’Server Address’

.PARAMETER Password
This is the server password that agents use to authenticate with the LabTech server.
(Get-LTServiceInfo).ServerPassword

.PARAMETER LocationID
This is the LocationID of the location that the agent will be put into.
(Get-LTServiceInfo).LocationID

.PARAMETER Rename
This will call Rename-LTAddRemove to rename the install in Add/Remove Programs

.PARAMETER Hide
This will call Hide-LTAddRemove to remove the agent from Add/Remove Programs

.EXAMPLE
Install-LTService -Server https://lt.domain.com -Password sQWZzEDYKFFnTT0yP56vgA== -LocationID 42
This will install the LabTech agent using the provided server URL, Password, and LocationID.

Reinstall-LTService

.SYNOPSIS
This function will reinstall the LabTech agent from the machine.

.DESCRIPTION
This script will atempt to pull all current settings from machine and issue an ‘Uninstall-LTService’ ‘Reinstall-LTService’ with gathered information.
If the function is unable to find settings it will ask for needed paramaters.

.PARAMETER Server
This is the URL to your LabTech server.
example: https://lt.domain.com
This is used to download the uninstallers.
(Get-LTServiceInfo).’Server Address’

.PARAMETER Password
This is the server password that agents use to authenticate with the LabTech server.
(Get-LTServiceInfo).ServerPassword

.PARAMETER LocationID
This is the LocationID of the location that the agent will be put into.
(Get-LTServiceInfo).LocationID

.PARAMETER Rename
This will call Rename-LTAddRemove to rename the install in Add/Remove Programs

.PARAMETER Hide
This will call Hide-LTAddRemove to remove the agent from Add/Remove Program

.PARAMETER Backup
This will run a ‘New-LTServiceBackup’ before uninstalling.

.EXAMPLE
Uninstall-LTService -Server ‘https://lt.domain.com’
This will uninstall the LabTech agent using the provided server URL to download the uninstallers.

 

Get-LTError

This will pull the %ltsvcdir%\LTErrors.txt file into an object.

.EXAMPLE
Get-LTError | where {(Get-date $_.Time) -gt (get-date).AddHours(-24)}
Get a list of all errors in the last 24hr

.EXAMPLE
Get-LTError | Out-Gridview
Open the log file in a sortable searchable window.

Reset-LTService

This function can remove some of the agents local settings.
ID, MAC, LocationID
The function will stop the services, make the change, then start the services.
Resetting all of these will force the agent to check in as a new agent.
If you have MAC filtering enabled it should check back in with the same ID.
This function is useful for duplicate agents.

.PARAMETER ID
This will reset the AgentID of the computer

.PARAMETER Location
This will reset the LocationID of the computer

.PARAMETER MAC
This will reset the MAC of the computer

.EXAMPLE
Reset-LTService
This resets the ID, MAC and LocationID on the agent.

.EXAMPLE
Reset-LTService -ID
This resets only the ID of the agent.

Hide-LTAddRemove

This function will rename the DisplayName registry key to hide it from the add/remove programs list.

Show-LTAddRemove

This function will rename the HiddenDisplayName registry key to show it in the add/remove programs list.
If there is not HiddenDisplayName key the function will import a new entry.

Test-LTPorts

The function will make sure that LTTray is using UDP 42000.
It will then test all the required TCP ports.

Get-LTLogging

This function will pull the logging level of the LabTech service.

Set-LTLogging

This function will pull all of the registy data into an object.

Get-LTProbeErrors

This will pull the %ltsvcdir%\LTProbeErrors.txt file into an object.

New-LTServiceBackup

This function will backup all the reg keys to ‘HKLM\SOFTWARE\LabTechBackup’
This will also backup those files to “$((Get-LTServiceInfo).BasePath)Backup”

Get-LTServiceInfoBackup

This function will pull all of the backed up registy data into an object.

Rename-LTAddRemove

This function will change the value of the DisplayName registry key to effect add/remove programs list.

 

3 thoughts on “LabTech Agent Powershell Module

  • You have any guidance on running these commands remotely and silently? I’ve tried via the LabTech cmd prompt as well as via the ScreenConnect commands tab and I always run into weird issues that seem like parsing/syntax problems. Here’s an example:

    C:\Windows\system32>powershell.exe -ExecutionPolicy bypass -NoProfile -NoLogo -c “”

    Missing ‘)’ in method call.

    At line:1 char:46

    + + CategoryInfo : ParserError: (CloseParenToken:TokenId) [], Paren

    tContainsErrorRecordException

    + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

    • The module is quite easy to use with LabTech. First make sure the machine has PowerShell 3+. Then just call from shell as you where doing. I have also changed the quotes in the example from double quotes to single to help with LT not handling quotes very well.
      Example:
      powershell “(new-object Net.WebClient).DownloadString(‘https://goo.gl/tb38WQ’) | iex;Get-LTServiceInfo”

  • Hi – While running Reinstall-LTService command getting “Process is terminated due to StackOverFlowException” post uninstallation of agent.

    When we run the above command, it is uninstalling the LTService but not installing the agent. In middle it is stopping with above error.

Leave a Reply

Your email address will not be published. Required fields are marked *