Powershell: Halo PSA improved Datto RMM sync
Someone over on MSPGeek this week pointed out that the built in integration for DattoRMM in Halo PSA wasn’t pulling over some key information like manufacturer and serial number. After have a chat with the guys at Halo it turns out the endpoint they are using doesn’t include that information! After having a look this information is only contained in the Audit endpoint and not the standard device endpoint.
To get this to work first you need to make sure you have a Rich text custom field called CFsoftwareDetails on your Assets. This can be done at
Configuration > Custom Objects > Custom Fields and select Asset from the dropdown in Halo PSA.
The additional asset fields will be added automatically so you don’t need to worry about those, its just the custom field you need to make sure is set.
Next setup the Datto RMM integration in Halo and get your assets to sync over.
Get your API details for both Halo and Datto RMM and add them to the script in a secure way.
Note: There is one workaround in the script at the moment to deal with a bug in Halo. The first time you add a field to an asset it will add the field but not the data. To fix this it just runs the update twice for each asset.
$HaloClientID = "Your Halo Client ID"
$HaloClientSecret = "Your Halo Secret"
$HaloURL = "Your Halo URL"
$DattoURL = "Your Datto API URL"
$DattoKey = "Your Datto Key"
$DattoSecretKey = "Your Datto Secret"
if (Get-Module -ListAvailable -Name DattoRMM) {
Import-Module DattoRMM
} else {
Install-Module DattoRMM -Force
Import-Module DattoRMM
}
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"
# Connect to Datto
# Provide API Parameters
$params = @{
Url = $DattoURL
Key = $DattoKey
SecretKey = $DattoSecretKey
}
# Set API Parameters
Set-DrmmApiParameters @params
$BaseHaloAssets = Get-HaloAsset
# Loop all assets
foreach ( $HaloBaseAsset in $BaseHaloAssets ) {
# Get the full version of the Halo Asset
$HaloAsset = Get-HaloAsset -AssetId $HaloBaseAsset.Id
# If the device is synced from Datto we will update its details
if ($HaloAsset.datto_id) {
# Collect all the device data from Datto RMM
$DattoDevice = Get-DrmmDevice -deviceUid $HaloAsset.datto_id
$DattoDeviceAudit = Get-DrmmAuditDevice -deviceUid $HaloAsset.datto_id
$DattoDeviceSoftwareHTML = Get-DrmmAuditDeviceSoftware -deviceUid $HaloAsset.datto_id | convertto-html -as table -fragment | out-string
# Build the Update Object
$UpdateAsset = @{
id = $HaloBaseAsset.Id
fields = @(
@{
name = "Antivirus Product"
value = $DattoDevice.antivirus.antivirusProduct
},
@{
name = "Description"
value = $DattoDevice.description
},
@{
name = "Device Category"
value = $DattoDevice.deviceType.category
},
@{
name = "Device Type"
value = $DattoDevice.deviceType.type
},
@{
name = "External IP Address"
value = $DattoDevice.extIPAddress
},
@{
name = "IP Address"
value = $DattoDevice.intIPAddress
},
@{
name = "Last Logged in User"
value = $DattoDevice.lastLoggedInUser
},
@{
name = "Mac Address"
value = ($DattoDeviceAudit.nics | Where-Object { $_.macAddress -ne '' }).macAddress -join ', '
},
@{
name = "Manufacturer"
value = $DattoDeviceAudit.systemInfo.manufacturer
},
@{
name = "Memory"
value = ($DattoDeviceAudit.PhysicalMemory.size | measure-object -sum).sum / 1024 / 1024 / 1024
},
@{
name = "Model"
value = $DattoDeviceAudit.systemInfo.model
},
@{
name = "Name"
value = $DattoDevice.hostname
},
@{
name = "OS Version"
value = $DattoDevice.operatingSystem
},
@{
name = "Processor"
value = $DattoDeviceAudit.processors.name
},
@{
name = "Serial Number"
value = $DattoDeviceAudit.bios.serialNumber
}
)
customfields = @(
@{
name = "CFsoftwareDetails"
value = $DattoDeviceSoftwareHTML
}
)
}
$null = Set-HaloAsset -Asset $UpdateAsset
# Workaround for API bug on first addition of fields not setting value.
$null = Set-HaloAsset -Asset $UpdateAsset
}
}