Reputation: 14327
I have a PowerShell script that needs to run normally, and also when invoked via RunspaceInvoke, e.g.
using (RunspaceInvoke invoker = new RunspaceInvoke())
{
invoker.Invoke(powerShellScript);
}
Part of this script doesn't need to run when being called with RunspaceInvoke, and moreover, it fails when being called with RunspaceInvoke.
Is there a way to detect (from within PowerShell) whether the script is being called with RunspaceInvoke?
Thanks
Upvotes: 0
Views: 1048
Reputation: 201592
I don't know how you can tell if you are being called from RunspaceInvoke. However, I suspect this will only happen in your own C#-based program that hosts the code you show above. If that is the case, then have your script test the value of $host.Name. In the C# execution context, this will return "Default Host".
Upvotes: 1