Note: If you’re interested in Ninja scripts, you will find another blog here with helpful scripts too for NinjaOne at – 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

  1. Go to Administration > Devices > Global Custom Fields
  2. Click Add > Field
  3. Call the Label Monitors and set Select Field Type to Multi-line
  4. Click Create
  5. In the Automations dropdown, select Read/Write
  6. In the Definition Scope dropdown, select Device
  7. Set a description/tooltip text/footer text as per your own requirements
  8. Click Save

Creating the Script

  1. Navigate to Administration > Library > Automation
  2. Click Add > New Script
  3. Enter an Automation name as required, like “Custom Field Population Script – Monitors”
  4. Enter a description if required
  5. Set a category
  6. Set the language as PowerShell
  7. Set the operating system as Windows
  8. Set the architecture as All
  9. 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
  1. Choose Save

Test the Script

  1. Navigate to any online device and run the script we just created. Leave the script to complete then give it a minute or two
  2. 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.

  1. Open up the policy for the devices you want to populate the monitors field with and navigate to Scheduled Automations
  2. Give the schedule a name, like “Custom Field Population – Monitors”
  3. Set an appropriate schedule based on how often you need this field to update
  4. Click Add on Automations and select the Custom Field script
  5. Click Add to add the Scheduled Automation