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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FarNet.FSharp.PowerShell" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FarNet.FSharp.PowerShell --version 2.0.0                
#r "nuget: FarNet.FSharp.PowerShell, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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:

  1. FarNet - Far Manager .NET host and API for modules
  2. FarNet.FSharpFar - F# compiler service host and tools
  3. FarNet.PowerShellFar - PowerShell Core, host and tools
  4. FarNet.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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 651 11/19/2023
1.0.1 1,087 1/1/2023
1.0.0 778 11/18/2022
0.2.0 874 8/18/2022
0.1.1 927 3/6/2021
0.1.0 1,006 6/13/2020
0.0.5 938 6/11/2020
0.0.4 975 6/10/2020
0.0.3 907 6/9/2020
0.0.2 931 6/9/2020
0.0.1 955 6/9/2020