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

PowerShell: Ninja Property Docs Set Piped

Topic

This article explains how to use Ninja-Property-Docs-Set-Piped to set the value of a specified custom field in a document 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

This cmdlet sets the value of a specified custom field in a document using the PowerShell pipeline. You can specify the field name using the -AttributeName parameter, the document using the -DocumentName parameter, and the document template using the -TemplateId parameter. The value can be provided via the pipeline or using the -Value parameter. The cmdlet updates the value of the specified custom field in the specified document with the provided value. 

Only fields with automation write permissions can be updated using this cmdlet. The device executing this cmdlet must be assigned as a documentation delegate for the document containing the custom field to be updated. The specified custom field in the document is updated after the next successful sync with the NinjaOne platform, which typically occurs within a few minutes.

Syntax

Ninja-Property-Docs-Set-Piped [[-TemplateId] <Object>] [[-DocumentName] <Object>] [[-AttributeName] <Object>] [[-Value] <Object>] [<CommonParameters>]

Examples

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

$alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ1234567890"
$DesiredValue = New-Object System.Collections.Generic.List
for($i = 0; $i -lt 199999; $i++){
$DesiredValue.Add("$($alphabet[(Get-Random -Maximum
$alphabet.Length)])")
}
$CustomFieldValue = "$($DesiredValue -join '')"
PS C:> Ninja-Property-Docs-Set-Piped -TemplateId "5" -DocumentName "My
Example Document" -AttributeName "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 in "My Example Document".

Example 2: Pipeline Support

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

The PowerShell pipeline can be used to set the value of a custom field by piping the desired
value into the Ninja-Property-Docs-Set-Piped cmdlet.

Parameters

-AttributeName

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

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

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

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

Specify the ID of the document template containing 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: 3
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 -TemplateId , -DocumentName , and -AttributeName parameters accept string values representing the ID of the document template, the name of the document, and the name of the custom field, respectively, for which you want to set a value.

Outputs

None

  • The device executing this cmdlet must be assigned as a documentation delegate for the document containing the custom field to be updated.
  • Only fields with automation write permissions can be updated using this cmdlet. For information about permissions for custom fields refer to NinjaOne Custom Fields: Getting Started.
  • The specified custom field in the document 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