Questions tagged [powershell-hosting]

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

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

16 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,357
  • 1
  • 19
  • 20
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,435
  • 1
  • 26
  • 35
5
votes
0 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,341
  • 8
  • 28
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…
Antony Scott
  • 20,775
  • 10
  • 60
  • 88
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
  • 11,628
  • 18
  • 66
  • 91
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
  • 10,107
  • 12
  • 64
  • 150
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
  • 211
  • 4
  • 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
  • 10,107
  • 12
  • 64
  • 150
0
votes
0 answers

C# Add commands to long running hosted PowerShell session after calling Invoke()

I'm trying to (eventually) write a C# service wrapper for long running .exe applications, such as crypto nodes or game servers. So far I've written a small PowerShell host that outputs the .exe output (currently to the console, eventually it will go…
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
  • 24,276
  • 25
  • 91
  • 195
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,488
  • 15
  • 56
  • 110
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
  • 10,107
  • 12
  • 64
  • 150
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,030
  • 7
  • 57
  • 98
1
2