Windows Agent - Configuring the PowerShell Script

Introduction

Follow this article to configure the PowerShell script needed during agent deployment.

Prerequisites

  • The script must be run with Administrative privileges to successfully install.

Instructions

Copying the SNAP Agent URL

  1. In the Blackpoint Portal, navigate to Customers in the left-hand menu. 
  2. In the Customer List section, find the customer you want to deploy the agent to. Click the Manage button. You will be redirected to the Customer Details page.
  3. Provided that a service has been added to this customer, you will see a Download SNAP Agent button. Click to download the .exe file. Likewise, you can copy the URL to your clipboard if you prefer to use the hosted agent link.
  4. The URL contains two values you will need in the next section: the CustomerUID and the CompanyEXE. Save or paste this information in a secure location.
    • CustomerUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
    • CompanyEXE: COMPANYNAME_installer.exe
    For example, if the URL is https://portal.blackpointcyber.com/installer/f1dc5f6a-1e05-883e-9c90-61pon278wm52/MyFirstCustomer_snap_installer.exe, then:
    • The CustomerUID is f1dc5f6a-1e05-883e-9c90-61pon278wm52
    • The CompanyEXE is MyFirstCustomer_snap_installer.exe

Modify PowerShell script

  1. Download the Powershell script here. Right-click on the link and select Save Link As...
  2. Open the script, in the "Edit Me" section, paste in the CustomerUID and the CompanyEXE values you recorded in the previous section.
  3. Send the script to the deployment method you prefer. Guides for common deployment methods (such as RMM and GPO) are listed under Deployment Guides.

    Important. The script must be run with Administrative privileges to successfully install.
    #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
    #.______    __          ___       ______  __  ___ .______     ______    __  .__   __. .___________.##  
    #|   _  \  |  |        /   \     /      ||  |/  / |   _  \   /  __  \  |  | |  \ |  | |           |## 
    #|  |_)  | |  |       /  ^  \   |  ,----'|  '  /  |  |_)  | |  |  |  | |  | |   \|  | `---|  |----`##  
    #|   _  <  |  |      /  /_\  \  |  |     |    <   |   ___/  |  |  |  | |  | |  . `  |     |  |####### 
    #|  |_)  | |  `----./  _____  \ |  `----.|  .  \  |  |      |  `--'  | |  | |  |\   |     |  |#######         
    #|______/  |_______/__/     \__\ \______||__|\__\ | _|       \______/  |__| |__| \__|     |__|#######         
    #####################################################################################################                                                                                                
    ####################################╔═╗╔╗╔╔═╗╔═╗///╔╦╗╔═╗╔═╗╔═╗╔╗╔╔═╗╔═╗#############################
    ####################################╚═╗║║║╠═╣╠═╝/// ║║║╣ ╠╣ ║╣ ║║║╚═╗║╣ ###### Ver 2.2 04/09/2021 ###
    ####################################╚═╝╝╚╝╩ ╩╩/////═╩╝╚═╝╚  ╚═╝╝╚╝╚═╝╚═╝#############################
    
    ###########
    # EDIT ME
    ###########
    
    #Customer UID found in URL From Blackpoint Portal
    $CustomerUID = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
    
    #Snap Installer name
    $CompanyEXE = "COMPANYNAME_installer.exe" 
    
    ##############################
    # DO NOT EDIT PAST THIS POINT
    ##############################
    
    #Installer Name
    $InstallerName = "snap_installer.exe"
    
    #InstallsLocation
    $InstallerPath =  Join-Path $env:TEMP $InstallerName
    
    #Snap URL
    $DownloadURL = "https://portal.blackpointcyber.com/installer/$CustomerUID/$CompanyEXE"
    
    #Service Name
    $SnapServiceName = "Snap"
    
    #Enable Debug with 1
    $DebugMode = 1 
    
    #Failure message
    $Failure = "Snap was not installed Successfully. Contact [email protected] if you need more help."
    
    function Get-TimeStamp {
        return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
    }
    
    
    #Checking if the Service is Running
    function Snap-Check($service)
    {
        if (Get-Service $service -ErrorAction SilentlyContinue)
        {
            return $true
        }
        return $false
    }
    
    #Debug 
    function Debug-Print ($message)
    {
        if ($DebugMode -eq 1)
        {
            Write-Host "$(Get-TimeStamp) [DEBUG] $message"
        }
    }
    
    #Checking .NET Ver 4.6.1
    function Net-Check {
        #Left in to help with troubleshooting
        #$cimreturn = (Get-CimInstance Win32_Operatingsystem | Select-Object -expand Caption -ErrorAction SilentlyContinue) 
        #$windowsfull =  $cimreturn
        #$WindowsSmall = $windowsfull.Split(" ")
        #[string]$WindowsSmall[0..($WindowsSmall.Count-2)]
        #If ($WindowsSmall -eq $Windows10) {  
        
        Debug-Print("Checking for .NET 4.6.1+...") 
        #Calls Net Ver 
            If (! (Get-ItemProperty "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full").Release -gt 394254){
                       
    
            $NetError = "SNAP needs 4.6.1+ of .NET...EXITING" 
            Write-Host "$(Get-TimeStamp) $NetError"
            exit 0
            }
            
            {
            Debug-Print ("4.6.1+ Installed...")
            }
               
    }
    
    #Downloads file
    function Download-Installer {
        Debug-Print("Downloading from provided $DownloadURL...")
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        $Client = New-Object System.Net.Webclient
        try
        {
            $Client.DownloadFile($DownloadURL, $InstallerPath)
        }
        catch
        {
        $ErrorMsg = $_.Exception.Message
        Write-Host "$(Get-TimeStamp) $ErrorMsg"
        }
        If ( ! (Test-Path $InstallerPath) ) {
            $DownloadError = "Failed to download the SNAP Installation file from $DownloadURL"
            Write-Host "$(Get-TimeStamp) $DownloadError" 
            throw $Failure
        }
        Debug-Print ("Installer Downloaded to $InstallerPath...")
    
    }
    
    #Installation 
    function Install-Snap {
        Debug-Print ("Verifying AV did not steal exe...")
        If (! (Test-Path $InstallerPath)) {
        {
            $AVError = "Something, or someone, deleted the file."
            Write-Host "$(Get-TimeStamp) $AVError"
            throw $Failure
        }
        }
        Debug-Print ("Unpacking and Installing agent...")
        Start-Process -NoNewWindow -FilePath $InstallerPath -ArgumentList "-y"    
    }
    
    function runMe {
        Debug-Print("Starting...")
        Debug-Print("Checking if SNAP is already installed...")
        If ( Snap-Check($SnapServiceName) )
        {
            $ServiceError = "SNAP is Already Installed...Bye." 
            Write-Host "$(Get-TimeStamp) $ServiceError"
            exit 0
        }
        Net-Check
        Download-Installer
        Install-Snap
      # Error-Test
        Write-Host "$(Get-TimeStamp) Snap Installed..."
    }
    
    try
    {
        runMe
    }
    catch
    {
        $ErrorMsg = $_.Exception.Message
        Write-Host "$(Get-TimeStamp) $ErrorMsg"
        exit 1
    }