FarNet.FSharp.PowerShell
2.0.0
Prefix Reserved
dotnet add package FarNet.FSharp.PowerShell --version 2.0.0
NuGet\Install-Package FarNet.FSharp.PowerShell -Version 2.0.0
<PackageReference Include="FarNet.FSharp.PowerShell" Version="2.0.0" />
paket add FarNet.FSharp.PowerShell --version 2.0.0
#r "nuget: FarNet.FSharp.PowerShell, 2.0.0"
// Install FarNet.FSharp.PowerShell as a Cake Addin #addin nuget:?package=FarNet.FSharp.PowerShell&version=2.0.0 // Install FarNet.FSharp.PowerShell as a Cake Tool #tool nuget:?package=FarNet.FSharp.PowerShell&version=2.0.0
FarNet.FSharp.PowerShell
F# friendly PowerShell Core helper
Package (two in one)
(1)
The NuGet package FarNet.FSharp.PowerShell may be used as usual in F# projects.
In this case PowerShell Core comes with its dependency Microsoft.PowerShell.SDK
(batteries included because Windows PowerShell cannot be used).
(2)
The package is also used by FarNet.FSharpFar in Far Manager and its satellite fsx.exe
.
In this case PowerShell Core comes with another package FarNet.PowerShellFar.
To install FarNet packages, follow these steps.
Thus, you need these packages in Far Manager:
FarNet
- Far Manager .NET host and API for modulesFarNet.FSharpFar
- F# compiler service host and toolsFarNet.PowerShellFar
- PowerShell Core, host and toolsFarNet.FSharp.PowerShell
- this package connects 2. and 3. in 1.
It looks like a lot but includes all the batteries and the power plant. This setup is portable with Far Manager, with caveats about prerequisites.
Overview
F# code
The PS
type wraps the PowerShell class and exposes somewhat similar 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
instance.
Use the type safe generic InvokeAs()
in addition to Invoke()
.
Result objects must be compatible with the specified type.
Use F# asynchronous InvokeAsync()
and InvokeAsyncAs()
.
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 or script.
Example
"Hello, world!" example:
open FarNet.FSharp.PowerShell
PS.Create().Script("Write-Output 'Hello, world!'").Invoke()
|> printfn "%A"
See also
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.PowerShell.SDK (>= 7.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.