F# friendly PowerShell extension
(net45 and Windows PowerShell)
The NuGet package FarNet.FSharp.PowerShell may be used as usual in F# projects. Note, System.Management.Automation.dll is not needed in your final binaries. It is just for building.
The package is also designed for FarNet.FSharpFar. To install FarNet packages, follow these steps.
F# code
PS
is the F# friendly wrapper of the PowerShell class, with similar but fewer members. Use PS.Create()
instead of PowerShell.Create()
.
Use Script()
and Command()
instead of AddScript
and AddCommand()
. PS
does not directly support command chains. But it is fine to invoke several scripts and commands using the same PS
object.
Use the type safe helper Invoke2()
in addition to Invoke()
. All result objects must be compatible with the specified type.
Use F# asynchronous InvokeAsync()
and InvokeAsync2()
. For parallel scenarios use different PS
instances.
Use the operator ?
for getting PSObject
properties. Note, it also works for Hashtable
wrapped by PSObject
.
PowerShell code
The default $ErrorActionPreference
is Stop
, safe for non-interactive.
Use Get-Type
to get a type defined in the calling F# assembly.
"Hello, world!" example:
open FarNet.FSharp.PowerShell
PS.Create().Script("Write-Output 'Hello, world!'").Invoke()
|> printfn "%A"
For more examples see /samples.
Features and API may change before v1.0.
The project is suitable for cloning and playing with Visual Studio 2019.
FarNet.FSharp.PowerShell.sln contains the main project and tests.
FSharpFar development and tools are optional. They require:
C:\Bin\Far\x64