Powershell script returning error when being triggered via ServiceNow

Watts, Steven 0 Reputation points
2023-02-13T13:09:51.94+00:00

Hi,

I'm a ServiceNow developer having issues with running a PowerShell script on a jump server. When I trigger the script from ServiceNow I get the below errors.

WARNING: Error initializing default drive: 'The server has rejected the client credentials.'.

Get-QADUser : The specified domain either does not exist or could not be contacted.

+ $user = Get-QADUser $UserName -Credential $Credentials |Select -Expan ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When I run the same script, see below, directly from the jump server it runs as expected and adds the user to the group specified. I've removed the user and group information from the below.

Name Type DN

---- ---- --

[User] user CN=,OU=,OU=,OU=,OU=,OU=,OU=,OU=,DC=,DC=

User [name] successfully added to group [name].


Are their any additional actions that I need to take to allow an outside application, such as ServiceNow, to run a PS script on a jump server?

Thanks in advance.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2023-02-14T14:06:55.0666667+00:00

    When you RDP to the jump server, are you logging in with a domain account or a local account? I see that you are passing credentials on the cmdlet that is failing, but I don't know what else the script does. When you configure the ServiceNow "task" do you define a user id to run the process as, similar to the Windows task scheduler? Can you configure it to run with whatever account you RDP to the server with?

    You could try temporarily creating a local account and test the script with that. I would expect SN to be running as a service probably as System or LocalService. The local account would mimic the AD access of those accounts.

    Use Test-NetConnection to verify that the firewalls don't block access to the domain controllers. I would also test with PS's Get-ADUser instead of the Quest module.

    There are a number of hits for that error. You might want to look through these.

    https://www.bing.com/search?q=WARNING%3A+Error+initializing+default+drive%3A+%27The+server+has+rejected+the+client+credentials

    0 comments No comments

  2. Limitless Technology 44,746 Reputation points
    2023-02-14T16:30:38.8666667+00:00

    Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query

    A PowerShell script can return an error when being triggered via ServiceNow if the script is not properly configured or if the ServiceNow instance does not have the correct permissions to execute the script. To troubleshoot this issue, you can check the PowerShell script for any syntax or logical errors and make sure that the ServiceNow instance has the correct permissions to execute the script. Additionally, you can also check the Windows event viewer for any relevant errors that may have been logged when the script was triggered.

    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.