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
2
votes
1 answer

Powershell 'runspace' does not run from the Powershell console

I am trying to understand why this code will run in the Powershell ISE but not from the Powershell console function close-window (){ # close $hash.window.Dispatcher.Invoke("Normal",[action]{ $hash.window.close() }) # clean up …
beehaus
  • 415
  • 1
  • 4
  • 13
2
votes
0 answers

C# start.process powershell longer runtime than native ps1

I'm using the following C# code to run a PowerShell script, the script runs within a second when run outside of C# but within the following C# code block it runs in excess of 9 secs. The C# code is compiled and run as a windows service under the…
Sjoerd
  • 167
  • 1
  • 9
2
votes
1 answer

Keeping a powershell runspace alive in C# WPF?

I'm planning on building an Active Directory/Exchange admin console using C# talking powershell to DC and Exchange servers. I want to on application launch establish powershell connections to these servers and then keep them alive so I can keep…
2
votes
1 answer

Create Remote Powershell Session and load modules in Runspace using C#

I want to connect to a remote powershell session and load modules in the runspace. I got the connection part using this link :- Create remote powershell session in c#? How do I load the modules in the runspace and call other commands in that module…
RDs
  • 513
  • 6
  • 22
2
votes
3 answers

Why can't I Write-Error from PowerShell.Streams.Error.add_DataAdded?

I'm investigating using Runspaces for parallel running. Currently, I'm trying to get back messages from whatever script I might run, to help me diagnose problems, in the same stream type from which they originate: verbose messages in the Verbose…
user2871239
  • 1,499
  • 2
  • 11
  • 27
2
votes
1 answer

runspace New-MsolLicenseOptions commandparameter

I am trying to write a console application to manage user license options in Office 365. I am using runspace in conjunction with the MSOL powershell module. Basically i am able to manage all the users licence requirements with exception of the…
2
votes
2 answers

How to PowerShell 2 or 3 when creating RunSpace?

On a computer with PowerShell 2.0 and PowerShell 3.0 installed, how can I select which is started from my C# app when I create the RunSpace? It seems there are all kinds of configuration parameters, but none that control which version of PowerShell…
DougN
  • 4,407
  • 11
  • 56
  • 81
2
votes
2 answers

Run Powershell from C#

I need to start a powershell script from C# and get the PSSSecurityException on pipeline.Invoke() AuthorizationManager check failed. My code: RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); using (Runspace runspace =…
Jorn
  • 217
  • 2
  • 5
  • 14
2
votes
1 answer

Should Remote Powershell sessions be closed?

I'm writing a C# server application that, among other things, calls several remote Powershell cmdlets on an Exchange server. It's not the main activity of my application, but these functions are occasionally called. When they do, I do the…
Avner Shahar-Kashtan
  • 14,492
  • 3
  • 37
  • 63
2
votes
1 answer

PowerShell Runspace to Exchange Online Budget Exceeded Error

I have an application that programmatically invokes PowerShell commands on Exchange Server. Connecting the app to Exchange online server outlook.office365.com is successful, and invoking individual commands works, but sending several commands in a…
Boris R.
  • 371
  • 4
  • 11
2
votes
2 answers

Powershell: Create file in runspace session

Just a quick on this morning. Is it possible to create a file and store in it the Powershell runspace/session memory? Something like: out-file 'powershell session space'? instead of: out-file C:\temp\system_info.txt I'm creating an e-mail template…
obious
  • 609
  • 8
  • 21
  • 33
2
votes
2 answers

Memory Leaks while using PowerShell

I am connecting to a Office 365 instance using power shell in VB.net.This works fine but the memory usage of the service in which this is running keeps on increasing.I am using the following code to initiate and close the power shell.Seems like the…
agupta
  • 403
  • 1
  • 7
  • 17
2
votes
1 answer

Runspace & custom powershell

I'm trying to develop some tool in C# which is using PowerShell. However, I have to use different powershell then this one which is used by default when creating Runspace, I mean this…
Lukasz Spas
  • 595
  • 2
  • 9
  • 23
1
vote
3 answers

Import a Powershell Module on a Remote Server in a C# Runspace

I need to be able to import a module that resides on a remote machine through a C# runspace. To be clear what I mean by this: The service I'm creating resides on server A. It creates a remote runspace to server B using the method below. Through…
Arangarx
  • 51
  • 2
  • 8
1
vote
1 answer

Run a Remote Powershell Script on a Different Remote Server in a C# Runspace

I need to be able to execute a PS1 script that resides on a remote machine against another remote machine through a C# runspace. To be clear what I mean by this: The service I'm creating resides on server A. It creates a remote runspace to server…
Arangarx
  • 51
  • 2
  • 8