Invoke PowerShell Get AD User Error

Im attempting to test the functionality of a much larger script, but I have run into an issue with my test. The test is simply getting a user from AD. I have written the following to a text file.

Import-Module activedirectoy
Get-ADUser {{samaccountname}} —> (not a variable - the user’s samaccount name typed in)

I used the “Read Text File” activity to convert the txt file containing the script to a string. Then used the “Invoke Power Shell” activity using the string variable in the Command Text parameter. I also checked IsScript. I am getting the below error.

Invoke Power Shell: Unable to cast object of type ‘Microsoft.ActiveDirectory.Management.ADUser’ to type ‘System.Management.Automation.PSObject’.

Any help would be greatly appreciated!


Can you try to set proper type (probably Microsoft.ActiveDirectory.Management.ADUser) in TypeArgument and proper type variable in Output property?


Hi @Yoichi.

I did try to search for this in browse for type but there was no results.


If there is no type in the type selection, either of the following might help you.

  • Add some package to include the target type. (I don’t know which activity has it.)

  • Change output type to other in Powershell side.

Or how about using ActiveDirectory package?


Hello @Jcircuit13

If you are trying to do AD automation using UiPath, its better to sue the default UiPath powershell package for this. All the functionalities are covered as different activities and its easy to use.

The first link can help you to solve your issue.

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