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

Run docker-compose command from C# .Net 4.7

I'm wishing to run a command from C# to a container set up via docker-compose. In Powershell, I run this command and the file is created: docker-compose exec database sh -c "mysqldump -u((username)) -p((password)) ((databasename)) >…
eltiare
  • 1,817
  • 1
  • 20
  • 28
0
votes
2 answers

Powershell runspace output behaves differently depending on how returning custom object is defined

I am experimenting with Powershell runspaces and have noticed a difference in how output is written to the console depending on where I create my custom object. If I create the custom object directly in my script block, the output is written to the…
Collin Craige
  • 109
  • 1
  • 8
0
votes
1 answer

In Powershell, displaying a server restart check script in the textbox, freezes the WPF GUI

I created a PowerShell script that uses a WPF GUI. It has the option to choose a server from a combobox (more servers will be added later). The chosen server can be rebooted by clicking on the reboot button. Then a script, that will check the reboot…
0
votes
1 answer

How to access underlying pipeline in Powershell Api C#

I need to access underlying powershell default Pipeline which just created as result of Pwoershell.Create(); I need to stop that pipeline so that script execution must stopped immediately. I know I can Create Pipeline object and execute script by…
Usman
  • 2,742
  • 4
  • 44
  • 82
0
votes
0 answers

PowerShell: Call runspace N times and cleanup particular instance when done

I have below example in my script. I call same runspace and same script block but with different arguments. The purpose is to update many windows forms in a responsive GUI. The problem is that all finished instances are kept in the memory. If I make…
Vinkelman
  • 117
  • 1
  • 7
0
votes
1 answer

Why Runspace in Powershell scripts in C#

I want to be clear about one thing that why we are using Runspace while running the PowerShell scripts in C#. It runs even though the absence of Runspace. If it can be run without the Runspace why we need? For eg: PowerShell ps =…
SaravananKS
  • 577
  • 4
  • 18
0
votes
1 answer

Using Invoke-WebRequest on an array in PowerShell

I'm trying write a script that will grab the fortune 100 URLs from here, put those into an array, and then write a runspace that uses Invoke-WebRequest to get the content of those URLs and writes that content to a file. This is the code that I have…
mfalde
  • 15
  • 6
0
votes
0 answers

PowerShell: Runspace & Delegates

I try to improve the speed of my Exchange Online script by using runspaces. My problem is the fact that the script-block could not call the Get-MailboxFolderStatistics because this cmdlet is provided by the Exchange Online module. Therefore have I…
thuld
  • 680
  • 3
  • 10
  • 29
0
votes
1 answer

Powershell Script Using Runspaces

I am new to PowerShell, and just for practice I got instructions to, "Read in fortune 100 URLs to an array...then using runspaces, connect to each one and write the page you get with Invoke-WebRequest to file." Then I was given this link:…
mfalde
  • 15
  • 6
0
votes
2 answers

How to clear and reuse a DataGridView in powershell?

I'm using a Datagridview inside a windows form to display some data. The data is loaded in the background after pressing a button. This works fine when I press the button for the first time. But I need to be able, to do this again and again without…
0
votes
3 answers

Powershell start-process Runspace wont start except with -noexit flag

So i wrote this little GUI with Runspaces. it works as expected when running it in ISE, and if i start it from a PS prompt, but when i try to run it from a Shortcut it just wont boot as long as i dont use the -noexit flag. but when using the -noexit…
0
votes
1 answer

Executing chain of commands in Powershell Pipeline

I want to execute a set of powershell commands to manage my HyperV Guest machine. Can I use the below code to do this ? Do I need to clear pipeline.Commands before executing the next command ? Collection results = null; using (Runspace…
Yesudass Moses
  • 1,841
  • 3
  • 27
  • 63
0
votes
0 answers

The term 'Set-MpPreference' is not recognized as the name of a cmdlet when running through C#

I am trying to set the preference DisableRealtimeMonitoring to false with the following runspace: try { Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); Command…
Goemon Code
  • 73
  • 1
  • 10
0
votes
2 answers

Powershell: TextBlock in Runspace – Add Inline with fontstyles

I have a problem with powershell and styling a part of Text in a TextBlock. I use a function to push text to a runspace window and a TextBlock in it, which works fine. Function Update-Log { Param ( $Content, $type = "Black" …
0
votes
0 answers

Runspace scriptblock array cannot be passed

I'm tinkering with the code below. It should create a PoshRSJob and run the function foo again in the runspace there. I want to be able to turn the $list parameter into an [array] or [string[]], but when I do it throws errors. I considered…
CuriousOne
  • 922
  • 1
  • 10
  • 26