Run powershell script for remoting on MID server

Manasi Marathe
Tera Contributor

I am trying to run a powershell script on MID server for transferring a file from MID to an external server using flow and action. I am using script step to insert cmd on ecc queue for MID server and am not using the powershell step since I do not want to enter separate connection and credential details in Servicenow for MID server.

 

When I run the powershell script directly on MID server in an interactive session, file transfer works successfully. However, when I trigger the flow with script action, I observe the below error which states that access for PSremoting is denied.

 

Connecting to remote server "remote_server" failed
with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.

 

Kindly help me troubleshoot the issue further.

11 REPLIES 11

Hi @Manasi Marathe 

 

I reproduced the problem at my end. Please make use of below PowerShell script to troubleshoot this. Also, configure your PowerShell step as shown in snip below :

 

# set username and password
$password = ConvertTo-SecureString "Your Password Variable" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ($userName, $password)

# create new session with remote system
$session = New-PSSession -ComputerName "Remote Server" -Credential $Cred
# copy file
Copy-Item "Path to file on Mid Server" -Destination "Path to file on Destination" -ToSession $session

 

AmitVerma_0-1705483975182.png

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Rajdeep Ganguly
Mega Guru


Here are some steps you can take to troubleshoot and resolve the issue:

1. **Check the MID Server User Permissions**: Ensure that the user account running the MID Server service has the necessary permissions to execute the PowerShell script. The user account should have administrative privileges.

2. **Enable PSRemoting**: The error message suggests that PowerShell Remoting (PSRemoting) might not be enabled on the remote server. You can enable it by running the command Enable-PSRemoting -Force in the PowerShell on the remote server.

3. **Check the Execution Policy**: The execution policy in PowerShell might be restricting the script from running. You can check the current execution policy by running Get-ExecutionPolicy and set it to Unrestricted by running Set-ExecutionPolicy Unrestricted.

4. **Use Credential Object in Your Script**: If your script requires authentication, ensure you are passing a credential object in your script. You can create a credential object in PowerShell using the Get-Credential cmdlet.

5. **Check Firewall Settings**: Ensure that the firewall settings on both the MID Server and the remote server are not blocking the PSRemoting.

6. **Check the WinRM Service**: PSRemoting relies on the Windows Remote Management (WinRM) service. Ensure that this service is running on both the MID Server and the remote server.

7. **Debug the Script**: You can add debugging statements in your script to identify at which point the script is failing when run from the MID Server.

8. **Check the ECC Queue**: Check the ECC Queue in ServiceNow for any error messages related to the execution of the script.

Remember to revert any changes (like the execution policy) back to their original settings after troubleshooting to maintain security.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER