PowerShell Integration Issues

DylanB
Tera Guru

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. 

DylanB_0-1707317963432.png

 

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: 

DylanB_1-1707318029980.png

 

5 REPLIES 5

abelal
Tera Contributor

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.

abelal_0-1708614730817.png

When this is executed in MID server it gets transformed to this generated script under %TEMP%

abelal_1-1708614783933.png

Notice that -credential $cred is missing from generated script command as well as the comment!