Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to execute Powershell script from ServiceNow

SNOW44
Mega Guru

Hello Community,

I have installed a mid server in my personal PC. In mid server agent>scripts>powershell>myService.ps1 created myService.ps1 . From ECC queue, I created a output record as below

1. name=mid.server.<mid_name>
2. Topic=Command
3. Name=powershell scripts\PowerShell\myService.ps1
4. Queue=output
5. state=ready

When I created a record as above in ECC queue. I'm getting error as below,

<?xml version="1.0" encoding="UTF-8"?><results probe_time="2547"><result command="powershell scripts\PowerShell\myService.ps1"><stdout/><stderr>scripts\PowerShell\myService.ps1 : The module 'scripts' could not be loaded. For more information, run 'Import-Module
scripts'.
At line:1 char:1
+ scripts\PowerShell\myService.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (scripts\PowerShell\myService.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule
</stderr></result><parameters><parameter name="agent" value="mid.server.IST Mid Server"/><parameter name="signature" value=""/><parameter name="response_to" value=""/><parameter name="from_sys_id" value=""/><parameter name="source" value=""/><parameter name="priority" value="2"/><parameter name="agent_correlator" value=""/><parameter name="skip_sensor" value="true"/><parameter name="processed" value=""/><parameter name="error_string" value=""/><parameter name="sys_id" value="0a3585f12f7595106739dcb6f699b6d7"/><parameter name="sequence" value="1831bf486500000001"/><parameter name="from_host" value=""/><parameter name="sys_created_on" value="2022-09-08 07:15:53"/><parameter name="sys_domain" value="global"/><parameter name="name" value="powershell scripts\PowerShell\myService.ps1"/><parameter name="topic" value="Command"/><parameter name="state" value="ready"/><parameter name="queue" value="output"/><parameter name="ecc_queue" value="0a3585f12f7595106739dcb6f699b6d7"/></parameters></results>

Can anyone advice how to solve above error.

Thanks inadvance.

7 REPLIES 7

Mahendra RC
Mega Sage

Hello SNOW,

I believe you can refer this article Execute Powershell Script from ServiceNow to understand how you can run Powershell script from ServiceNow.

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

Hi SNOW,

Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.

If you still need any further help or guidance on this then please update those on this question.

Thanks

_ChrisHelming
Tera Guru

Your path is incorrect. Try using the full path:
Name=C:\some\folder\powershell scripts\PowerShell\myService.ps1

That's what the error is telling you:
ObjectNotFound: (scripts\PowerShell\myService.ps1:String)

It doesn't see anything called "scripts" with files in it. You have to be explicit for where that folder/file is.

Aman66
Tera Contributor

hi @SNOW44 how are you solved the above issue can u please help me i am getting same issue