Questions tagged [powershell-hosting]

When you embed PowerShell inside your process, like powershell_ise.exe does.

Documentation: https://learn.microsoft.com/en-us/powershell/scripting/developer/hosting/writing-a-windows-powershell-host-application

15 questions
18
votes
2 answers

Hosting PowerShell: PowerShell vs. Runspace vs. RunspacePool vs. Pipeline

I attempting to add some fairly limited PowerShell support in my application: I want the ability to periodically run a user-defined PowerShell script and show any output and (eventually) be able to handle progress notification and user-prompt…
JaredReisinger
  • 6,955
  • 1
  • 22
  • 21
9
votes
1 answer

Hosting powershell runspace in web application

I'm writing a web service that executes powershell scripts (active directory, directory management, etc). Right now, Runspace instance is created per web request. As Runspace initialization is time consuming operation, plus often I have to import…
Misha N.
  • 3,455
  • 1
  • 28
  • 36
6
votes
2 answers

How to determine if Write-Host will work for the current host

Is there any sane, reliable contract that dictates whether Write-Host is supported in a given PowerShell host implementation, in a script that could be run against any reasonable host implementation? (Assume that I understand the difference between…
jimbobmcgee
  • 1,561
  • 11
  • 34
3
votes
1 answer

Getting Enter-PSHostProcess behavior via PSSessionConfiguration file

Scenario: Windows service with Powershell host embedded into it. Single runspace is allocated at startup. Multi-dll solution. Requirement: Need to access .NET classes inside running service. From a local Powershell instance using…
2
votes
1 answer

Hosting a restricted Powershell with custom cmdlets

I am hosting powershell within my app and have set up a restricted runspacepool, which is basically empty (to the best of my knowledge). public class MyPowerShell : IDisposable { private RunspacePool _runspacePool; private PowerShell…
2
votes
2 answers

hosting powershell like cli in asp.net mvc to perform maintaince

I need CLI for our asp.net mvc application to perform maintenance tasks and some status tasks. I think powershell is designed to provide CLI. But i do not know anything about it other than name. How can i host powershell in asp.net mvc running in…
mamu
  • 12,184
  • 19
  • 69
  • 92
2
votes
1 answer

Can I create the variables and launch the methods of my classes in PowerShell hosted by me?

PowerShell 4.0 I want to host PowerShell engine in my application and to have the capability of using API of my application in the hosted PowerShell. I read the description of the PowerShell class and its members in the documentation. In the…
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
1
vote
1 answer

Can I use Powershell command window to interact with a Powershell hosting app?

I'm working on an application to have Powershell embedded in it. I'm wondering if there is a way I can launch a separate Powershell command window, and interact with my application through this Powershell window? Can anyone point out some reference?…
awatto
  • 231
  • 5
  • 16
1
vote
1 answer

Add-Type cmdlet: is it possible to point the set of the DLL files instead of Assembly names?

I need to launch the cmdled in PowerShell is hosted inside of AutoCAD. Assemblies of AutoCAD (it is host of PowerShell) are not in GAC. How can I correctly to point the assemblies of AutoCAD? Is it possible to point the set of the DLL files instead…
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
0
votes
1 answer

Using the PowerShell host from C# how can I get the output?

Having the following NET 5 Console application: static void Main(string[] args) { using var ps = PowerShell.Create(); // ps.AddCommand("Get-Service"); ps.AddStatement().AddCommand("Get-Service"); ps.Invoke(); } The calls seems to be…
g.pickardou
  • 32,346
  • 36
  • 123
  • 268
0
votes
0 answers

In c#, add commands to PowerShell InitialSessionState using script and make them discoverable from C#

Is there a way to find functions that were imported into an InitialSessionState using ImportPSModule()? I have this wrapper around PowerShell to run scripts self-hosted by my applicaton (comments and error checking removed for brevity) public class…
A Noethe
  • 121
  • 2
0
votes
1 answer

PowerShell AddCommand called from C# Exception

I am trying to build a C# console app that executes a series of PowerShell commands that run against an Azure Subscription. var line1 = "$cred = Get-Credential" var line2 = "Add-AzureAccount -Credential $cred" var psi =…
Snowy
  • 5,942
  • 19
  • 65
  • 119
0
votes
1 answer

How can I create the PowerShell variables for working with the static members?

PowerShell 4.0 In my application the Application class has the set of important properties, methods, and events. I want to work with that members through the app PowerShell variable (it would be like the alias of the class). But the…
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
0
votes
1 answer

Understanding PowerShell Hosting

I've done some work hosting PowerShell and have done a lot of reading but I am seeing strange behavior and it makes me wonder if I do not understand the host like I thought I did. I am creating a Runspace with RunspaceFactory: var runSpace =…
Adam Driscoll
  • 9,395
  • 9
  • 61
  • 104
0
votes
1 answer

Why is my PowerShell host running as 32-bit on a 64-bit machine?

I'm building a PowerShell host in VS 2012, currently in a C# (.NET 4.5) Console Project. The project is configured for Any CPU and 'Prefer 32-bit' is not checked. I've added a reference to System.Management.Automation manually by adding …
serialhobbyist
  • 4,768
  • 5
  • 43
  • 65