take powershell object save as xml and load in c#

Question:

I have the following powershell script that scans a location and adds the file details to a xml file,

As far as I understand this should be a object in the .net framework, assuming a dataset ?
what I would like to do is load this object into a c# application and use it as a dataset.

How would I load the object into a dataset in c# ?

Answer:

  1. Add reference to the System.Management.Automation.dll assembly.
  2. Create a PowerShell Runspace
  3. Open the Runspace
  4. Create a PowerShell Pipeline object with the Import-CliXml command
  5. Invoke the Pipeline
  6. Close the Runspace

Source:

take powershell object save as xml and load in c# by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply