Power Shell

Hello all!
I need to get ADUser user attribute.

Power shell code:
“Get-ADUser -identity $Name -properties extensionAttribute1 | Select extensionAttribute1”

But it returns an empty collection.

In activitie “IsScript” checked

Are you getting any output when you execute same command from powershell ISE?

If yes and if you are not getting any output from UiPath activity, try this code:

Param
(
$name
)
Get-ADUser -identity $Name -properties extensionAttribute1 | Select extensionAttribute1 | out-file “SomeTextFilePathOnYourMachine”

I always redirect powershell commands output to text files and then read those text files. Even in case of any exception, I use try catch block and redirect exception message to text file(in the catch block).

If you want to get output from activity directly, UiPath activity expects us to define type of output. Type of output will be different when the command executes normally and when exception occured. So I always redirect output to text file and read it later.

Let me know if you still get any doubts.

im use “read text file” activitie and write your code in it.
11111
But i get error : Invoke Power Shell: The term ‘Param’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

replace the $Name with the actual user name with string manipulation and then use that in your command.

Otherwise, there are AD activities packages that you can use. Might not have all the desired capabilities.

I have already replaced

Does your command work on its own outside of uipath?

Yes yes in this form: Get-ADUser -identity “TestUser” -properties “extensionAttribute1” | Select “extensionAttribute1”

paste this as is in invoke powershell and try

and try this, same error: “Get-ADUser -identity “”“TestUser””" -properties “”“extensionAttribute1"”" | Select “”“extensionAttribute1"”"

I’m sorry. After param I typed { instead ( accidentally. So it was not able to recognize Param block. Corrected the code now. Please check my previous post:

Also pass the Name parameter in the “Invoke Powershell” activity input properties, inside the Parameters collection:

Let me know if this works

I did everything as you wrote, but i got error:

Invoke Power Shell: The term ‘Param’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Also i try write “TestUser” in value, dont work too

I use Param() in all my codes and it worked. Did you click on “IsScript” button?

Also can you share the exact code what you are writing? Also the screenshot of Invoke powershell activity properties.

There’s something called “PowershellVariables” in Misc properties of that activity. Don’t fill that. Fill your inputs in the Input property “Parameters” as I gave in my above screenshot.

it should be like this:

"Get-ADUser -identity ""TestUser"" -properties ""extensionAttribute1"" | Select ""extensionAttribute1"""

might have to change typeargument to String

New error:

Invoke Power Shell: Unable to cast object of type ‘System.Management.Automation.PSCustomObject’ to type ‘System.Collections.ObjectModel.Collection1[System.Collections.ObjectModel.Collection1[System.Management.Automation.PSObject]]’.

you can set the typeargument accordingly and then create the output variable based on that. Just doing ctrl+k will do.
Otherwise you can probably use Object as the type argumnet

@a.ef Is there a compulsion to use power shell?
There are activities to fetch user info from AD.
Check this link