Problem Running PowerShell Script

I am trying to run a PowerShell script using the Run power shell script activity from the UiPath.Script.Activities package, but keep receiving this error:

18.4.1+Branch.master.Sha.bc66386dd8e2160b6d35f31d5ce934a5aa4cf4bd

Source: Run power shell script

Message: One or more errors occurred.

Exception Type: System.AggregateException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.AggregateException: One or more errors occurred. ----> System.Management.Automation.ParameterBindingException: A parameter cannot be found that matches parameter name ‘msExchMobileAllowedDeviceIDs’.
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) at System.Management.Automation.DlrScriptCommandProcessor.RunClause(Action1 clause, Object dollarUnderbar, Object inputToProcess)
— End of stack trace from previous location where exception was thrown —
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
— End of inner ExceptionDetail stack trace —
at UiPath.Script.Activities.PowerShell.RunPowerShellScript`1.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

I am able to run another script without an issue and have verified that I have the parameters and Output setup similar. I’m guessing that it is just having an issue using one of our AD exchange attributes…but the script runs without an issue when I trigger it manually.

Any help would be greatly appreciated.

Cheers!
s3vn

Update, I removed the parameter from my script that was giving the error and I received a new error message. The script is actually running and doing the work needed, but I am then getting this error from UiPath:

18.4.1+Branch.master.Sha.bc66386dd8e2160b6d35f31d5ce934a5aa4cf4bd

Source: Run power shell script

Message: Unable to cast object of type ‘System.Management.Automation.PSModuleInfo’ to type ‘System.String’.

Exception Type: System.InvalidCastException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidCastException: Unable to cast object of type ‘System.Management.Automation.PSModuleInfo’ to type ‘System.String’.
at System.Linq.Enumerable.d__971.MoveNext() at System.Collections.Generic.List1…ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at UiPath.Script.Activities.PowerShell.RunPowerShellScript`1.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

It looks like UiPath is angry because I am trying to return a string from my PowerShell script…I want it to return a yes or no, is that not possible?

Yes you can return a string no problem, but it is quite finicky setting it up. It is hard to tell what’s happening without seeing the paramters, script, variables, etc.

Is the powershell script itself setup to output a string? Double check that the names are correct in the PowerShellVariables pop-up window and that the direction is set to “out” and that the type is “string” and you are setting the value to the correct UiPath variable

1 Like

I was able to resolve the issue…my script was using the Import-PSSession cmdlet and UIPath couldn’t handle the output. I piped the cmdlet into Out-Null and it worked without an issue.

1 Like

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