You want to use the System.Management.Automation namespace. Here's an example of running some cmdlets from F#.
// C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0
open System.Management.Automation
open System.Management.Automation.Runspaces;
let runSpace = RunspaceFactory.CreateRunspace()
runSpace.Open()
let pipeline = runSpace.CreatePipeline()
let getProcess = new Command("Get-Process")
pipeline.Commands.Add(getProcess)
let sort = new Command("Sort-Object")
sort.Parameters.Add("Property", "VM")
pipeline.Commands.Add(sort)
// Identical to the following PowerShell command line:
// PS > Get-Process | Sort-Object -Property VM | select ProcessName
let output = pipeline.Invoke()
for psObject in output do
psObject.Properties.Item("ProcessName").Value.ToString()
|> printfn "%s"
You can also build cmdlets with F# and use PowerShell to move data. Check out this post on the Visual Studio F# Team Blog. It's a good example on how to write a Cmdlet in F#. You can also embed F# into PowerShell but in general it's better to make Cmdlets.