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

283 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",…
makerofthings7
  • 60,103
  • 53
  • 215
  • 448
10
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
  • 1,205
  • 1
  • 11
  • 18
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,455
  • 1
  • 28
  • 36
9
votes
2 answers

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,942
  • 3
  • 34
  • 67
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
  • 241
  • 1
  • 5
  • 15
6
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,807
  • 2
  • 26
  • 44
5
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
5
votes
2 answers

Where "Write-Host" output goes in Powershell System.Management.Automation Reference assemblies 4.0

I am using System.Management.Automation with reference assemblies 4.0 with C# I need to see the output of Write-Host. Documentation says that Write-Host will be outputted in the output stream. What is the output stream for getting Write-Host output…
Usman
  • 2,742
  • 4
  • 44
  • 82
5
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…
Carlton2001
  • 53
  • 1
  • 4
5
votes
1 answer

Why there is no way to pass InitialSessionState for a remote RunspacePool?

Why the following method does not have an overload which accepts a RunspaceConnectionInfo (to specify the remote server info) as well as a…
Jagan
  • 447
  • 5
  • 12
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
5
votes
1 answer

ImportPSModule Failure Detection

I am trying to use InitialSessionState.ImportPSModule in order to import a Powershell module. I am interested in knowing if importing of the module failed due to any reason (e.g file not found etc.). Putting such code in the try block does not…
Dev28
  • 497
  • 5
  • 16
4
votes
1 answer

Call function from module inside a runspace

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 =…
1
2 3
18 19