PowerShell Integration Issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 07:01 AM - edited 02-07-2024 07:22 AM
Hi all, I am attempting to run a simple PowerShell script and I'm running into various issues. We have a service account set up and that account has access to the mid-server. When manually remoting into the mid-server as that account, I can run PowerShell commands.
I have set up a connection and credential for this but to be honest, I'm not totally sure the settings are correct. What I'd like to do is use the service account to run PowerShell commands on the mid-server.
When attempting to run the below script via the PowerShell action, I am getting a couple of different errors depending on my settings. The current error is below. Any help on this would be greatly appreciated.
This is the inline script I'm running:
Get-ADUser -Filter "employeeid -eq '14892'"
$GUID = Get-ADUser -Filter "EmployeeID -eq '14892'" | Select-Object -ExpandProperty ObjectGuid | Select-Object -ExpandProperty GUID
$FirstName = Get-ADUser -identity $GUID | select -ExpandProperty GivenName
Write-Host "$FirstName"
These are the connection details I'm using:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 07:14 AM - edited 02-22-2024 07:17 AM
I found a solution too, see Re: Powershell Using \$cred - Page 2 - ServiceNow Community.
To cut a long story short the script we pass is modified before it gets executed. Anywhere we explicitly use `-credential $cred` it is stripped out. So I create me own $credential object and use that instead to stop it from stripping it out.
For example, have the below in ServiceNOW script editor.
When this is executed in MID server it gets transformed to this generated script under %TEMP%
Notice that -credential $cred is missing from generated script command as well as the comment!