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
2
votes
0 answers

Powershell Runspacepool - Why can't I output from a Synchronized Hashtable to a .txt file

What I'm trying to do The below script loops through every item in an Array of data streams and requests a summary value for output to a text file. This external request is by far the most expensive part of the process, and so I am now using a…
2
votes
0 answers

Could someone explain the Runspace PSThreadOptions?

My main question is does 1 RunSpace represent 1 thread. I read this post: Process vs Instance vs Runspace in PowerShell And originally I understood it as: You have a currently running powershell process. A runspace object is created within…
Nick
  • 304
  • 1
  • 12
2
votes
1 answer

How to send input to [Console]::In.ReadLine() from parent process?

Starter is used for starting target script process: # STARTING PS (TARGET) SCRIPT COMPILED TO EXE $processStartInfo = New-Object System.Diagnostics.ProcessStartInfo $processStartInfo.FileName = $somePath $processStartInfo.WorkingDirectory =…
manidos
  • 3,244
  • 4
  • 29
  • 65
2
votes
0 answers

How to automate a C# application using powershell console?

Context I have a C# application with a GUI for standard users, but for advanced users I want to provide a command line that will allow to manipulate all objects in the app. My idea is to use powershell for that. If I can run the powershell engine…
laperouse
  • 151
  • 1
  • 4
2
votes
2 answers

Process vs Instance vs Runspace in PowerShell

the [Powershell]::create() - method creates a new PowerShell-"Instance" either in the "current or a new runspace". Can someone explain how the terms process, instance, runspace and (maybe thread) relate to each other in this regard. In laymen's…
Moss
  • 325
  • 2
  • 16
2
votes
2 answers

Powershell run space write protected variables ( not replace able )

I need to define a container in powershell which cannot be modify able once it is created. I know there is a way, by which variables can be created as hidden in current run space but still somehow that is also not safe for my problem. I want to…
Usman
  • 2,742
  • 4
  • 44
  • 82
2
votes
1 answer

How to access Powershell variable set within C# commandlets

I would like to access all PSVariables set within a commandlet in C#. So, my one C# Commandlet would set variables from powershell script in sessionState and another commandlet will enumerate all sessionState variables along with their types set…
Usman
  • 2,742
  • 4
  • 44
  • 82
2
votes
0 answers

Child thread Manipulating Parent Thread

The original script/tool so far is 1000+ lines so I made a mock that represents my problem. What this code basically does is create a Parent Thread with a GUI and its Start Button creates Child Threads that copies and executes files on remote…
2
votes
0 answers

How do I specify 'noProfile' in a Powershell runspace in c#

I have an application that's running powershell commands in c#. I want my runspace to NOT load the user's profile when they run my app. Here's my code that initializes the runspace: var iss =…
Ethan Eiter
  • 101
  • 9
2
votes
1 answer

New-PSSession Parellel Execution

We have two PSSessions that need to be established and imported into the current session before our script can continue. Both steps require about 10 - 15 seconds each for a total of 20 - 30 seconds when run in series. Is it possible to run…
Douglas Plumley
  • 565
  • 5
  • 21
2
votes
1 answer

SessionStateProxy property is empty at new Runspace object when created using Uri

My remote runspaces works fine when I'm using PS 3.0+ but as soon as I'm running my code using PS 2.0, SessionStateProxy property is null (but only when I try to create remote runspace. powershell -version 2 $Uri = New-Object…
ALIENQuake
  • 520
  • 3
  • 12
  • 28
2
votes
0 answers

Is there any way to clone Powershell Runspace object

I want to know if it is possible to create a new Powershell Runspace object from an old one. I'm am going to do some powershell operations concurrently. I create powershell runspace every time and run certain commands. Let's say the first 5 commands…
Shen Prabu
  • 130
  • 13
2
votes
1 answer

New-PSSession and Runspacepool clarification

I need to run Exchange online cmdlets using powershell classes in C#. To run exchange online cmdlets i need to establish a remote powershell session. My doubts are: 1) If runspacepool size is 2, should i create that remote powershell session in both…
Praveen Kumar
  • 946
  • 3
  • 10
  • 29
2
votes
1 answer

Import specific cmdlets from modules to use in Runspacepool

In C#, InitialSessionState class provides a way to import specific modules and make it available to all the runspaces in the runspacepool using "ImportPSModule" method. (But this imports all cmdlets in the module being imported) To import specific…
Praveen Kumar
  • 946
  • 3
  • 10
  • 29
2
votes
1 answer

How to show runspace child powershell objects streams on host console?

I have some Powershell objects (created with [PowerShell]::Create()) acting as threads in my powershell application. How can I show the streams data (Verbose and Error streams) on the invoker's console, during the run itself, and not only after the…
iTayb
  • 12,373
  • 24
  • 81
  • 135