I have some functions in a module I would like to call from a runspace but It´s not working. I assume that I somehow have to send the module to the runspace.
The example below works fine.
$hash = [hashtable]::Synchronized(@{})
$hash.OutData
$runspace = [runspacefactory]::CreateRunspace()
$runspace.Open()
$runspace.SessionStateProxy.SetVariable('Hash',$hash)
$powershell = [powershell]::Create()
$powershell.Runspace = $runspace
$powershell.AddScript({
$hash.OutData = Get-Date
}) | Out-Null
$handle = $powershell.BeginInvoke()
While (-Not $handle.IsCompleted) {
Start-Sleep -Milliseconds 100
}
$powershell.EndInvoke($handle)
$runspace.Close()
$powershell.Dispose()
But if I call my own function instead like this, the OutData is blank. The function works fine outside of the runspace.
$powershell.AddScript({
$hash.OutData = Get-customData
}) | Out-Null
What do I have to do be able to call my function?