How do I work with PSCustomObject in the Assign step after InvokePowershell

I am trying to use InvokePowershell, and then do a foreach, looping around a collection of PSCustomObject.

But, since UiPath doesn’t know what’s in the PSCustomObject, it will not validate when I try to attempt to something like item.name

Compiler error(s) encountered processing expression “item.name”.
Option Strict On disallows late binding.

I receive
Example:
InvokePowershell with “Get-Result” and set output to variable named “myResult” of Collection of System.Management.Automation.PSCustomObject.

Get-Result is simply a function in a module like:

$result = New-Object PSCustomObject -Property @{
    name = "abc"
    value = "def"
}
Write-Output $result

24

Hi @goldparrotgloo

Is your For Each loop also set to loop through the PSCustomObjects?
Like so:

Yes. For an example, do a simple InvokePowershell with “Get-Verb”, store output in variable “verbs”. This will all be a Collection of System.Management.Automation.PSCustomObject.

Then setup your For Each, as you indicate.
Inside the For Each, simply do a WriteLine “item.Verb.ToString” .

I receive error “Verb” is Not a Member of PSCustomObject.

Even using System.Reflection in an InvokeCode shape shows no properties.
I was able to use PSNoteProperty in InvokeCode, and can see the values as below but can’t seem to manipulate outside of pure visual basic.

Any thoughts???

Dim psCommands As System.Management.Automation.PowerShell = System.Management.Automation.PowerShell.Create

psCommands.AddCommand("Get-Verb")

'Run the commands

Dim colPSResults As System.Collections.ObjectModel.Collection(Of System.Management.Automation.PSObject) = psCommands.Invoke()
    'Check the results
    For Each objResult As System.Management.Automation.PSObject In colPSResults
        For Each Prop As System.Management.Automation.PSNoteProperty In objResult.Properties
             Console.WriteLine("name:" & Prop.Name)
    Console.WriteLine("value:" & Prop.Value.ToString)
        Next
   Next

How did you end up solving this?
I’m currently trying to connect to Office 365 and Get-QuaratineMessage,
but I get an error saying that it cant cast PSCustomObject to PSModuleInfo

I have the exact same issue when trying to access the properties in the PSCustomObject.
This is a big problem for me at the moment. It would be great if UiPath can provide a solution to this problem or a workaround.

I have a workaround for this.

In the powershell script that you invoke, export the result to a csv file like this,
Get-Service | select name, displayname | Export-Csv "C:\output.csv" -NoTypeInformation

Then use a read CSV activity on the output.csv file.
After that you can use a foreach activity on the data.

Regards

Hi guys,

Did anyone found a way to solve this AVOIDING outputting anything to a csv or text file?

Thanks in advance