How can handle Import-Module ActiveDirectory error / exception in PowerShell activity to take workflow at failure path
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2018 06:28 AM
In my PowerShell Activity I have code like :
In ecc queue I have error like :
In my post processing currently i am handling failure and success like :
"Activity Failure" I mentioning in catch in power shell script.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2018 07:36 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2018 04:03 AM
Hi,
As per the error, it looks like on your target host (MID server), Active Directory module is not installed.
Thanks,
Prateek Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2018 04:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2018 11:00 AM
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