Uipath - Powershell script errors

Hi Team,

I am not able to run a powershell script or even a command through Invoke PowershellScript pallet, I have been trying for a while now can someone help me . Below are the error that i receive when i just tried “Get-service” and “Get-childitem” and “hostname”.

Error
1.) Get-service
“unable to cast object of type ‘system.serviceprocess.servicecontroller’ to type ‘system.management.automation.psobject’ uipath”

2.) get-childitem
" object reference not set to an instance of an object uipath powershell"

3.) hostname

unable to cast object of type ‘system.string’ to type ‘system.management.automation.psobject’ uipath

Please assist !!

Thanks Vinod
email : vinodcrimson@yahoo.com

Hello

In “Invoke Powershell activity” properties, section “Misc”:

1.) Set TypeArgument as “system.serviceprocess.servicecontroller”
2.) Set TypeArgument as “System.IO.FileInfo”
3.) Set TypeArgument as “system.string”

In attachment, find your examples:

You have to change the TypeArgument depending on the return type of your command/script.

If you wish to know what is the return type(s) of a cmdlet:
in a Powershell windows, type :
(Get-Command commandName).OutputType

example : (Get-Command Get-ChildItem).OutputType

PS.xaml (5.0 KB)

7 Likes

Hi Team,

Sorry for the late reply but if i have a bigger with lot of functions and lot many data as output, then how do i categorize and figure out datatype of each? Because now i am facing with a simple powershell itself.

Please let me know on how to go ahead.

Thanks
Vinod

thank u this helped me too :slight_smile:

This solution worked