10.1. Installing ASGARD Agent via PowerShell Script

The following example script installs the ASGARD Agent with PowerShell. Place the installer and script in the same folder. Adjust the script as needed.

 1# Setting vars
 2$scriptpath = $MyInvocation.MyCommand.Path
 3$dir = Split-Path $scriptpath
 4$installer = "asgard2-agent-windows-amd64.exe"
 5$servicename = "asgard2-agent"
 6
 7# Checking if ASGARD Agent is already installed
 8if (Get-Service -Name $servicename -ErrorAction SilentlyContinue) {
 9    Write-Host "ASGARD Agent already installed, exiting"
10    exit 0
11} else {
12    Write-Host "ASGARD Agent not found, trying to install..."
13
14    # Install ASGARD Agent
15    Start-Process -Wait -FilePath "$dir\$installer" -WorkingDirectory $dir -WindowStyle Hidden -PassThru
16
17    # Timeout just to make sure the service is up and running
18    Timeout /T 15
19
20    # Checking service to see if agent was installed
21    if (Get-Service -Name $servicename -ErrorAction SilentlyContinue) {
22        Write-Host "Installed ASGARD Agent successfully"
23        exit 0
24    } else {
25        $Host.UI.WriteErrorLine("Could not install ASGARD Agent")
26        exit 1
27    }
28}

10.2. Deploy ASGARD Agents via SCCM

To deploy the ASGARD Agent (or any other .exe installer) via SCCM, you need a PowerShell script with conditions that mark an installation as successful or failed.

Refer to Microsoft's Create applications in Configuration Manager.

 1# Get current directory
 2$scriptpath = $MyInvocation.MyCommand.Path
 3$dir = Split-Path $scriptpath
 4
 5# Run the installer
 6$installer = "asgard2-agent-windows-amd64.exe"
 7Start-Process -Wait -FilePath "$dir\$installer" -WorkingDirectory $dir -WindowStyle Hidden -PassThru
 8
 9# Timeout just to make sure the service is up and running
10Timeout /T 15
11
12# If the service exists, the script writes console output and exits with code 0
13# If the service does not exist, the script writes an error output and exits with code 1
14# See https://learn.microsoft.com/en-us/mem/configmgr/apps/deploy-use/create-applications#about-custom-script-detection-methods
15
16$servicename = "asgard2-agent"
17if (Get-Service -Name $servicename -ErrorAction SilentlyContinue) {
18    Write-Host "ASGARD Agent installed"
19    exit 0
20} else {
21    $Host.UI.WriteErrorLine("ASGARD Agent not installed")
22    exit 1
23}

Warning

This is an example script for SCCM. If you encounter any problems, refer to the link provided above for additional information.

SCCM applications can also use a script to detect the deployment. You can use this part of the script to detect whether the installation was successful:

1$servicename = "asgard2-agent"
2if (Get-Service -Name $servicename -ErrorAction SilentlyContinue) {
3   Write-Host "ASGARD Agent installed"
4   exit 0
5} else {
6   $Host.UI.WriteErrorLine("ASGARD Agent not installed")
7   exit 1
8}