Using PowerShell Script Upload The Package In Orchestrator With OAuth Authentication Using External Application Feature

Using the external application feature, how to deploy the nupkg package in Orchestrator using PowerShell script with OAuth authentication using the external application feature?

Use the below script to upload packages using external application (OAuth) authentication feature. All the BOLD values needs to be updated as per the environment.

=======================================================================================

$body = @{

client_id = "be5cc241-64da-4483-81cd-4f928b76aa56"

scope = "OR.Execution OR.Execution.Write OR.Jobs"

client_secret = "rdyMsc6YDEQ2X(a"

grant_type = "client_credentials"

}

$token= Invoke-RestMethod -Method POST -URI "https://orchUrl/identity/connect/token" -Body $body

Write-Host "Access Token:" $token.access_token

$accessTokenStore=$token.access_token

$boundary = "----WebKitFormBoundaryaaUBEnK21nqVaDsE"

$authHeader1 = @{

"accept"="application/json"

"Authorization"="Bearer $accessTokenStore"

}

$path='C:\Temp\Utils_Custom-ReFramework.1.0.55.nupkg'

$enc = [System.Text.Encoding]::GetEncoding("iso-8859-1")

$fileBin = [IO.File]::ReadAllBytes($Path)

$fileEnc = $enc.GetString($fileBin)

$LF = "`r`n"

$bodyLines = (

"--$boundary",

"Content-Disposition: form-data; name=`"file`"; filename=`"Utils_Custom-ReFramework.1.0.55.nupkg`"",

"Content-Type: application/octet-stream$LF",

$fileEnc,

"--$boundary--$LF"

) -join $LF

$URL="https://OrchUrl/odata/Processes/UiPath.Server.Configuration.OData.UploadPackage"

$result=Invoke-RestMethod -Method POST -Headers $AuthHeader1 -ContentType "multipart/form-data; boundary=$boundary" -Uri $URL -Body $bodyLines

Write-Host($result)

=====================================================================================