Already a NinjaOne customer? Log in to view more guides and the latest updates.

PowerShell: Ninja Property Set

Topic

This article explains how to use Ninja-Property-Set to set the value of a specified device custom field.

Ninja-Property-Set is a legacy cmdlet. While it may still work, we recommend using Set-NinjaProperty instead.
If you use the NinjaOne PowerShell Module outside of an automation script, you may need to adjust PowerShell's execution policy. For more information about execution policies, refer to Microsoft's documentation: about Execution Policies (external link).

Environment

  • NinjaOne
  • Microsoft PowerShell

Description

This cmdlet sets the value of a specified device custom field. You can specify the field name using the -Name parameter and the value to set using the -Value parameter. The cmdlet updates the value of the specified custom field on the device.

Only fields with automation write permissions can be updated using this cmdlet. The specified custom field is updated after the next successful sync with the NinjaOne platform, which typically occurs within a few minutes.

Syntax

Ninja-Property-Set [[-Name] <Object>] [[-Value] <Object>] [<CommonParameters>]

Examples

Example 1: Checkbox Custom Field

PS C:> Ninja-Property-Set -Name "deployed" -Value $True

In this example, the deployed checkbox custom field is checked by setting its value to $True . You could also check the box using 1 instead of $True , as both values are accepted for checkbox custom fields. Acceptable Checkbox Values: 0, 1, true, false.

Example 2: Date Custom Field

$DeploymentDate = Get-Date -Year "2026" -Month "02" -Day "01" -Hour "0" -
Minute "0" -Second "0"
$StartOfEpoch = Get-Date -Year "1970" -Month "01" -Day "01" -Hour "0" -
Minute "0" -Second "0"
$DeploymentInUTC = $DeploymentDate.ToUniversalTime()
$TimeSpan = New-TimeSpan -Start $StartOfEpoch -End $DeploymentInUTC
$DeploymentInEpochTime = [math]::Round($TimeSpan.TotalSeconds)
PS C:> Ninja-Property-Set -Name "deploymentDate" -Value
$DeploymentInEpochTime

In this example, the deploymentDate date custom field is set to February 1, 2026. The date is converted to epoch time (the number of seconds that have elapsed since January 1, 1970 UTC) before being set as the value of the custom field, as date custom fields in the CLI accept epoch time values. Acceptable Date Formats: Unix Epoch Time (seconds since January 1, 1970 UTC), ISO format 'yyyy-MM-dd' UTC

Example 3: Date and Time Custom Field

$LastSeen = Get-Date -Year "2026" -Month "02" -Day "02" -Hour "13" -Minute
"0" -Second "0"
$StartOfEpoch = Get-Date -Year "1970" -Month "01" -Day "01" -Hour "0" -
Minute "0" -Second "0"
$LastSeenInUTC = $LastSeen.ToUniversalTime()
$TimeSpan = New-TimeSpan -Start $StartOfEpoch -End $LastSeenInUTC
$LastSeenInEpochTime = [math]::Round($TimeSpan.TotalSeconds)
PS C:> Ninja-Property-Set -Name "lastSeen" -Value $LastSeenInEpochTime

In this example, the lastSeen date and time custom field is set to February 2, 2026 at 1:00 PM. The date and time value is converted to epoch time (the number of seconds that have elapsed since January 1, 1970 UTC) before being set as the value of the custom field, as date and time custom fields in the CLI accept epoch time values. Acceptable Date and Time Formats: Unix Epoch Time (seconds since January 1, 1970 UTC), ISO format 'yyyy-MM-ddTHH:mm:ss' UTC

Example 4: Decimal Custom Field

PS C:> Ninja-Property-Set -Name "pi" -Value "3.14"

In this example, the pi decimal custom field is set to 3.14. Acceptable Decimal Values: Any number from -9999999.999999 to 9999999.999999.

Example 5: Drop-down Custom Field

PS C:> Ninja-Property-Set -Name "favoriteBand" -Value "2a100199-4067-4332-
8f4d-451e14b94a76"

In this example, the favoriteBand drop-down custom field is set to the option with the guid of 2a100199-4067-4332-8f4d-451e14b94a76 . Drop-down custom fields in the CLI accept the guid of the option you want to set, which can be found using the Ninja-Property- Options cmdlet. Acceptable Drop-down Values: The guid of the option to set, which can be found using the Ninja-Property-Options cmdlet.

Example 6: Email Custom Field

PS C:> Ninja-Property-Set -Name "supportEmail" -Value
"[email protected]"

In this example, the supportEmail email custom field is set to "[email protected]". Acceptable Email Values: Any string that follows the RFC 5322 official standard for email addresses.

Example 7: Integer Custom Field

PS C:> Ninja-Property-Set -Name "favoriteNumber" -Value "42"

In this example, the favoriteNumber integer custom field is set to 42. Acceptable Integer Values: Any whole number from -2147483648 to 2147483647.

Example 8: IP Address Custom Field

PS C:> Ninja-Property-Set -Name "primaryDNS" -Value "1.1.1.1"

In this example, the primaryDNS IP address custom field is set to "1.1.1.1". Acceptable IP Address Values: Any valid IPv4 or IPv6 address.

Example 9: Multi-line Custom Field

PS C:> Ninja-Property-Set -Name "exampleMultiline" -Value "Line 1`n`nLine
3"

In this example, the exampleMultiline multi-line custom field is set to a string with multiple lines of text.

Example 10: Multi-select Custom Field

PS C:> Ninja-Property-Set -Name "exampleMultiselect" -Value "154d90cf-3d4a-
4e43-8b79-232ccd5b74a6, 834d0865-1c70-492b-ac11-73854fd0294d"

In this example, the exampleMultiselect multi-select custom field is set to the options with the guids of 154d90cf-3d4a-4e43-8b79-232ccd5b74a6 and 834d0865-1c70-492b-ac11-73854fd0294d . Multi-select custom fields in the CLI accept a comma-separated list of guids representing the options you want to set, which can be found using the Ninja-Property-Options cmdlet. Acceptable Multi-select Values: A comma-separated list of guids representing the options to set, which can be found using the Ninja-Property-Options cmdlet.

Example 11: Phone Custom Field

PS C:> Ninja-Property-Set -Name "supportNumber" -Value "+18008675309"

In this example, the supportNumber phone custom field is set to "+18008675309". Acceptable Phone Values: Any string that follows the E.164 standard for phone numbers, which includes a plus sign followed by the country code and subscriber number (e.g.,+18008675309).

Example 12: Secure Custom Field

PS C:> Ninja-Property-Set -Name "superSecretPassword" -Value "Hunter42"

In this example, the superSecretPassword secure custom field is set to "Hunter42".Acceptable Secure Values: Any string that's less than 200 characters.

Example 13: Text Custom Field

PS C:> Ninja-Property-Set -Name "exampleTextField" -Value "My Text Value"

In this example, the exampleTextField text custom field is set to "My Text Value". Acceptable Text Values: Any string that's less than 200 characters.

Example 14: Time Custom Field

$UpdateTime = Get-Date -Hour "09" -Minute "0" -Second "0"
$LocalTimeZone =[System.TimeZoneInfo]: :Local
$UpdateTimeInUTC =[System.TimeZoneInfo]: :ConvertTimeToUtc($UpdateTime,
$LocalTimeZone)
$TimeInSecondsSinceMidnight =
[math]: :Round(($UpdateTimeInUTC.TimeOfDay).TotalSeconds)
PS C:> Ninja-Property-Set -Name "updateTime" -Value
$TimeInSecondsSinceMidnight

In this example, the updateTime time custom field is set to 9:00 AM. The time value is converted to the number of seconds since midnight in UTC before being set as the value of the custom field, as time custom fields in the CLI only accept values in this format. Acceptable Time Values: The number of seconds since midnight UTC, or a time string in the format 'HH:mm:ss' UTC.

Example 15: URL Custom Field

PS C:> Ninja-Property-Set -Name "exampleUrl" -Value "https://www.ninjaone.com"

In this example, the exampleUrl URL custom field is set to "https://www.ninjaone.com". Acceptable URL Values: Any string thats less than 200 characters and begins with https:// .

Example 16: WYSIWYG Custom Field

PS C:> Ninja-Property-Set -Name "exampleWYSIWYG" -Value "<h1
style='color:#f015ca'>Hello World</h1>"

In this example, the exampleWYSIWYG WYSIWYG custom field is set to "<h1 style='color:#f015ca'>Hello World</h1>" . WYSIWYG custom fields in the CLI accept HTML as a value, which allows for rich text formatting in the custom field. To access the full capabilities of WYSIWYG custom fields, it is recommended to use Set NinjaProperty or Ninja-Property-Set-Piped as they support larger character limits for custom field values compared to Ninja-Property-Set .

Using single quotes in your html is recommended to avoid having to escape double quotes in your html string when setting a WYSIWYG custom field value using Ninja-Property- Set . Acceptable WYSIWYG Values: Any string that's less than 199,999 characters. The string should contain valid HTML for best results, and using single quotes in the HTML is recommended to avoid having to escape double quotes in the HTML string.

Parameters

-Name

Specify the name of the custom field for which you want to set a value.

Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Value

Specify the value to set for the specified custom field.

Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Inputs

System.String

The cmdlet does not accept input from the pipeline. The -Name and -Value parameters accept string values representing the name of the custom field to set and the value to set for the custom field, respectively.

Outputs

None

  • Only fields with automation write permissions can have their options retrieved using this cmdlet. For information about permissions for custom fields refer to NinjaOne Custom Fields: Getting Started.
  • The specified custom field is updated after the next successful sync with the NinjaOne platform, which typically occurs within a few minutes.

Additional Resources

For more information about asset management and custom scripting, refer to the following resources:

FAQ

Next Steps