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
3
votes
4 answers

Write PowerShell Output (as it happens) to WPF UI Control

I've been reading blogs about writing to the UI from different runspaces (http://learn-powershell.net/2012/10/14/powershell-and-wpf-writing-data-to-a-ui-from-a-different-runspace/). I'm basically trying to make it so I can click a button in the UI…
jmcdade
  • 155
  • 1
  • 1
  • 13
2
votes
1 answer

MVC Controller with Runspace Impersonation

Trying to execute a Powershell cmdlet from a MVC 3 Controller using impersonation but keep receiving an "Requested registry access is not allowed." exception when calling Runspace.Open() StringBuilder stringBuilder = new StringBuilder(); …
ServerMonkey
  • 1,042
  • 3
  • 19
  • 42
2
votes
3 answers

how to establish and enter a remote session using runspace in powershell

I am trying to establish a session with a remote host B from my machine A, within a C# code. I am using runspace API for that. the code snippet is provided below Runspace runspace = RunspaceFactory.CreateRunspace(); …
user1156612
  • 41
  • 1
  • 3
2
votes
1 answer

Test-NetConnection -AsJob?

Is there any way I can utilize this piece of code with Test-NetConnection -ComputerName $_ -Port 5985 instead of Test-Connection -ComputerName $_ -Count 1 -AsJob ? I can't utilize -AsJob with the Test-NetConnection cmdlet. Are there any…
unixpipe
  • 75
  • 1
  • 9
2
votes
1 answer

PowerShell Runspace and EndInvoke

I've cobbled together an example of a runspace popping up a Windows form and a timer closing it after 3 seconds. See this example: $runspace = [runspacefactory]::CreateRunspace() $runspace.ApartmentState = "STA" $runspace.ThreadOptions =…
Captain_Planet
  • 1,228
  • 1
  • 12
  • 28
2
votes
1 answer

How do you reuse local functions in different PowerShell runspaces?

I've been playing around and learning about runspaces and Winforms and am wondering how I'd go about reusing a function for each different runspace I make. I can get it to work by including the full script of the function in each scriptblock, but I…
Jurm
  • 21
  • 2
2
votes
2 answers

How do I get a variable from a module run space in PowerShell?

There is a module that has an "initialize" function that sets a variable that gets used in other scripts/functions in the module to validate that the initialize function was run. Something like Start-InitializeThing Connect to the API …
Erick W
  • 25
  • 4
2
votes
2 answers

Using a powershell object in C# to retrieve cmdlet get-physicaldisk

Problem with Powershell object in C#9 I am trying to retrieve physical disks in C# using a system.management.powershell object. When I try using the cmdlet “Get-Process” the powershell object retrieves all processes correctly. using (PowerShell…
2
votes
1 answer

Powershell. Accessing variable outside a Runspace instance

I wrote a small application using WPF and Runspaces and ran into some difficulties. $Runspace = [runspacefactory]::CreateRunspace() $Runspace.ApartmentState = "STA" $Runspace.ThreadOptions = "ReuseThread" $Runspace.Open() $code = { #Build the…
2
votes
1 answer

Contacts import using runspacepools

I'm trying to import contacts using RunspacePools, but I'm having trouble getting it to work. If I take it out of the runspace logic, it works fine, just takes a long time. I'd really like to use runspacepools to speed up the import process and make…
Koobah84
  • 185
  • 2
  • 12
2
votes
0 answers

Powershell WPF Runspace - Changing values in SyncHashtable is slow?

im building a tool with powershell wpf. I finally managed to get my head around runspaces somewhat and am successfully updating the main forms progress bar from a runspace, woo! However, it is really slow when i touch anything in the sync hash table…
bdot
  • 51
  • 4
2
votes
3 answers

How to catch full invoke text from powershell class in C#

I want to catch the output exactly as I get it when I run commands in PowerShell. For instance when I type LS, I get: Yet when I use this code: Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); …
Michiel Krol
  • 243
  • 3
  • 9
2
votes
4 answers

Adding elements to a form from another runspace

I have a form in which as soon as ready several elements will be added (for example, a list). It may take some time to add them (from fractions of a second to several minutes). Therefore, I want to add processing to a separate thread (child). The…
2
votes
2 answers

How to read Write-Host output from Powershell script in C#

When running the script in Powershell i'm able to receive the Write-Host output but not in C#. Here is the code for the output Write-Host "HELLO WORLD TEST." The application fails when it reaches this line: Collection results =…
Tom
  • 79
  • 1
  • 10
2
votes
1 answer

How to combine PowerShell runspace stderr, stdout etc into a single stream

I'm looking for the equivalent of the PowerShell pipeline redirection *>&1 when running a job. I run the jobs roughly like this: $Instance = [PowerShell]::Create() $Instance.AddScript($CommandList) $Result = $Instance.BeginInvoke() …
bielawski
  • 1,466
  • 15
  • 20