How to define a function in a Powershell runspace and execute it How to define a function in a Powershell runspace and execute it powershell powershell

How to define a function in a Powershell runspace and execute it


Use the CreateDefault method instead of Create when you're creating your initial session state. If you don't you have a lot more to configure to make that session state viable.

$initialSessionState = [InitialSessionState]::CreateDefault()

Chris

Edit: Added an example.