PowerShell Script to connect Robots with Orchestrator

Hi all,
I have machine key and URL with me, i need a power shell script where i can pass the Machine key and url so that Uipath assistant will connect with the Orchestrator

You can adapt the below approach. It will allow you to create a script with all the machine key/machine id credentials for each Orchestrator (On-Premise or Cloud) and use it easily in case you have a lot of robots to connect to and you need to speed up the process.

Save the below script let’s say as connect_robots.ps1

param (
[parameter(Mandatory=$true)]
[String] $connect_user,
[parameter(Mandatory=$true)]
[String] $connect_url,
[parameter(Mandatory=$true)]
[String] $connect_method
)

$UserAccount = $connect_user
$ConnectionURL = $connect_url
$ConnectMethod = $connect_method
$UiRobotExeLocationPath = "C:\Program Files\UiPath\Studio\UiRobot.exe"


if($ConnectionURL -eq ' https://ON_PREMISE_ORCHESTRATOR_HOSTNAME/'){
$ClientIdCredentials = @{}
$ClientIdCredentials.Add('your_domain\your_username', @{ClientID='YOUR_CLIENT_ID';ClientSecret='YOUR_CLIENT_SECRET'})
$ClientdID = $ClientIdCredentials[$UserAccount].ClientID
$ClientdSecret = $ClientIdCredentials[$UserAccount].ClientSecret

if($ConnectMethod -eq 'ClientIdConnection'){
Write-Host 'ClientIdConnection for '$UserAccount
$ConnectCommand = '/c "{0}" --connect --url {1} --clientID {2} --clientSecret {3}' -f $UiRobotExeLocationPath, $ConnectionURL, $ClientdID, $ClientdSecret
Start-Process -FilePath "C:\Windows\System32\cmd.exe" -ArgumentList $ConnectCommand
Write-Host 'ClientIdConnection was successful' -ForegroundColor green
}
if($ConnectMethod -eq 'MachineKeyConnection'){
Write-Host 'MachineKeyConnection for '$UserAccount
$ConnectCommand = '/c "{0}" --connect --url {1} --key {2}' -f $UiRobotExeLocationPath, $ConnectionURL, $ClientdID
Start-Process -FilePath "C:\Windows\System32\cmd.exe" -ArgumentList $ConnectCommand
Write-Host 'MachineKeyConnection was successful' -ForegroundColor green
}
}

if($ConnectionURL -eq ' https://cloud.uipath.com/YOUR_ORG_NAME/YOUR_TENANT_NAME/orchestrator_'){
$ClientIdCredentials = @{}
$ClientIdCredentials.Add('your_domain\your_username', @{ClientID='YOUR_CLIENT_ID';ClientSecret='YOUR_CLIENT_SECRET'})
$ClientdID = $ClientIdCredentials[$UserAccount].ClientID
$ClientdSecret = $ClientIdCredentials[$UserAccount].ClientSecret

if($ConnectMethod -eq 'ClientIdConnection'){
Write-Host 'ClientIdConnection for '$UserAccount
$ConnectCommand = '/c "{0}" --connect --url {1} --clientID {2} --clientSecret {3}' -f $UiRobotExeLocationPath, $ConnectionURL, $ClientdID, $ClientdSecret
Start-Process -FilePath "C:\Windows\System32\cmd.exe" -ArgumentList $ConnectCommand
Write-Host 'ClientIdConnection was successful' -ForegroundColor green
}
if($ConnectMethod -eq 'MachineKeyConnection'){
Write-Host 'MachineKeyConnection for '$UserAccount
$ConnectCommand = '/c "{0}" --connect --url {1} --key {2}' -f $UiRobotExeLocationPath, $ConnectionURL, $ClientdID
Start-Process -FilePath "C:\Windows\System32\cmd.exe" -ArgumentList $ConnectCommand
Write-Host 'MachineKeyConnection was successful' -ForegroundColor green
}
}

Execute the below command:

.\connect_robots.ps1 -connect_user domain\username -connect_url YOUR_ORCHESTRATOR_URL -connect_method YOUR_CONNECTION_METHOD 

or

Login into the Robot machine with the robot account and run the below command:

$UserToConnect = whoami
.\connect_robots.ps1 -connect_user $UserToConnect -connect_url YOUR_ORCHESTRATOR_URL -connect_method YOUR_CONNECTION_METHOD  

Example:

In case you didn’t supply a required parameter, the script will ask you to provide it:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.