tags:

views:

642

answers:

5

Microsoft seems to be heavily pushing that their server applications (i.e SQL Server 2008, Exchange Server, etc) all have some type of PowerShell integration. The logic makes sense in that one can choose to manage the application from a GUI or CLI.

Therefore if one were to follow that trend and want to build an application that had a PowerShell interface, how would one even start?

Has anyone in the community done this type of thing? If so, what seems to be the best approach?

Update:

The UI needs to have a certain look/feel. Therefore, PowerGUI does not lend itself in this situation. However, I've used PowerGUI and do agree that it can help bridge gaps.

Part of the confusion is really whether or not hosting PowerShell is necessary in order to build an application on top of it. From what I've found, it is not (i.e. Cmdlet's). However, I have not seen anyone really discuss this in the answers yet.

+3  A: 

Exchange 2007 admin console hosts PS directly, and surfaces every UI action by showing a ubiquitous "and here's the PowerShell you just asked me to do" UI model). SQL Server 2005 & 8 admin consoles demo the concept of surfacing everything in a UI as scripts as a way of dogfooding scripting abilities (but there is little PowerShell support in SQL Server) (Distinction between Exchange and SQL Server's type of support added in response Shaw's comment, thanks)

PowerGUI is a good shell/framework for driving PowerShell based systems. If you're building a larger system, this may or may not be a good direction for your case, though the fact that it allows people to develop cusotm consoles might be a useful extensibility point for your system as a whole.

PowerScripting podcast has a few interviews on topics like this. Also get-scripting podcast

Ruben Bartelink
Yup, they just have a bunch of cmdlets and a custom link with console file to launch PowerShell.
JasonMArcher
@JasonMArcher not sure what you're driving at/specifically agreeing with. PowerGUI is an open source tool [intended to be used mainly by admins, but devs that need to automate stuff too] that serves as a good intermediate level example of PS hosting, and worthy of a look in the context of Scott's Q?
Ruben Bartelink
Exchange 2007 and System Center Virtual Machine Manager 2008 have full PowerShell integration: The UI actually runs cmdlets in the background. SQL Server is not so much a good example for PowerShell integration: The UI does not run cmdlets in the background, and there's only a couple of cmdlets.
Marco Shaw
Perhaps we should clarify what we are talking about. Scott asked about creating a PowerShell interface, a way to interact with this app from PowerShell. For just that, I think a snapin (or module in v2) would be the best idea.
JasonMArcher
Now, you could take that plan a big step further and implement all your interface in PowerShell and wrap GUI around it. This is what Exchange and SCVMM have done. This has the advantage of one code base for the interface, but would mean rewriting your interface if you already have one.
JasonMArcher
@JasonMArcher: I getcha. My first (and only!) read reckoned he was looking to do a console+script UI for a new app simulataneously (which is why I was referring to SQL Admin as fitting in that space). @Scott: are you happy with the answers? Looking for anything more, different?
Ruben Bartelink
Actually, the "application on top of PowerShell" bit in the title led me down the path of assuming what I mentioned in the prev comment... (i.e., as opposed to "how do I add some PS integration spice")
Ruben Bartelink
Awesome information in this thread! Thanks for the participation.
Scott Saad
+4  A: 

Start here: How to Create a Windows PowerShell Hosting Application

Alex Barrett
This link looks like a better choice to get started IMHO
Sung Meister
Some other good stuff: http://blogs.msdn.com/daiken/archive/2007/04.aspx
Marco Shaw
This is a good place to start for hosting, but to my understanding one does not necessarily have to "host" PowerShell in order to build on top of it.
Scott Saad
A: 

You could try primal forms for building a complete application from a script or you need to build your application with an snappin cmdlets (the previous being what is used by sql, exchange etc.) but link to primail forms here

http://www.primaltools.com/products/info.asp?p=PrimalForms

qa_warrior
+1  A: 

This is an intriguing idea!

I haven't ever thought about it, and I have no idea if I think it's a good idea, but some creative things could be done.

For example, suppose you have some typical administrative-ish piece of software. Don't really care what, specifically. In a classic app dev't scenario, I'd typically try to generate a list of Command objects (things that'd implement some sort of ICommand), and then my UI would bind to those.

Suppose, now, that you were to instead create a cmdlet for each Command. The UI would more-or-less exist as a friendly interface for the core logic in the suite of cmdlets.

Yeah, ok, nothing new here. People've been doing this for a long time, building up GUIs around command-line tools. I think the key difference is that you'd instead be building up individual command line tools from the concept of the application itself. Heck, it might make more sense for both the application and the cmdlets to reference some shared library of commands instead of making the GUI sit on top of the cmdlets themselves.

Errr- sorry for the scatterbrained response. This answer was pretty much purely stream-of-consciousness. :)

Greg D
+2  A: 

I attended a PowerShell / MMC 3.0 Devlab at Microsoft a few years ago that taught how to do this very thing. The basic idea was to create the "management functionality" via a series of PowerShell cmdlets in a PSSnapin for your application. CLI oriented folks can just load the snapin and party on your cmdlets directly. For the GUI oriented, you build a MMC snapin that hosts a PowerShell runspace which, in response to GUI actions, executes the appropriate PowerShell cmdlets to tweak the application that is being managed. For bonus points, you display what PowerShell code will be executed by the MMC GUI such that the code can be copied and pasted into a script. There are plenty of examples out on the web that show how to host a PowerShell runspace in your (or the MMC) process and execute PowerShell script in that runspace and get back results.

Keith Hill