I wrote a Powershell script that reads a CSV file and returns the given collection from the data. The following is sample script output.
Count Name ------ ------ 12 Rubies 3 Pearls 20 Emeralds
I can get the results in C # by saving it in PSObject like this:
var shell = PowerShell.Create(); shell.Commands.AddScript("C:\\Scripts\\Powershell\\Get-MyData.ps1"); Collection<PSObject> results = shell.Invoke();
Now, when I expect one object, I can get each value and assign them to the following variables:
foreach (PSObject psObject in results) { localVariable = Convert.ToString(psObject.Properties["Name"].Value); }
However, I had problems converting this solution to dynamic. That is, it is expected that the number of rows will change. Therefore, I implemented this earlier when the source code is an SQL database using a solution similar to the one posted here , so I assumed that the data should be capable but I cannot get it to work in this scenario. Any ideas or suggestions? Thanks!
Note. The Powershell script component is required here, as it includes other mechanisms for formulating the output, so although I could just read from the CSV file using C #, this is simply not an option.
source share