Take powershell save as xml object and load c #

I have the following powershell script that scans a location and adds file data to an XML file,

Get-ChildItem -recurse c:\DATA | Select-Object  * , @{Name="Kbytes";Expression={ "{0:N0}" -f ($_.Length / 1Kb) }},@{Name="Age";Expression={ (((Get-Date) - $_.CreationTime).Days) }}  | Export-Clixml c:\DATA\Final.xml 

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

How to load an object into a dataset in C #?

+5
source share
1 answer
  • Add a link to the assembly System.Management.Automation.dll.
  • Create PowerShell Runspace
  • Open Runspace
  • Create a PowerShell Object PipelineUsing the CommandImport-CliXml
  • Call Pipeline
  • Close Runspace

        var rs = RunspaceFactory.CreateRunspace();
        rs.Open();
        var pl = rs.CreatePipeline(@"Import-CliXml c:\DATA\Final.xml;");
        var result = pl.Invoke();
        rs.Close();
    
+5
source

All Articles