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
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
  • 258
  • 2
  • 13
4
votes
2 answers

Powershell GUI Freezing, even with runspace

I am creating a powershell script with a GUI, that copies user profiles from a selected source disk to a destination disk. I've created the GUI in XAML, with VS Community 2019. The script works like this : you select the source disk, the destination…
Oscar Loret
  • 65
  • 1
  • 7
4
votes
2 answers

Difference Between Pipeline and PowerShell class in C#

I want to know the difference between executing PowerShell script in C# using the Pipeline class versus the PowerShell class. Using Pipeline : Pipeline pipe = runspace.CreatePipeline(); Using PowerShell class: PowerShell ps =…
SaravananKS
  • 577
  • 4
  • 18
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,742
  • 4
  • 44
  • 82
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
  • 351
  • 1
  • 3
  • 13
4
votes
0 answers

custom cmdlet entry in remote powershell

I have been trying for days to add my custom cmdlet to the runspace of a remote powershell in C# string shellUri = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell"; System.Security.SecureString sString = new…
S. Schenkel
  • 181
  • 9
4
votes
1 answer

How to define a function in a Powershell runspace and execute it

I'would like to define a function in a powershell and execute it in a different runspace. I tried this: Function Add-Message { param( [parameter(mandatory=$true)][String]$pMessage ) ("--$pMessage--") | Out-File -FilePath…
Vik
  • 333
  • 5
  • 14
4
votes
2 answers

Passing double quotes through PowerShell + WinRM

I am using this code to execute remote code (MSI installs) on a server. Passing double quote through the script is just not working. I tried two variations as given below (#3 and #4) along with the outputs. Input #1 (Simple case to test double…
Partho
  • 138
  • 1
  • 11
4
votes
2 answers

Custom PSHostUserInterface is ignored by Runspace

The Background I'm writing an application that programatically executes PowerShell scripts. This application has a custom PSHost implementation to allow scripts to output logging statements. Currently, the behavior I'm seeing is that some requests…
Mike Bailey
  • 12,479
  • 14
  • 66
  • 123
4
votes
1 answer

How can I expose an embedded PowerShell runspace to remoting

I have an ASP.Net application which can run embedded runspaces for which I have built a fairly extensive PowerShell functionality including: Interactive console, and Web base ISE-like UI a number of commandlets exposing the app functionality &…
Adam Najmanowicz
  • 1,200
  • 6
  • 10
3
votes
2 answers

PowerShell says '%' and `New-Object` are not found. Am I missing an import? WinRM, or Exchange Role permission?

Suppose I already configured IIS to allow the remote runspace of "full", how do I resolve the exception that I'm getting where Powershell says "%" is not found. Then when I comment out the offending for..each statement, it says New-Object can't be…
makerofthings7
  • 60,103
  • 53
  • 215
  • 448
3
votes
2 answers

Is there an easier way to run commands in parallel while keeping it efficient in Windows PowerShell?

This self-answer intends to provide an easy and efficient parallelism alternative for those stuck with Windows PowerShell and being unable to install Modules due to, for example, Company Policies. In Windows PowerShell, the built-in available…
3
votes
0 answers

Why does my powershell runspace seem to run sequentially?

I have built a network keyword searcher to assist with my job. I am opening Word documents and inspecting their content for key words. The process took far too long with a classic "for each" file run search. I developed the below code to execute a…
3
votes
3 answers

How to dynamically add items to a PowerShell ArrayList and process them recursively using Runspace pool?

I have a for loop that iterates through an ArrayList and during the process, adds more items to the list and processes them as well (iteratively). I am trying to convert this function to run concurrently using Runspacepool. Here is the normal code…
Suraj
  • 468
  • 1
  • 4
  • 14
1
2
3
18 19