My Technical Notes

Work Blog

Wednesday, 11 June 2014

Embedding F# In PowerShell

Following on from Doug Finke's ‘Embedding’ F# in PowerShell article, I wanted to load F# scripts within PowerShell.

Later, after a bit of Google-ing, I worked out that you don't need to use the fsc.exe compiler, because we can instead use Add-Type. However we need a "CodeDom" for the F#. I ended up installing The Old F# "PowerPack", which includes one in its FSharp.Compiler.CodeDom.dll DLL file.

Here is the definition of my Add-FSharpType CmdLet:

Give either of these two parameters:

  • Path - the path to the F# script file.
  • TypeDefinition - a string containing the F# code.

To invoke the Fibonacci code:


Sergey Tihon said...

Have you tried F# Compiler Services?

Tahir Hassan said...

Sergey (sorry for the late reply), I remember trying it, but I just couldn't get it to work.