Invoke powershell execution error

Hi i am trying to invoke this code here:

And i get this error:
2019-08-09_140340 ,

It works fine in powershell but gets the error while using invoke activity in studio

Can anybody help?
Thanks in advance

Hi @dcrt,
First of all please remember o use “Is Script” property in the right pane of Invoke Power Shell activity. Second thing is that you are using variables defined in PS. Have you use them in PowerShellVariables property as well?

Yes i have done both

There must be somewhere in invoked code a part related to input some data manually. Seems that this is causing problem here. Unfortunate I can’t see your workflow and whole code. If you could provide all (just hide sensitive data), maybe I would be able to find solution.

This is actually the all of the code:

"cls

$Searcher = New-Object DirectoryServices.DirectorySearcher
$Searcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry('My Domain')
$Searcher.Filter =  “(&(objectCategory=person)(objectClass=user)(displayname=$displayname))”
$Searcher.FindAll()| ForEach-Object {
   $_.Properties.adspath
}
"

And i am trying to get display name from outside. But i have embedded it to try and that version of the code also didn’t work.
I can’t see any part of this code that requires interaction

Are you trying to get displayname of the user from active directory with this maybe?

There are different domains. I am trying to get the domain name of the user whose display name has been entered. I am repeating that code for all the domains that i have (as seen in the first picture)

Like i said it works fine on powershell.

Uh, i found the problem, it was the cls line on the code all along. I had to remove it.
Thank you!

This is the one thing. But I think you should use Get-Aduser instead of this. It’s newer and you can get more details from it.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.