Invoke PowerShell - Object reference not set to an instance of an object error while looping


I am attempting to execute a simple PowerShell script that takes a DataTable as an input parameter and checks each row for a value. For simplification, my script is iterating through a DataTable and entering these values into SAP GUI (not relevant).

foreach($row in $dt_example){
echo row.Age
echo row.Height

When executing the script only through PowerShell, it works completely fine and performs as expected. However when I invoke the PowerShell script using the Invoke PowerShell activity, it will process each row item and then when complete will throw the “Object reference not set to an instance of an object error while looping” error. With no rows remaining, the script should stop as it does through just PowerShell, but for some reason in UiPath Studio it keeps trying to iterate through the datatable even once its finished.

Anyone have a good idea why a script would work fine outside of UiPath but fails when invoked through UiPath?

Hi @tom_mccaffrey

If you are passing any out argument then check if a variable is assigned and also a screenshot of your properties and parameters will help