There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was:
...
Of type: System.Management.Automation.CmdletInvocationException
Stack trace:
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at Spe.Core.Host.ScriptSession.ExecuteCommand(Boolean stringOutput, Boolean marshallResults)
at Spe.Core.Host.ScriptSession.<>c__DisplayClass150_0.b__0()
at Spe.Core.Utility.SpeTimer.Measure[T](String message, Boolean log, Func`1 action)
at Spe.Client.Applications.PowerShellIse.ExecuteInternal(ScriptSession scriptSession, String script)
at Spe.Client.Applications.ScriptRunner.Run()
Inner Exception:There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was:
...
Of type: System.Management.Automation.PSInvalidOperationException
Stack trace:
at System.Management.Automation.ScriptBlock.GetContextFromTLS()
at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)
at System.Management.Automation.ScriptBlock.DoInvokeReturnAsIs(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Object[] args)
at Microsoft.PowerShell.Commands.Internal.Format.MshExpression.GetValue(PSObject target, Boolean eatExceptions)
at Microsoft.PowerShell.Commands.Internal.Format.MshExpression.GetValues(PSObject target, Boolean expand, Boolean eatExceptions)
at Microsoft.PowerShell.Commands.Internal.Format.ComplexControlGenerator.ExecuteFormatTokenList(TraversalInfo level, PSObject so, List`1 formatTokenList, List`1 formatValueList)
at Microsoft.PowerShell.Commands.Internal.Format.ComplexControlGenerator.ExecuteFormatControl(TraversalInfo level, ControlBase control, PSObject so, List`1 formatValueList)
at Microsoft.PowerShell.Commands.Internal.Format.ComplexViewGenerator.GenerateComplexViewEntryFromDataBaseInfo(PSObject so, Int32 enumerationLimit)
at Microsoft.PowerShell.Commands.Internal.Format.ComplexViewGenerator.GeneratePayload(PSObject so, Int32 enumerationLimit)
at Microsoft.PowerShell.Commands.Internal.Format.OutOfBandFormatViewManager.GenerateOutOfBandData(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, Int32 enumerationLimit, Boolean useToStringFallback, List`1& errors)
at Microsoft.PowerShell.Commands.Internal.Format.InnerFormatShapeCommand.ProcessOutOfBandObjectOutsideDocumentSequence(PSObject so)
at Microsoft.PowerShell.Commands.Internal.Format.InnerFormatShapeCommand.ProcessObject(PSObject so)
at System.Management.Automation.CommandProcessor.ProcessRecord()
Steps to Reproduce the Problem
Simplified
For convenience I created a package with everything needed to reproduce the issue:
Expected Behavior
No errors
Actual Behavior
Steps to Reproduce the Problem
Simplified
For convenience I created a package with everything needed to reproduce the issue:
/sitecore/system/Modules/PowerShell/Script Library/RunspaceException/Functions/Example1
in ISEManual
Here's a complete list of steps:
Enable
ScriptedItemEventHandler
foritem:added
eventAdd SPE module with item:added handler integration point
Open ISE and run this script