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

PowerShell: Set NinjaProperty

Topic

This article explains how to use Set-NinjaProperty to set the value of a custom field based on its name and type.

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

The Set-NinjaProperty cmdlet allows you to set the value of a custom field by specifying its name, type, and value. If a type is specified, it automatically converts the provided value to a format compatible with the specified field type. For instance, if a DateTime object is provided and the type is "Date," the cmdlet converts the value to a Unix epoch timestamp before setting the field.

This cmdlet also supports setting values for dropdown and multi-select fields using field names instead of GUIDs. Supported field types include: "Checkbox", "Date", "Date", "DateTime", "Decimal",
"Dropdown", "Email", "Integer", "IP Address", "MultiLine", "MultiSelect", "Phone", "Secure", "Text", "Time", "URL", and "WYSIWYG."

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. The device executing this cmdlet must be a document delegate for the document containing the custom field if the -DocumentName parameter is used.

Syntax

Set-NinjaProperty [-Name] <String> [[-Value] <Object>] [[-Type] <String>] [[-DocumentName] <String>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

Examples

Example 1: Checkbox Custom Field

Set-NinjaProperty -Name "deployed" -Value $True -Type "Checkbox"

Sets the custom field "deployed" to true. Acceptable Checkbox Values: 0, 1, True, False or a Boolean value.

Example 2: Date Custom Field

$DeploymentDate = Get-Date -Year "2026" -Month "02" -Day "01" -Hour "0" -
Minute "0" -Second "0"
Set-NinjaProperty -Name "deploymentDate" -Value $DeploymentDate -Type "Date"

Sets the custom field "deploymentDate" to the specified date. Acceptable Date Values: DateTime objects or strings convertible to DateTime.

Example 3: Date and Time Custom Field

$LastSeen = Get-Date -Year "2026" -Month "02" -Day "02" -Hour "13" -Minute
"0" -Second "0"
Set-NinjaProperty -Name "lastSeen" -Value $LastSeen -Type "DateTime"

Sets the custom field "lastSeen" to the specified date and time. Acceptable Date and Time Values: DateTime objects or strings convertible to DateTime.

Example 4: Decimal Custom Field

PS C:> Set-NinjaProperty -Name "pi" -Value 3.14 -Type "Decimal"

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:> Set-NinjaProperty -Name "favoriteBand" -Value "Mötley Crüe" -Type
"Dropdown"

In this Example, the favoriteBand dropdown custom field is set to "Mötley Crüe" using the
option name instead of the GUID. Acceptable Drop-down Values: The name of one of the predefined options for the field.

Example 6: Email Custom Field

PS C:> Set-NinjaProperty -Name "supportEmail" -Value "[email protected]"
-Type "Email"

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:> Set-NinjaProperty -Name "favoriteNumber" -Value "42" -Type "Integer"

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:> Set-NinjaProperty -Name "primaryDNS" -Value "1.1.1.1" -Type
"IPAddress"

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

Example 9: Multi-line Custom Field

PS C:> Set-NinjaProperty -Name "exampleMultiline" -Value "Line 1`n`nLine 3"
-Type "MultiLine"

In this example, the exampleMultiline multi-line custom field is set to a string with multiple
lines of text. Acceptable Multi-line Values: Any string that's less than 10,000 characters.

Example 10: Multi-select Custom Field

PS C:> Set-NinjaProperty -Name "exampleMultiselect" -Value ("Value 3",
"Option 1") -Type "MultiSelect"

In this example, the exampleMultiselect multi-select custom field is set to "Value 3" and "Option 1" using the display names instead of GUIDs. Acceptable Multi-select Values: An array of strings representing the display names of the valid options to set, which can be found using the Ninja-Property-Options cmdlet.

Example 11: Phone Custom Field

PS C:> Set-NinjaProperty -Name "supportNumber" -Value "+18008675309" -Type
"Phone"

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:> Set-NinjaProperty -Name "superSecretPassword" -Value "Hunter42" -
Type "Secure"

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:> Set-NinjaProperty -Name "exampleTextField" -Value "My Text Value" -
Type "Text"

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"
PS C:> Set-NinjaProperty -Name "updateTime" -Value $UpdateTime -Type "Time"

In this example, the updateTime time custom field is set to 9:00 AM. Acceptable Time Values: A DateTime object representing a time, or a string that can be converted to a DateTime object.

Example 15: URL Custom Field

PS C:> Set-NinjaProperty -Name "exampleUrl" -Value
"https://www.ninjaone.com" -Type "URL"

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:> Set-NinjaProperty -Name "exampleWYSIWYG" -Value "<h1
style='color:#f015ca'>Hello World</h1>" -Type "WYSIWYG"

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. 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. 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 device or documentation custom field whose value you would like to set.

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

Specify the value to set for the specified custom field.

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

The type of custom field, which determines how the provided value is processed and converted.Supported types include: "Checkbox", "Date", "DateTime", "Decimal", "Dropdown", "Email", "Integer", "IP Address", "MultiLine", "MultiSelect", "Phone", "Secure", "Text", "Time", "URL", and "WYSIWYG".

Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-DocumentName

Specify the name of the document from which to set the value of the specified documentation custom field.

Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Force

If confirm is not specified and the cmdlet would prompt for confirmation, this parameter forces the cmdlet to run without asking for confirmation.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Common Parameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, - InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, - Verbose, -WarningAction, and -WarningVariable.For more information about common parameters, refer to Microsoft document about_CommonParameters (external link).

Inputs

Outputs

  • If you do not specify a type, the cmdlet will attempt to set the string value as-is. See Ninja-Property-Set examples for how values are processed when a type is not specified. 
  • Dropdown and MultiSelect values are validated against predefined options before being set.
  • If an invalid type is provided, a warning is displayed.
  • Non-breaking spaces are automatically replaced to the html equivalent &nbsp; for "WYSIWYG" types.
  • 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