Update Custom Asset Fields with Text from Custom Registry Key via Powershell Script?

We’re trying to write a custom value (text) to a custom registry key and then have the Syncro Agent (via Powershell Script) grab that data and write it to a custom asset field

@jeff I saw you and @VerandaTech going back and forth a bit about pushing RegKey Data to Custom Asset Fields in the post below:

REGKEY data to CUSTOM ASSET FIELDS

Wondering if you or anyone else might have some insight on how I might manipulate that script to meet my needs?

Might be super simple, but it’s 3:30am and I think it’s time to “phone a friend” lol

Any help would be greatly appreciated!

To expand on the example, here are a couple of commands to store arbitrary string data in a registry key. This is system wide in HKLM so use an admin account to store the data.

Powershell set the registry key

New-ItemProperty -Path "HKLM:\SOFTWARE\MSPNAME" -Name "Thing to track" -Value "Tracking Data" -PropertyType String -Force

Command Prompt style set the registry key

reg.exe ADD "HKEY_LOCAL_MACHINE\SOFTWARE\MSPNAME" /f /t REG_SZ /v "Thing to track" /d "Tracking Data"

Powershell to run from Syncro to pull registry item into custom asset field

## Required Syncro library module
Import-Module $env:SyncroModule
## Fetch value from registry
$TrackingData= Get-ItemPropertyValue "HKLM:\SOFTWARE\MSPNAME" -Name "Thing to track"
## Debug - show the value in the script output
Write-Host $TrackingData
## Store the value in a Syncro Asset custom field
Set-Asset-Field -Name "Tracking Data" -Value "$($TrackingData)"

Hi @jeff

Any ideas how I might be able to place and then grab a piece of custom text etc on a Mac/OSX and push it to a custom asset field.

Was successful using your PS Script to pull regkey data into the dashboard on a Win machine, so thanks a TON for that!

Now I just need to figure out how to do it on a Mac lol

I have not been able to test this very well. My scripts on the Mac side of Syncro don’t seem to be working.

#!/bin/bash
## Store the date in a text file
date > /tmp/test.txt
## Append some arbitrary text to the file starting with a line break
echo "\nScript ran successfully" >> /tmp/test.txt
## Read the text file into a variable called myvar
myvar=`cat /tmp/test.txt`
## Store the variable into a Syncro custom asset field called "Tracking Data" 
syncro set-asset-field --name="Tracking Data" --value=$myvar

@jeff This might sound like a dumb question, but here goes haha

If the Windows method uses Powershell, what exactly do you call what’s being to push it to the dashboard in OSX?

Not Powershell, right?

bash script

See the #!/bin/bash on the first line. That determines which command interpreter is used to process the script.