Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

Sample connectionJSON config for REST connection to run powershell scripts?

jralexander137
New Contributor III
New Contributor III

Hi I was wondering if anyone had a sample connectionJSON config they could share for use with a rest connector that will be used to launch powershell scripts. My understanding is that its preferable to launch PS Scripts using rest connector vs winconnector but I am unsure of how to craft the connectionJson to connect to the saviynt app installed on the windows server used to execute powershell scripts. 

Any sample would be greatly appreciated.

6 REPLIES 6

rushikeshvartak
All-Star
All-Star

Refer https://forums.saviynt.com/t5/identity-governance/rest-exchange-ps-1-script-not-triggered/m-p/36965


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

So i was able to get test connection working. When I try to test with a user update task, the task gets generated but it looks like the job is not completing or erroring out. 

jralexander137_0-1704585665281.png

Any suggestions on why that might be? I have connectionJson/userUpdateJson configured as such:

{
"authentications": {
"userAuth": {
"authType": "Basic",
"url": "https://saviyntwinpsdev.domain.com/SaviyntDev_WinPS/PS/ExecutePSScript",
"httpMethod": "POST",
"httpParams": {},
"httpHeaders": {
"Accept": "application/json"
},
"httpContentType": "application/json",
"properties": {
"userName": "domain\\svcAccount",
"password": "XXXX"
},
"expiryError": "ExpiredAuthenticationToken",
"authError": [
"InvalidAuthenticationToken",
"AuthenticationFailed",
"Authentication_MissingOrMalformed",
"Authentication_ExpiredToken"
],
"retryFailureStatusCode": [
403,
401,
500
],
"timeOutError": "Read timed out",
"errorPath": "errors.code",
"maxRefreshTryCount": 5,
"tokenResponsePath": "token",
"tokenType": "Basic",
"accessToken": "Basic abcd"
}
}
}

{
"accountIdPath": "accountName",
"responseColsToPropsMap": {},
"call": [{
"name": "call1",
"connection": "userAuth",
"showResponse": true,
"url": "https://saviyntwinpsdev.domain.com/SaviyntDev_WinPS/PS/ExecutePSScript",
"httpMethod": "POST",
"httpParams": "{\"Script\":\"Powershell.exe -File E:/TestEmailProvisioning3.ps1 ${user.systemUserName} \"}",
"httpHeaders": {
"Authorization": "${access_token}",
"Accept": "application/json"
},
"httpContentType": "application/json",
"successResponses":[
{
"message": "Mailbox Created"
}
],
"unsuccessResponses": {
"statusCode": [
400,
500,
401,
null
]
}
}]
}

Configure success codes. Also share postman response


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

I added success status codes and the task is still completing but I am not seeing any response result in the logs. the logSamp attachment shows what returns on a success from postman  currently along with a 200 response(which I don't see in the logs either). Its definitely not returning the success message nor the 200(from what I can see in the logs). So I would assume the task should remain open. Its also not triggering the script as far as I can tell, the mailbox is not being provisioned(works from postman and running locally on the winps server).

Here my current config:

{
"accountIdPath": "accountName",
"responseColsToPropsMap": {},
"call": [
{
"name": "call1",
"connection": "userAuth",
"url": "https://saviyntwinpsdev.rob.com/SaviyntDev_WinPS/PS/ExecutePSScript",
"httpMethod": "POST",
"httpParams": "{\"Script\":\"cd E:\\\\; powershell .\\\\TestMailboxProvisioning3.ps1 ${user.systemUserName}\"}",
"httpHeaders": {
"Authorization": "${access_token}",
"Accept": "application/json"
},
"httpContentType": "application/json",
"successResponses": {
"message": "Mailbox Created",
"statusCode": [200]
},
"unsuccessResponses": {
"statusCode": [400, 500, 401, null]
}
}
]
}

Logs showing no response but tasks being closed:

"2024-01-07T20:41:43.945+00:00","ecm-worker","rest.RestProvisioningService","quartzScheduler_Worker-5-2wvft","DEBUG","updateUserJSON: [accountIdPath:accountName, responseColsToPropsMap:[:], call:[[name:call1, connection:userAuth, url:https://saviyntwinpsdev.rob.com/SaviyntDev_WinPS/PS/ExecutePSScript, httpMethod:POST, httpParams:{"Script":"cd E:\\; powershell .\\TestMailboxProvisioning3.ps1 ${user.systemUserName}"}, httpHeaders:[Authorization:${access_token}, Accept:application/json], httpContentType:application/json, successResponses:[message:Mailbox Created, statusCode:[200]], unsuccessResponses:[statusCode:[400, 500, 401, null]]]]]"
"2024-01-07T20:41:43.945+00:00","ecm-worker","rest.RestProvisioningService","quartzScheduler_Worker-5-2wvft","DEBUG","User for which the loop is running:4939342"
"2024-01-07T20:41:43.945+00:00","ecm-worker","rest.RestProvisioningService","quartzScheduler_Worker-5-2wvft","DEBUG","Tasks to work on = 1"
"2024-01-07T20:41:43.945+00:00","ecm-worker","rest.RestProvisioningService","quartzScheduler_Worker-5-2wvft","DEBUG","Action to be performed =null"
"2024-01-07T20:41:43.945+00:00","ecm-worker","rest.RestProvisioningService","quartzScheduler_Worker-5-2wvft","DEBUG","updateUserActionResponse : true"
"2024-01-07T20:41:43.945+00:00","ecm-worker","services.ArsTaskService","quartzScheduler_Worker-5-2wvft","DEBUG","Entering provisionAccesstoAccountSaviynt"
"2024-01-07T20:41:43.945+00:00","ecm-worker","services.ArsTaskService","quartzScheduler_Worker-5-2wvft","DEBUG","{4939342=[com.saviynt.ecm.task.ArsTasks : 168]}"
"2024-01-07T20:41:43.945+00:00","ecm-worker","services.ArsTaskService","quartzScheduler_Worker-5-2wvft","DEBUG","UPDATEUSER"
"2024-01-07T20:41:43.945+00:00","ecm-worker","services.ArsTaskService","quartzScheduler_Worker-5-2wvft","DEBUG","Processing task 168 start"
"2024-01-07T20:41:43.946+00:00","ecm-worker","services.ArsTaskService","quartzScheduler_Worker-5-2wvft","DEBUG","completing task = 168"
"2024-01-07T20:41:43.946+00:00","ecm-worker","services.ArsTaskService","quartzScheduler_Worker-5-2wvft","DEBUG","completing task = 168 done"

I am testing the call out through postman and getting some weird access denied error. Originally it was working fine but now all of a sudden the pssession fails to establish when I call the script from postman. If I go to the script and run it manually, the hard coded creds in the script work fine. I am not sure why it wouldnt work via rest call then if the creds are hardcoded? The script is being executed as I have some output to file just before the pssession is established:

"Exception: Failed error streamNew-PSSession : [exps.rob.com] Connecting to remote server exps.rob.com failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.At E:\\TestMailboxProvisioning3.ps1:39 char:12+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin gTransportException + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailedImport-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for the argument, and then try running the command again.At E:\\TestMailboxProvisioning3.ps1:42 char:18+ Import-PSSession $Session -DisableNameChecking -AllowClobber+ ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand E:\\TestMailboxProvisioning3.ps1 : The term 'Enable-RemoteMailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:1+ .\\TestMailboxProvisioning3.ps1 szshim+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,TestMailboxProvisioning3.ps1 Remove-PSSession : Cannot validate argument on parameter 'Id'. The argument is null. Provide a valid value for the argument, and then try running the command again.At E:\\TestMailboxProvisioning3.ps1:68 char:18+ Remove-PSSession $Session+ ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Remove-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.RemovePSSessionCommand System.Exception: Failed error streamNew-PSSession : [exps.rob.com] Connecting to remote server exps.rob.com failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.At E:\\TestMailboxProvisioning3.ps1:39 char:12+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin gTransportException + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailedImport-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for the argument, and then try running the command again.At E:\\TestMailboxProvisioning3.ps1:42 char:18+ Import-PSSession $Session -DisableNameChecking -AllowClobber+ ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand E:\\TestMailboxProvisioning3.ps1 : The term 'Enable-RemoteMailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:1+ .\\TestMailboxProvisioning3.ps1 szshim+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,TestMailboxProvisioning3.ps1 Remove-PSSession : Cannot validate argument on parameter 'Id'. The argument is null. Provide a valid value for the argument, and then try running the command again.At E:\\TestMailboxProvisioning3.ps1:68 char:18+ Remove-PSSession $Session+ ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Remove-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.RemovePSSessionCommand \r\n at MVC_FIM.Services.PowerShellService.fnExecuteScript(String ScriptName) System.Exception: Failed error streamNew-PSSession : [exps.rob.com] Connecting to remote server exps.rob.com failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.At E:\\TestMailboxProvisioning3.ps1:39 char:12+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin gTransportException + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailedImport-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for the argument, and then try running the command again.At E:\\TestMailboxProvisioning3.ps1:42 char:18+ Import-PSSession $Session -DisableNameChecking -AllowClobber+ ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand E:\\TestMailboxProvisioning3.ps1 : The term 'Enable-RemoteMailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:1+ .\\TestMailboxProvisioning3.ps1 szshim+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,TestMailboxProvisioning3.ps1 Remove-PSSession : Cannot validate argument on parameter 'Id'. The argument is null. Provide a valid value for the argument, and then try running the command again.At E:\\TestMailboxProvisioning3.ps1:68 char:18+ Remove-PSSession $Session+ ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Remove-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.RemovePSSessionCommand System.Exception: Failed error streamNew-PSSession : [exps.rob.com] Connecting to remote server exps.rob.com failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.At E:\\TestMailboxProvisioning3.ps1:39 char:12+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin gTransportException + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailedImport-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for the argument, and then try running the command again.At E:\\TestMailboxProvisioning3.ps1:42 char:18+ Import-PSSession $Session -DisableNameChecking -AllowClobber+ ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand E:\\TestMailboxProvisioning3.ps1 : The term 'Enable-RemoteMailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:1+ .\\TestMailboxProvisioning3.ps1 szshim+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,TestMailboxProvisioning3.ps1 Remove-PSSession : Cannot validate argument on parameter 'Id'. The argument is null. Provide a valid value for the argument, and then try running the command again.At E:\\TestMailboxProvisioning3.ps1:68 char:18+ Remove-PSSession $Session+ ~~~~~~~~ + CategoryInfo : InvalidData: (:) [Remove-PSSession], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.RemovePSSessionCommand \r\n at MVC_FIM.Services.PowerShellService.fnExecuteScript(String ScriptName)\r\n at MVC_FIM.Services.PowerShellService.fnExecuteScript(String ScriptName)"

jralexander137
New Contributor III
New Contributor III

Looks like  its not seeing the task? 

jralexander137_0-1704591444787.png