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

PowerShell: Set NinjaTag

Topic

This article explains how to use Set-NinjaTag to assign a specified system tag to the current device.

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-NinjaTag cmdlet assigns one or more specified system tags to the current device. System tags are predefined tags in the NinjaOne platform that can be used to categorize and manage devices. The cmdlet adds the specified tag(s) to the current device without affecting any existing tags. 

This cmdlet must be executed within a Ninja automation script to modify the assigned system tags. Tag assignment changes are applied after the next successful sync with the NinjaOne platform, which typically occurs within a few minutes.

Syntax

Set-NinjaTag [-Name] <String[]> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

Examples

Example 1: Assign from Automation Script

PS C:> Set-NinjaTag -Name "IIS"

Assigns the "IIS" system tag to the current device.

Example 2: Assign from Active Terminal

PS C:> Set-NinjaTag -Name "IIS"
Set-NinjaTag : Access to tags is possible only from automation script
At line:1 char:1
+ Set-NinjaTag -Name "IIS"
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : FromStdErr: (:) [Write-Error],
WriteErrorException
+ FullyQualifiedErrorId :
Microsoft.PowerShell.Commands.WriteErrorException,Set-NinjaTag

Tags are only settable from an automation script, so an error message is returned when attempting to run the cmdlet in an active terminal session.

Parameters

-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
-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: None
Accept pipeline input: False
Accept wildcard characters: False
-Name

Specify the name of the system tag(s) to assign to the current device.

Type: String[]
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
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

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

System.String[]

The cmdlet accepts an array of strings representing the name(s) of the system tag(s) to assign to the current device.

Outputs

None

  • This cmdlet must be executed within a Ninja automation script to modify the assigned system tags.
  • Tag assignment changes are applied after the next successful sync with the NinjaOneplatform, 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