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
1
vote
1 answer

why can't I execute a simple powershell rasdial command in my runspace in a vb.net winforms app?

I've built an app that contains a PowerShell runspace. It works perfectly for everything I've thrown at it.... until today. One bit of functionality I've added detects when the user is trying to access corporate resources and will highlight if their…
John
  • 755
  • 1
  • 18
  • 46
1
vote
0 answers

PowerShell Retrieving value of TextBox from another thread (WPF)

I'm looking to be able to get the text from my textbox (folderDialogTextBox.Text), I am able to successfully set the text using the dispatcher, but oddly enough I cannot read the current value of the text. When running $syncHash from the console, I…
Rickybobby
  • 245
  • 1
  • 13
1
vote
1 answer

runspace: EndInvoke() fails to return all the scriptblocks output , only the last exception

The script block $sb = { write-output "Testing 1" write-output "Testing 2" throw " Exception in sb" } Calling EndInvoke() only returns the below. My runspace tasks are in some case hours long. I can not lose all the output except the last…
deetle
  • 197
  • 8
1
vote
1 answer

Is it possible to share module between runspaces or assign a module to a runspace pool in Powershell?

I'm writing a multithreaded script which was leveraging the ability to multithread with runspaces and saving time until I had to use the Exchange module. It takes so long to load the Exchange module, it's almost as slow or slower than synchronous…
Bbb
  • 517
  • 6
  • 27
1
vote
1 answer

How can I collect the return value data when using a runspace pool and begininvoke?

I have this code working well synchronously with powershell.Invoke() however with powershell.BeginInvoke() I am not able to capture the output. To use the below code you'll need to populate the $servers variable and it should run otherwise. I tried…
Bbb
  • 517
  • 6
  • 27
1
vote
1 answer

How to run a Powershell script with Rename-Computer in it using C#

I need to run a Powershell Script using C# with "Rename-Computer" in it on a Windows 2016 Server. The Problem is that it is not working or executing correctly. The remote Computer doesn't get renamed and also not in the AD. When Executing there are…
Gumpex
  • 23
  • 6
1
vote
1 answer

Powershell Runspace - New-Object not recognized

Given the following... Powershell script that implements a runspace pool A HashTable of named scriptblocks Scriptblocks that call New-Object to create SQL related objects (SMO, SqlClient, etc) My script iterates through a list of servers and adds…
1
vote
1 answer

Imported or Loaded Modules in Runspace, still 'Connect-AzureRMAccount' throws 'command not recognised as cmdlet..'

As the question is quite intuitive, I'm trying to use AzureRM in my asp .net core web application. I've created InitialStateSession and Runspace as follows. Runsapce Version: 7.0.3 Installed the AzureRM module from…
Venkatesh Dharavath
  • 500
  • 1
  • 5
  • 18
1
vote
1 answer

Is there a .NET Core alternative to System.Management.Automation.RunspaceInvoke?

I'm currently porting a library from .NET Framework to .NET Core. The Framework version of the library makes use of some runspaces in Powershell, which I'm not very familiar with (leave aside the merits of using Powershell in Core for the sake of…
1
vote
0 answers

Powershell memory usage in runspacepool

i have a problem with code: Measure-Command{ $controller=Get-ADDomainController -Filter *| Select -ExpandProperty Hostname $users=Get-ADUser -Filter * |select samaccountname $scriptblock={ param($samacc,$controller) $result=@() …
Vad
  • 693
  • 3
  • 13
1
vote
1 answer

The experiment of passing a variable to a stream

I want to understand how flows communicate with each other. More precisely, when a new thread is born and a variable is passed to it, then this is a common variable or a synchronized copy. Here is what I do to figure it out: $A = '0' # Expansion of…
1
vote
0 answers

Execute Resolve-DnsName in a runspace within a job

The following code works fine: $ScriptBlock = { Resolve-DnsName -name BELCL003000 } $Pool = [RunspaceFactory]::CreateRunspacePool(1, 6) $Pool.ApartmentState = 'MTA' $Pool.Open() $Runspaces = @() $Runspace =…
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
1
vote
0 answers

Powershell instance locks up main thread

I have a Powershell script with a Windows Forms UI from which I create a new Powershell instance, which in turn starts IE (hidden) and grabs information from a website. Sometimes the UI locks up and only becomes responsive again after manually…
1
vote
1 answer

PowerShell redirect Information Stream to Verbose Stream from inside script

I'd like to redirect the Information Stream to the Verbose Stream from within my executing PowerShell script (not from the PowerShell command line). As far as I know, the only way of getting a handle on the Information Stream object is via the…
Jeff
  • 35,755
  • 15
  • 108
  • 220
1
vote
1 answer

Difference between a runspace and external request in Powershell

According to https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.internal.internalcommand.commandorigin?view=powershellsdk-1.1.0#System_Management_Automation_Internal_InternalCommand_CommandOrigin There is a runspace, and…
john doe
  • 170
  • 1
  • 11