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

Connecting to Exchange online using C# powershell sdk

I used to use Basic authentication when connecting to Exchange online, but after Microsoft disabled the basic authentication I have not had luck connecting to it. Having it use authentication popup would be ideal. Code looked something like this: …
Jan
  • 91
  • 1
  • 1
  • 8
1
vote
1 answer

PowerShell: RunSpace.SessionStateProxy.SetVariable is not setting variable

ConsoleApplication: class Program { static void Main() { using (var runSpace = RunspaceFactory.CreateRunspace()) { runSpace.Open(); runSpace.SessionStateProxy.SetVariable("Var1", "Alex"); …
Rookian
  • 19,841
  • 28
  • 110
  • 180
1
vote
1 answer

PowerShell WPF Runspace script - $syncHash returns Null in console but works in ISE

Im testing a script I found on https://learn-powershell.net/2012/10/14/powershell-and-wpf-writing-data-to-a-ui-from-a-different-runspace/. It is about PowerShell and WPF: Writing Data to a UI From a Different Runspace. I copied the whole code and…
Dom
  • 168
  • 8
1
vote
1 answer

Powershell How to integret 4 script block in loop, as Start-Rsjob to run parallel & get each's status?

Simple question, but its solution will become life-Saver for me. I have powershell script as below that just copy paste some source folders to/on some destination locations as routeen as weekly backup. Source folders are on windows Server2K12 on HDD…
1
vote
1 answer

How to exit from ForEach-Object Parallel and update a variable outside of Runspace in Powershell 7?

The code below isolates the task I am trying to do. Once a number over 3 is checked in $loopMe, I want the foreach-object loop to end across all runspaces and that the value of numberOverLimit is set to true. $loopMe =…
OrigamiEye
  • 864
  • 1
  • 12
  • 31
1
vote
1 answer

Adding command to CreatePipeline() vs Using Commands.Add()

I'm having some trouble understanding the difference between the following code snippets: using System.Management.Automation; using System.Management.Automation.Runspaces; Console.WriteLine("#------ TidyScript ------#"); Runspace runspace =…
RicardoP
  • 187
  • 8
1
vote
1 answer

wpf powershell applicaiton sometimes on not responding

i've created a WPF PowerShell application which functions OK. But sometimes when entering another user ID it gets on not responding for a while before showing some output. I've searched the internet and I can resolve this by adding runspaces. But I…
Toon
  • 29
  • 8
1
vote
1 answer

Powershell Add custom class to InitialSessionState of runspacepool

I can add a function to my runspacepool using initialsessionstate like this: $initialSessionState = [InitialSessionState]::CreateDefault() $definition = Get-Content Function:\Icmp-Ping -ErrorAction Stop $addMessageSessionStateFunction =…
Dom
  • 168
  • 8
1
vote
1 answer

Powershell runspaces clipboard interaction

I've recently gotten around to using runspaces, but I've a wall of sorts. I had this little script where one of the functions sets clipboard to a predefined text. When run in default runspace it works perfectly. As soon as I placed the script in a…
Nawad-sama
  • 151
  • 2
  • 12
1
vote
0 answers

How to avoid sending a Connect/Disconnect-ExchangeOnline for every pwsh command in a c# Blazor app

I am developing a server side Blazor app to facilitate Exchange online management via a GUI. I have a helper class that setups the runspace and communicates the results back to the the Blazor component. I added the class via an scoped Dependency…
NicCarlos
  • 11
  • 1
1
vote
2 answers

Powershell stream events

I wonder if it's possible to subscribe to the current Powershell session event stream so that every time some information/warning/error etc is added to the stream I can read it as an object. I was able to subscribe to DataAdded events of the 3…
managerger
  • 728
  • 1
  • 10
  • 31
1
vote
0 answers

Get-WmiObject in PowerShell RunSpace C#

EDIT: posted too soon, I figured it out. The ManagementObjectSearcher was looking at Win32_DiskDrive, where the PS command is looking at Win32_Volume. Updated that and made some tweaks so it will only show me drives with a drive letter, and to…
L3s
  • 11
  • 2
1
vote
1 answer

Object not being added to parent object in different runspace (Winforms/Powershell)

I have a function "Get-UserFolders" that I imported into the runspace using: $Definition = Get-Content function:\Get-UsersFolders -ErrorAction Stop $SessionStateFunction = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry…
RJ45
  • 55
  • 6
1
vote
1 answer

How to search for a string in multiple text files in an active running log

I am trying to search for a string in multiple text files to trigger an event. The log file is being actively added to by a program. The following script successfully achieves that goal, but it only works for one text file at a…
Sceptersax
  • 83
  • 1
  • 9
1
vote
0 answers

Powershell: New-Object System.Collections.ArrayList gets a Runspace attribute automatically

I am new to Powershell and am debugging a powershell script in which I am creating runspaces and storing the objects holding these runspaces in an ArrayList. While debugging, the ArrayList storing these objects automatically gets "Runspace" (while…
Meet Gujrathi
  • 65
  • 1
  • 6