fsprojects / FSharp.Management

The FSharp.Management project contains various type providers for the management of the machine.
http://fsprojects.github.io/FSharp.Management/
Other
91 stars 32 forks source link

Is it possible to use the powershell type provider on a module defined in a file ? #61

Closed chkeita closed 8 years ago

chkeita commented 8 years ago

i am trying to to use the type provider on some existing powershell scripts without much success. I was wondering if that feature is supported. if so what is the syntax to do it? Here is an example of i tried so far :

type PS =  PowerShellProvider< @"myModule.psm1">
sergey-tihon commented 8 years ago

It is not possible now, but definitely nice to have feature. @kcheick Do you want to implement this?

chkeita commented 8 years ago

I gave it a stab today and made little progress but it is not really working right now. It turns out that ytou can pass a path to powershell module file just like i did but the problem here is that the module is being imported under the restricted execution policy which prevents the script from being executed. I was able to get around it by setting the AuthorizationManager in HostedRuntime.fs like so :

let initState = InitialSessionState.CreateDefault()
initState.AuthorizationManager <- new Microsoft.PowerShell.PSAuthorizationManager("Microsoft.PowerShell")

this allows me to list the function in the module but when i call it it returns null no matter what. Now i am stuck, any pointer on what is happening here would be appreciated.

for reference here is my test module

function DoSomething{ 
    param ([string] $test)
    $test
}
export-moduleMember -function DoSomething

and the the testing code

type TestProv  = PowerShellProvider< @"testModule.psm1">
TestProv.DoSomething (test="testData") // intellisense works for the method name and parameters
|> printfn "%A"
// prints : <null>
chkeita commented 8 years ago

The powershell function was missing an output type Here is the PR

function doSomething {
    [OutputType([string])]
    param (
        [string] $test
    )
    return $test
}

export-moduleMember -function doSomething
sergey-tihon commented 8 years ago

Released in v0.3.1