Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API access to PowerShell Web Access?

PowerShell Web Access allows you to run PowerShell cmdlets through a web browser. It shows a web based console window.

Is there any way to run cmdlets without typing them in to the console window? And is there any way to get the results back?

I'm envisaging an app that lets a non-technical user restart a print queue (for example) without having to know PowerShell. The app would display a list of print queues and then the user could select one and restart the queue. The app would essentially be a wrapper that takes care of the syntax and variables so that users don't need to know.

Is there a way to do that through PowerShell Web Access? Or is there some other way for a non Windows app to send arbitrary commands to a Windows server without reinventing the wheel?

like image 256
user3521643 Avatar asked Nov 02 '22 01:11

user3521643


1 Answers

Not with PowerShell Web Access**. That is designed for an interactive session.

There are a few ways you could do this. All examples are illustrative and may be outdated, insecure, etc.

  • Create an ASP.NET web application running C#. Run PowerShell in the C#. Use PowerShell remoting as needed. Example.
  • Create GUI applications using Windows Presentation Foundation or WinForms. Use PowerShell remoting as needed. Example.
  • Create a services with an API (e.g. REST) that PowerShell can hit.
  • ** OK, I lied. Create a clunky solution that uses delegated, constrained endpoints accessed through PowerShell Web Access.
  • For each of the above solutions that uses PowerShell remoting, consider delegated and/or constrained endpoints. Example.

We have a web application that allows certain users to perform certain functions with certain parameters. Uses ASP.NET backed by C# with a set of predefined PowerShell scripts and configuration of who can do what stored in a SQL DB. For example...

  • Jane can restart application pool X on server Y.
  • John can restart service Z on server Q.
  • IT Support can unlock their own 'administrative' accounts from their standard accounts.
  • All of this can run from non-Windows computers. Some of it might be carefully exposed to allow use on Mobile devices : )

If you have the use cases, the small overhead of designing the system and writing the code behind it will pay off quite quickly.

Cheers!

like image 174
Cookie Monster Avatar answered Nov 08 '22 14:11

Cookie Monster