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

PowerShell: Ninja Property Set Piped

Topic

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

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 Ninja-Property-Set-Piped cmdlet sets the value of a specified device custom field using the PowerShell pipeline. You can specify the name of the custom field using the -Name parameter. The value can be provided via the pipeline or using the -Value parameter. The cmdlet updates the value of the specified custom field for the device with the provided value.

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-Piped [[-Name] <Object>] [[-Value] <Object>] [<CommonParameters>]

Examples

Example 1: Setting a Custom Field with 199,999 Characters

$alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ1234567890"
$DesiredValue = New-Object System.Collections.Generic.List[String]
for($i = 0; $i -lt 199999; $i++){
$DesiredValue.Add("$($alphabet[(Get-Random -Maximum
$alphabet.Length)])")
}
$CustomFieldValue = "$($DesiredValue -join '')"
PS C:> Ninja-Property-Set-Piped -Name "exampleWYSIWYG" -Value
$CustomFieldValue

Piped commands can be used to set the value of a custom field to a long string such as 199,999 characters, which is the maximum length for a WYSIWYG custom field. In this example, a random string of 199,999 characters is generated and set as the value of the exampleWYSIWYG custom field.

Example 2: Pipeline Support

$alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ1234567890"
$DesiredValue = New-Object System.Collections.Generic.List[String]
for($i = 0; $i -lt 199999; $i++){
$DesiredValue.Add("$($alphabet[(Get-Random -Maximum
$alphabet.Length)])")
}
$CustomFieldValue = "$($DesiredValue -join '')"
PS C:>$CustomFieldValue | Ninja-Property-Set-Piped -Name "exampleWYSIWYG"

Piped commands can be used to set the value of a custom field to a long string such as 199,999 characters, which is the maximum length for a WYSIWYG custom field. In this example, a random string of 199,999 characters is generated and set as the value of the exampleWYSIWYG custom field.

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: True (ByValue)
Accept wildcard characters: False

Inputs

System.String

The cmdlet accepts string input from the pipeline for the -Value parameter, which represents the value to set for the specified custom field. The -Name parameter accepts a string value representing the name of the custom field for which you want to set a value, but it does not accept pipeline input.

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