Using powershell script as trigger

Hello everyone,

I wanted to try to trigger a Unattended Robot with a powershell script. Here’s how I want it works :

  1. A powershell script monitor one (or multiples) folder
  2. This script add a item to a orchestrator’s queue if any file is put into this folder
  3. This queue trigger the unattended robot
  4. The robot do the process

Why don’t you call the robot periodically?

In order to use as little as possible in anticipation of having other robots and other treatments to do later.

Why not use the activiter trigger?

Because it is not worth leaving a robot permanently activated for only one type of treatment.

I made some search on powershell interactions with orchestrator API and I found this : GitHub - UiPath/orchestrator-powershell: UiPath Orchestrator PowerShell cmdlet library

I managed to install the powershell module but I can’t connect with Get-UiPathAuthToken even though my orchestrator url is good (https://platform.uipath.com) and my credentials are good too. Is someone already tried to call orchestrator API with powershell could help me to connect and add a queue item ?

Hi,

I have not used these PS modules. I could start the jobs via the startJob API using below code. Hope this helps.

$json = “{”“tenancyName”" : ““Default””, ““usernameOrEmailAddress””:““admin user””, ““password”” : ““admin password””}"

$out = Invoke-WebRequest “https://yourorchestrator/api/account/authenticate” -Method Post -Body $json -ContentType “application/json”
$token = $out | ConvertFrom-Json
$bearerToken = $token.result

$headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$headers.Add(“Authorization”, “Bearer $bearerToken”)

$json_body = “{”“startInfo”“: {”“ReleaseKey”“: ““xyz-xyz-xyz-xyz””,”“RobotIds”“: [xx],”“NoOfRobots”“: 0,”“Strategy”“: ““Specific””}}”
Invoke-WebRequest “https://yourorchestrator/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs” -Method Post -Body $json_body -ContentType “application/json” -Headers $headers

Regards,
Shiju Mathew

3 Likes

Hi,
did you manage to move it forward? I intend to do something simillar but failed on “Add-UiPathQueueItem” step :frowning:

Cheers

Hey @J0ska

What is the actual issue here please ?

Thanks
#nK

Hi,
Thx for reply.
1/ I can authenticate
2/ I can set folder "Set-UiPathCurrentFolder -FolderPath “folder”
3/ I can see the queue "Get-UiPathQueueDefinition -Name “queue” | Format-Table
4/ But I can not add itne to the queue "Add-UiPathQueueItem -QueueName “queue” -Reference “1111” -Priority “Normal” "
:frowning:

The error is:
Add-UiPathQueueItem : Value cannot be null.
Parameter name: source
At \testdrive\testdrive.ps1:32 char:1

  • Add-UiPathQueueItem -QueueName “queue” -Reference “1111” -Priori …
  •   + CategoryInfo          : NotSpecified: (:) [Add-UiPathQueueItem], ArgumentNullException
      + FullyQualifiedErrorId : System.ArgumentNullException,UiPath.PowerShell.Cmdlets.AddQueueItem
1 Like

Okay let me check please…

Same issue, may be a bug - Because the same works from API request but failing from PS.

Thx for checking. Will use API call instead.
Cheers

Cool, but let’s report this.