How can handle Import-Module ActiveDirectory error / exception in PowerShell activity to take workflow at failure path

bhumigothi
Kilo Contributor

In my PowerShell Activity I have code like :

find_real_file.png

In ecc queue I have error like :

find_real_file.png

In my post processing currently i am handling failure and success like :

"Activity Failure" I mentioning in catch in power shell script.

find_real_file.png

find_real_file.png

My question is : how i can handle error in workflow to take workflow at failure path when i face error like in ecc queue.

Please suggest best solution. I am fresher in Orchestration and PowerShell.

Thanks,

Bhumi

4 REPLIES 4

janrameez
Giga Contributor

Hello Bhumi,

 

The reason is that, the provided script is running on your mid server machine but not on the target AD machine. You need to specify -Computer $computer keywords in the script to specify the target machine. If there is no such keywords, it will always try to run on the Mid server host machine itself.

 

Refer the below:

https://youtu.be/7nf0p3xdGKA

https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/administer/orchestration-activities/reference/r_RunPowershellActivity.html

 

I also ran into the same issue and scratching my head for quite a while. Please Let me know if you find any solution for importing AD module in PS script.

Prateek Gupta3
Mega Guru

Hi,

 

As per the error, it looks like on your target host (MID server), Active Directory module is not installed.

 

Thanks,

Prateek Gupta

janrameez
Giga Contributor

Hello Prateek,

AD module is installed only on my target AD server, but not on the mid server.
However, when I run the OOTB AD activities like Query, Update, Delete, they are running without any issues, But, when I run some custom commands like - importing ad module, dsquery, Move-ADObject, acitivity is returing the mentioned error as - The specified module 'activedirectory' was not loaded because no valid module file was found in any module directory.

Any suggestions on running custom AD commands(dsquery, Move-ADObject)?

 

Thanks

MJ

Hi,

 

Actually when you are running the OOTB activities, the activities are using LDAP (ADSI) interface to run the scripts.

The way you can do is either go with LDAP. Try to search with ADSI Saercher. You will get help from Internet.

Or

You can create a PS Session on your Active Directory server from Mid server using Powershell.

Once the Session is created then you can run the above shown powershell commands.

Or

Try by using "Invoke-command" powershell command. In this you need to pass the computername. Write your script in Script Block parameter.

Please tell if it was successor failure.

 

Thanks,

Prateek Gupta