with one click
ninjaone-tags
// Use when code uses Get-NinjaTag, Set-NinjaTag, Remove-NinjaTag, ninjarmm-cli tag-get/tag-set/tag-clear, or user asks about NinjaOne device tagging, tag-based automation, or tag management.
// Use when code uses Get-NinjaTag, Set-NinjaTag, Remove-NinjaTag, ninjarmm-cli tag-get/tag-set/tag-clear, or user asks about NinjaOne device tagging, tag-based automation, or tag management.
| name | ninjaone-tags |
| description | Use when code uses Get-NinjaTag, Set-NinjaTag, Remove-NinjaTag, ninjarmm-cli tag-get/tag-set/tag-clear, or user asks about NinjaOne device tagging, tag-based automation, or tag management. |
NinjaOne tags classify devices (endpoints) beyond roles and custom fields. Tags enable device searches, automation assignment with conditions, and filtered queries.
Retrieves all tags assigned to the current device.
Syntax:
Get-NinjaTag
Returns: Array of strings containing tag names
Example:
# Get all tags assigned to this device
$tags = Get-NinjaTag
# Display all tags
$tags
# Access specific tag by index
$tags[0]
# Check if specific tag exists
if ($tags -contains "Production") {
Write-Output "Device is tagged as Production"
}
# Count tags
$tagCount = $tags.Count
Write-Output "Device has $tagCount tags"
Assigns a tag to the current device.
Syntax:
Set-NinjaTag [-Name] <String>
Parameters:
Name (String, Mandatory) - The tag name to assignReturns: None. Throws error if tag doesn't exist in the organization.
Example:
# Assign a tag
Set-NinjaTag -Name "Production"
# Assign using positional parameter
Set-NinjaTag "Development"
# Assign multiple tags
@("Web Server", "North Region", "Priority 1") | ForEach-Object {
Set-NinjaTag -Name $_
}
# Assign tag with validation
$tagName = "Production"
try {
Set-NinjaTag -Name $tagName
Write-Output "Successfully assigned tag: $tagName"
} catch {
Write-Error "Failed to assign tag '$tagName': $_"
}
Error Handling:
Removes a tag from the current device.
Syntax:
Remove-NinjaTag [-Name] <String>
Parameters:
Name (String, Mandatory) - The tag name to removeReturns: None. Throws error if tag doesn't exist in the organization.
Example:
# Remove a tag
Remove-NinjaTag -Name "Development"
# Remove using positional parameter
Remove-NinjaTag "Test Environment"
# Remove multiple tags
@("Old Tag", "Deprecated") | ForEach-Object {
try {
Remove-NinjaTag -Name $_
Write-Output "Removed tag: $_"
} catch {
Write-Warning "Could not remove tag '$_': $($_.Exception.Message)"
}
}
# Conditional tag removal
$tags = Get-NinjaTag
if ($tags -contains "Temporary") {
Remove-NinjaTag -Name "Temporary"
Write-Output "Removed temporary tag"
}
Lists all tags assigned to the device.
Syntax:
ninjarmm-cli tag-get
Returns: One tag per line
Example:
# Execute from PowerShell
$output = & ninjarmm-cli tag-get
$tags = $output -split "`n" | Where-Object { $_ -ne '' }
# Process each tag
foreach ($tag in $tags) {
Write-Output "Found tag: $tag"
}
Assigns a tag to the device.
Syntax:
ninjarmm-cli tag-set "Tag Name"
Example:
# Assign a tag via CLI
& ninjarmm-cli tag-set "Production"
# With error handling
$tagName = "Web Server"
$result = & ninjarmm-cli tag-set $tagName 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to set tag: $result"
}
Removes a tag from the device.
Syntax:
ninjarmm-cli tag-clear "Tag Name"
Example:
# Remove a tag via CLI
& ninjarmm-cli tag-clear "Development"
# With validation
$tagName = "Old Configuration"
$result = & ninjarmm-cli tag-clear $tagName 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Output "Successfully removed tag: $tagName"
} else {
Write-Warning "Could not remove tag: $result"
}
<#
.SYNOPSIS
Performs maintenance only on devices tagged for maintenance window.
#>
[CmdletBinding()]
param()
$tags = Get-NinjaTag
if ($tags -contains "Maintenance Approved") {
Write-Output "Device is approved for maintenance, proceeding..."
# Perform maintenance operations
# Remove maintenance tag after completion
Remove-NinjaTag -Name "Maintenance Approved"
# Add completion tag
Set-NinjaTag -Name "Maintenance Completed"
Write-Output "Maintenance completed successfully"
exit 0
} else {
Write-Output "Device not approved for maintenance, skipping..."
exit 0
}
<#
.SYNOPSIS
Automatically tags devices based on their role or configuration.
#>
[CmdletBinding()]
param()
try {
# Detect server role
$windowsFeatures = Get-WindowsFeature | Where-Object { $_.Installed }
# Tag as web server
if ($windowsFeatures.Name -contains "Web-Server") {
Set-NinjaTag -Name "Web Server"
Write-Output "Tagged as Web Server"
}
# Tag as database server
if (Get-Service -Name 'MSSQLSERVER' -ErrorAction SilentlyContinue) {
Set-NinjaTag -Name "Database Server"
Write-Output "Tagged as Database Server"
}
# Tag by organization
$orgName = $env:NINJA_ORGANIZATION_NAME
if ($orgName -like "*Production*") {
Set-NinjaTag -Name "Production"
Write-Output "Tagged as Production based on organization"
}
exit 0
} catch {
Write-Error "Tagging failed: $_"
exit 1
}
<#
.SYNOPSIS
Removes deprecated tags and standardizes tag naming.
#>
[CmdletBinding()]
param()
$deprecatedTags = @("Old System", "Legacy", "To Be Removed")
$tagMapping = @{
"Prod" = "Production"
"Dev" = "Development"
"QA" = "Quality Assurance"
}
try {
$currentTags = Get-NinjaTag
# Remove deprecated tags
foreach ($tag in $currentTags) {
if ($tag -in $deprecatedTags) {
Remove-NinjaTag -Name $tag
Write-Output "Removed deprecated tag: $tag"
}
}
# Standardize tag names
foreach ($tag in $currentTags) {
if ($tagMapping.ContainsKey($tag)) {
$newTag = $tagMapping[$tag]
Remove-NinjaTag -Name $tag
Set-NinjaTag -Name $newTag
Write-Output "Replaced '$tag' with '$newTag'"
}
}
exit 0
} catch {
Write-Error "Tag cleanup failed: $_"
exit 1
}
<#
.SYNOPSIS
Reports current device tags to a multi-line custom field for visibility.
#>
[CmdletBinding()]
param()
try {
$tags = Get-NinjaTag
if ($tags.Count -eq 0) {
$tagReport = "No tags assigned"
} else {
$tagReport = $tags -join ", "
}
# Store in custom field for dashboard visibility
Set-NinjaProperty -Name "deviceTags" -Value $tagReport -Type "MultiLine"
Write-Output "Tag report: $tagReport"
exit 0
} catch {
Write-Error "Tag reporting failed: $_"
exit 1
}
Get-NinjaTag to check current tags before adding/removingFor tag operations via REST API, refer to the ninjaone-api skill. The API supports:
API operations are performed through NinjaOne Public API v2 endpoints.