Powershell Script is not working in UIpath

hi All,

when we are trying to execute the below PowerShell script code.

its not executing can any one help me.

$auth = @{
tenancyName = “default”
usernameOrEmailAddress = “CRAS_API”
password = “CRAS_TestAP2”
}

$authjson = $auth | ConvertTo-Json
$authkey = Invoke-RestMethod https://test.rpa.swissre.com/api/account/authenticate-Method Post -Body $authjson -ContentType ‘application/json’
$authjson = $authkey | ConvertTo-Json
$tokenInJSon = $authjson | ConvertFrom-Json
$token = 'Bearer ’ + “$($tokenInJson.result)”
$token | ConvertTo-Json

Get Release Key

##$releaseIdOut = Invoke-RestMethod "https://test.rpa.swissre.com/odata/Releases?$select=Key&$filter=ProcessKey eq ‘{ProcessName}’ and EnvironmentName eq ‘{EnvironmentName}’ and OrganizationUnitId eq 1

Get folder details. Id is the value for X-UIPATH-OrganizationUnitId

$FolderHeader = @{‘Authorization’ = $token }

$FolderResponse = Invoke-RestMethod -Method GET -Uri ‘https://test.rpa.swissre.com/odata/Folders?$orderby=Id asc’ -Headers $FolderHeader

$FolderResponse | ConvertTo-Json

Start a job

$StartJobHeader = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”

$FolderId = 1

$StartJobHeader.Add(“X-UIPATH-OrganizationUnitId”, $FolderId)

$StartJobHeader.Add(“Accept”, “application/json, text/plain, /”)

$StartJobHeader.Add(“Content-Type”, “application/json”)

$StartJobHeader.Add(“Authorization”, $token)

$jobBody = ‘{
“startInfo” : {
“ReleaseKey” : “345f0d11-c5cf-46c2-b4a3-83364cd23718”,
“JobsCount”: 1,
“JobPriority”: “Normal”,
“Strategy”: “ModernJobsCount”,
“ResumeOnSameContext”: false,
“RuntimeType”: “Unattended”,
“InputArguments”: “{}”
}
}’

$StartJobResponse = Invoke-RestMethod " https://test.rpa.swissre.com/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs" -Method Post -Headers $StartJobHeader -Body $StartJobBody

$StartJobResponse | ConvertTo-Json

Hi @tangudi-nagendra.gupta,

Welcome to UiPath community!

Can you please check below detailed documentation for the same.

Hi @tangudi-nagendra.gupta

Welcome to Community

Please also refer this

PowerShell and UiPath - “Invoke PowerShell” Tutorial | UiPath

Hope this helps,
Thanks.

Here is a sample . Doesn’t point to the original problem but it may help