Questions tagged [runspace]

In the context of using PowerShell commands with managed code a runspace is the operating environment for the commands invoked by the host application.

This environment includes the commands and data that are currently present, and any language restrictions that currently apply.Host applications can use the default runspace that is provided by Windows PowerShell, or they can create their own runspaces by using the RunspaceFactory class. By using that class, The host application can create individual runspaces or they can create a pool of runspaces. Once a runspace is created and opened, the host application can invoke commands synchronously or asynchronously by using a PowerShell object. For more information see Writing a Windows PowerShell Host Application

230 questions
19
votes
1 answer

How do I host a Powershell script or app so it's accessible via WSManConnectionInfo? (like Office 365)

The only ways I know to connect to a remote runspace include the following parameters WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "localhost", 80, "/Powershell",…
halfbit
  • 54,462
  • 46
  • 195
  • 426
10
votes
2 answers

Memory leak using Powershell Remote Calls in C#

I have a windows service that is doing a lot of exchange remote calls to get some server information. I noticed that as longs as the time passes the memory used by the service starts growing until a memory exception is thrown. I have searched and it…
Manuel Quintero
  • 113
  • 1
  • 7
9
votes
1 answer

Hosting powershell runspace in web application

I'm writing a web service that executes powershell scripts (active directory, directory management, etc). Right now, Runspace instance is created per web request. As Runspace initialization is time consuming operation, plus often I have to import…
Misha N.
  • 3,435
  • 1
  • 26
  • 35
9
votes
1 answer

Scope vs Runspace vs Session vs AppDomain

I'm struggling to draw the boundaries in my head for PowerShell. My very limited understanding is this: A Scope contains user/script defined variables and functions, and there can be a hierarchy of scopes with a PS call stack. A Runspace dictates…
neumann1990
  • 878
  • 7
  • 15
9
votes
1 answer

Using the Task class in powershell

I’m trying to use the Task class in Powershell to run an operation asynchronously. But I’m getting the following exception: Id : 1 Exception : System.AggregateException: One or more errors occurred. --->…
musium
  • 2,395
  • 3
  • 25
  • 50
7
votes
2 answers

I don't understand the NewNotImplementedException runtime error I'm getting

I'm trying to implement a remote runspace that needs both connectionInfo to talk to Exchange and an imported module to talk to active directory. Here is problem code: runspace =…
caspersgrin
  • 231
  • 1
  • 5
  • 15
5
votes
2 answers

How is the new PowerShell 7 ForEach-Object Parallel implemented?

PowerShell 7 introduced a much needed feature for running pipeline input in parallel. The documentation for PowerShell 7 does not provide any detail on how this is implemented. Having leveraged PoshRSJob and Invoke-Parallel modules before, I'm…
sheldonhull
  • 1,594
  • 1
  • 19
  • 40
5
votes
3 answers

C# Runspace Powershell (Interactive)

I am trying with C# to execute a Powershell file with paramters in a runspace. Unfortunately i get the following output: A command that prompts the user failed because the host program or the command type does not support user interaction. Try a…
user2702653
  • 53
  • 1
  • 1
  • 4
5
votes
2 answers

powershell multi-runspace event passing

I've been searching for a way to pass events between different runspaces and yet have not found any. The following snipped creates a background runspace, which shows a small window with only one button. OnClick it shall post an event that the main…
exomium
  • 53
  • 1
  • 4
4
votes
2 answers

Powershell Runspace Enter-PSSession

I am writing a program that will run a program on a remote machine. I have installed the windows sdk and have successfully uploaded my file with bits now I would like to remotely run a change directory and execute a command using power shell. The…
user1158903
4
votes
1 answer

Powershell threading vs C# threading

In C# when I want to create a thread which calls a function I simply do this. Thread t = new Thread(() => calledFunction()); t.Start(); My goal is to do the same thing in Powershell. Nothing fancy, its only purpose is the prevent the GUI from…
Jomasdf
  • 228
  • 2
  • 13
4
votes
1 answer

Runspace Dispose in Powershell (GUI specific)

I'm an active reader of StackOverflow as it usually helps me resolve all my issues. But for my first question ever I'll ask your help about runspaces in Powershell, specifically for memory management. I created some PS apps with GUI and now I use…
4
votes
1 answer

How does Powershell know where to find modules for import?

I am really at beginner level for working with commandlets and powershell stuff. I am invoking commandlets from C# using PowerShell API. I saw strange behaviours. While on different threads on stackoverfow, people explicitly importing modules using…
Usman
  • 2,426
  • 4
  • 36
  • 68
4
votes
1 answer

How to call a method of a WPF form element running in another runspace in Powershell

I'm playing around with using runspaces in PowerShell to enhance performance of a small GUI application. What I've got so far is a runspace that has 2 purposes: First, it holds all my other runspaces and second, it parses my GUI xml file and…
Quhalix89
  • 129
  • 1
  • 2
  • 10
4
votes
1 answer

How to stop an asynchronous PowerShell scriptblock?

I'm trying to have a Powershell script start a looping asynchronous script block and then do some "other stuff". When the "other stuff" is complete at some unknown later time, I want to stop/kill the script block. I see the MS dev network info on…
Teknowledgist
  • 263
  • 3
  • 11
1
2 3
15 16