new-pssession in Powershell Action Step throws "access denied" error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 08:25 AM
Trying to run a remote command (just doing this as a test for now, so any command will do) via a Powershell Action step, and getting some odd behavior I'm hoping someone in the support community can help with.
I define connection inline, and use a credential alias I've tested and is known good (more on that below).
If I use the "run on midserver" option, and run this line of code:
However, if I run the same command on the MID server in an interactive PowerShell session, it works fine - so the permissions, PSremoting, etc, are all set up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 10:28 AM
After doing some more messing about, the issue seems to be ServiceNow passes $cred as type "System.Net.NetworkCredential", and the PowerShell New-Pssession needs a credential of type "PSCredential".
Which means I don't think the ServiceNow example given of "New-PSSession -credential $cred" in the help remarks section at the top of the Command window for a new PowerShell step would ever work . . .
Making the first line of the PowerShell script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 06:13 AM
Hello nbhms,
How can i set $cred
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 08:37 AM
Create a Windows credential object (and a credential alias for it) in Service Now.
Then in your Custom Powershell step "connection details" section, set "connection" to be "Define connection inline", and set "credential alias" to be the alias of the Windows credential you created.
Then inside your Powershell script, $cred will be whatever is in that credential object defined in Service Now. You don't have to define it in your script, it's a reserved variable that Service Now will create in the runspace of your PowerShell script that your script can reference. As I mention above though, I've found inconsistencies with it being a "System.Net.NetworkCredential" object vs what a lot of PowerShell commands want, which is a "System.Management.Automation.PSCredential" object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 05:47 AM - edited 04-17-2024 06:50 AM
could you please guide me how can i create windows credential object.
is it right syntax to create credential object
$cred = New-Object System.Management.Automation.PSCredential()
please reply on
https://www.servicenow.com/community/developer-forum/powershell-action-step-throws-quot-access-denie...