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

PowerShell: Set-NinjaUser

Topic

This article explains how to use Set-NinjaUser to assign a specified user to a 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-NinjaUser cmdlet assigns a specified user to a device. The user is identified by their email address and can be an end user, technician, or contact. If an account or contact is limited to an organization, NinjaOne will only match devices that belong to the same organization as the user. Technicians must have permission to access the device. 

This cmdlet must be executed within a Ninja automation script to modify the assigned user.
Updates to the assigned user will be displayed in the NinjaOne webui upon a successful sync which usually occurs within a few minutes.

Syntax

Set-NinjaUser [-EmailAddress] <String> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

Examples

Example 1: Assign a User - Automation Script

PS C:> Set-NinjaUser -EmailAddress "[email protected]"
Request successfully sent to agent. See device activity feed to confirm the
user was assigned.

The user with the email address "[email protected]" is assigned to the specified device.

Example 2: Assign a User - Active Terminal

PS C:> Set-NinjaUser -EmailAddress "[email protected]"
Set-NinjaUser : Access to set user is possible only from automation script
At line:1 char:1
+ Set-NinjaUser -EmailAddress "[email protected]"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : FromStdErr: (:) [Write-Error],
WriteErrorException
+ FullyQualifiedErrorId :
Microsoft.PowerShell.Commands.WriteErrorException,Set-NinjaUser

You can only assign a user 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
-EmailAddress

Specify the email address of the user to assign to the device. The user must already exist inNinjaOne as an end user, technician, or contact.

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

If the Confirm parameter is not specified, the Force parameter will override ShouldProcess and allow the cmdlet to continue processing.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
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

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

This cmdlet accepts a string representing the email address of the user to assign to the device.

Outputs

None

  • The user must already exist in NinjaOne as an end user, technician, or contact.
  • NinjaOne will display the new unmanaged device upon a successful sync, which usually occurs within a few minutes.

Additional Resources

For more information about asset management and custom scripting, refer to the following resources:

FAQ

Next Steps