Run powershell script for remoting on MID server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2024 10:45 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2024 08:51 PM
If possible, can you please share your PowerShell script. Let me see if we can tweak something to make it work. From ServiceNow end, nothing can be done as of now as you are not using PowerShell step.
Also, any particular reason for not using PowerShell step ? If you are concerned about storing Mid Creds, then you can use Mid Server Service Account to run your scripts.
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2024 10:19 PM
Below is the powershell script I'm attempting to execute from MID server:
# set username and password
$password = ConvertTo-SecureString "MyPlainTextPassword" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("username", $password)
# create new session with remote system
$so = New-PsSessionOption –SkipCACheck -SkipCNCheck
$session = New-PSSession -ComputerName destination_hostname -Credential $Cred -UseSSL -SessionOption $so
# copy file
Copy-Item "source location" -Destination "destination location" -ToSession $session
For running powershell step I need MID server credentials which cannot be shared with me. Hence the approach of using script action and triggering via ECC.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2024 10:32 PM
No need to get the Mid Server credentials. You can create a Windows Credential for your mid server and check "Use Mid Server Service Account" as shown in snip below :
This will help the PowerShell step to authenticate to mid server via the Mid Server Service account so that you can run your PowerShell scripts on the mid server.
For the copy operation, let me simulate the conditions on my side. I check and let you know how we can avoid multi hop authentication issue.
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2024 10:33 PM
Also, just to be clear with the requirement, you are trying to copy a file from Mid Server to another remote server ?
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2024 01:02 AM
Hi @Amit Verma
Yes my requirement is to copy file from MID server to remote server.
I have created Windows credentials as suggested and used the same in powershell step. But logs have reported the same error again:
Connecting to remote server <hostname> failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic. HRESULT: [5] Stack Trace: