PowerShell: Halo PSA – Add a Pop-Up to Companies based on Company Type

Recently Mikey O’Toole (@homotechsual) and I have been working on a PowerShell Module for Halo PSA (Mikey did most of the work and making the module far more organised than my normal ones 😀 ). We finally finished it so I thought I would start throwing together some example scripts of how to use it. You can get the module from https://www.powershellgallery.com/packages/HaloAPI/ and view docs at https://dev.azure.com/MSPsUK/HaloAPI

The first one is a simple script that will take a Company Type from Halo, find all the companies with that type and add a pop-up message to them. Create a new app and get your API keys for Halo from Configuration -> Integrations -> Halo PSA API

######################################################################################
# This script shows how you can add a pop-up note to each customer of a certain type #
######################################################################################

### Settings ###

$HaloClientID = "Your Halo API Client ID"
$HaloClientSecret = "Your Halo API Client Secret"
$HaloURL = "yourhalo.domain.com"

$HaloCompanyType = "Micro Managed Basic"
$HaloCompanyPopUpNote = "This customer has Managed Services"

###  Script  ###

if (Get-Module -ListAvailable -Name HaloAPI) {
	Import-Module HaloAPI 
} else {
	Install-Module HaloAPI -Force
	Import-Module HaloAPI
}


# Connect to Halo
Connect-HaloAPI -URL $HaloURL -ClientId $HaloClientID -ClientSecret $HaloClientSecret -Scopes "all"


# Fetch Halo Data
$HaloCompanies = Get-HaloClient
$HaloTypes = Get-HaloLookup -lookupid 33 -showall -excludezero

# Match type
$HaloType = $HaloTypes | where-object { $_.name -eq $HaloCompanyType }

if (($HaloType | Measure-Object).count -eq 1) {

	# Loop through all companies in Halo
	foreach ($HaloCompanyBase in $HaloCompanies) {

		# Get the full company object so we can match on the CustomerType
		$HaloCompany = Get-HaloClient -ClientID $HaloCompanyBase.id
		if ($HaloCompany.CustomerType -eq $HaloType.id) {
					
			# Check if there are existing alerts. Create a blank array list if there aren't any or create one with the existing data
			if ($HaloCompany.popup_notes -eq 0) {
				$UpdateNotes = [System.Collections.ArrayList]@()
			} else {
				$UpdateNotes = [System.Collections.ArrayList]$HaloCompany.popup_notes
			}
			
							
			# Build the new Halo popup alert from the Autotask one
			$NewAlert = @{
				note         = $HaloCompanyPopUpNote
				dismissable  = $true
				displaymodal = $false
			}
			
			# Add the Alert to the Arraylist
			$UpdateNotes.add($NewAlert)
				
			# Add the array of all old and new alerts to an update object
			$CompanyUpdate = @{
				id          = $HaloCompany.id
				popup_notes = $UpdateNotes
			}
			
			# Perform the update
			$null = Set-HaloClient -Client $CompanyUpdate
		
			
		}
	}
				
}

You may also like...