Skip to main content

Script or Action

Generated Cmdlet Help

This page has been generated from the NinjaOne PowerShell module source. To make changes please edit the appropriate PowerShell source file.

SYNOPSIS

Runs a script or built-in action against the given device.

SYNTAX

ACTION

Invoke-NinjaOneDeviceScript [-deviceId] <Int32> [-type] <String> [-actionUId] <Guid> [[-parameters] <String>]
[-runAs] <String> [-show] [-ProgressAction <ActionPreference>] [<CommonParameters>]

SCRIPT

Invoke-NinjaOneDeviceScript [-deviceId] <Int32> [-type] <String> [-scriptId] <Int32> [[-parameters] <String>]
[-runAs] <String> [-show] [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

Runs a script or built-in action against a single device using the NinjaOne v2 API.

EXAMPLES

EXAMPLE 1

# FULL REQUEST EXAMPLE (AUTO-GENERATED) - BEGIN
PS> $body = @{
runAs = "string"
type = "ACTION"
id = 0
uid = "00000000-0000-0000-0000-000000000000"
parameters = "string"
}
PS> Invoke-NinjaOneDeviceScript -deviceId 1 -deviceId $body
# FULL REQUEST EXAMPLE (AUTO-GENERATED) - END

Full request example (auto-generated).

EXAMPLE 2

Invoke-NinjaOneDeviceScript -deviceId 1 -type 'SCRIPT' -scriptId 1 -runAs 'system'

Runs the script with id 1 against the device with id 1 with system-level permissions.

EXAMPLE 3

Invoke-NinjaOneDeviceScript -deviceId 1 -type 'ACTION' -actionUId '00000000-0000-0000-0000-000000000000' -runAs 'system'

Runs the built-in action with uid 00000000-0000-0000-0000-000000000000 against the device with id 1 with system-level permissions.

EXAMPLE 4

Invoke-NinjaOneDeviceScript -deviceId 1 -type 'SCRIPT' -scriptId 1 -runAs 'loggedonuser'

Runs the script with id 1 as the currently logged-on user on device 1.

EXAMPLE 5

Invoke-NinjaOneDeviceScript -deviceId 1 -type 'SCRIPT' -scriptId 1 -runAs '26'

Runs the script with id 1 using the preferred credential with ID 26.

PARAMETERS

-deviceId

The device to run a script on.

Type: Int32
Parameter Sets: (All)
Aliases: id

Required: True
Position: 1
Default value: 0
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False

-type

The type - script or action.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-scriptId

The id of the script to run. Only used if the type is script.

Type: Int32
Parameter Sets: SCRIPT
Aliases:

Required: True
Position: 3
Default value: 0
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-actionUId

The unique uid of the action to run. Only used if the type is action.

Type: Guid
Parameter Sets: ACTION
Aliases:

Required: True
Position: 3
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-parameters

The parameters to pass to the script or action.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-runAs

The credential/role identifier to use when running the script or action. This parameter is case-sensitive and controls the permission level. Valid values are:

  • 'system': Run with system-level permissions (maps to general.system)
  • 'SR_MAC_SCRIPT': Run with system-level permissions on macOS (maps to general.system)
  • 'SR_LINUX_SCRIPT': Run with system-level permissions on Linux (maps to general.system)
  • 'loggedonuser': Run as the currently logged-on user (maps to editor.credentials.currentLoggedOnUser)
  • 'SR_LOCAL_ADMINISTRATOR': Run as local administrator (maps to editor.credentials.preferredWindowsLocalAdmin)
  • 'SR_DOMAIN_ADMINISTRATOR': Run as domain administrator (maps to editor.credentials.preferredWindowsDomainAdmin)
  • A credential ID as a string (e.g., '26'): Run using a specific user credential from your account. You can find credential IDs in the NinjaOne UI under Account > Credentials (maps to editor.credentials.preferredCredential)
Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 5
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-show

Show the status code returned from the API.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.Void

This commandlet returns no output by default. A success message will be written to the information stream if the API returns a 204 success code. Use -InformationAction Continue to see this message. Use the -show switch to return the HTTP status code.

NOTES

https://docs.homotechsual.dev/modules/ninjaone/commandlets/Invoke/scriptoraction