Note: If you’re interested in Ninja scripts, you will find another blog here with helpful scripts too for NinjaOne at https://mspp.io/ – by my friend and fellow Product Manager Luke Whitelock.
This one was slightly harder than I initially anticipated because of how the data is stored, but here’s how to achieve this:
Creating the Custom Field
- Go to Administration > Devices > Global Custom Fields
- Click Add > Field
- Call the Label Monitors and set Select Field Type to Multi-line
- Click Create
- In the Automations dropdown, select Read/Write
- In the Definition Scope dropdown, select Device
- Set a description/tooltip text/footer text as per your own requirements
- Click Save
Creating the Script
- Navigate to Administration > Library > Automation
- Click Add > New Script
- Enter an Automation name as required, like “Custom Field Population Script – Monitors”
- Enter a description if required
- Set a category
- Set the language as PowerShell
- Set the operating system as Windows
- Set the architecture as All
- Enter the following script:
$Monitors = Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID
$ParsedMonitors = ForEach ($Monitor in $Monitors)
{
$Manufacturer = [System.Text.Encoding]::ASCII.GetString($Monitor.ManufacturerName).TrimEnd([char]0)
$Name = [System.Text.Encoding]::ASCII.GetString($Monitor.UserFriendlyName).TrimEnd([char]0)
$Serial = [System.Text.Encoding]::ASCII.GetString($Monitor.SerialNumberID).TrimEnd([char]0)
"$Manufacturer, $Name, $Serial `n"
}
Ninja-Property-Set 'monitors' $ParsedMonitors
- Choose Save
Test the Script
- Navigate to any online device and run the script we just created. Leave the script to complete then give it a minute or two
- Navigate to the Custom Fields tab on the device, and notice you now have the monitors custom field populated
-
Schedule the Script
Even though we have created the script and custom field, we now need a method to periodically populate it.
- Open up the policy for the devices you want to populate the monitors field with and navigate to Scheduled Automations
- Give the schedule a name, like “Custom Field Population – Monitors”
- Set an appropriate schedule based on how often you need this field to update
- Click Add on Automations and select the Custom Field script
- Click Add to add the Scheduled Automation
Leave A Comment