CURRENT STATUS: The forums you are now looking at are CLOSED. Visit the new forums.


Using PowerShell as a page handler with IIS?  [SOLVED]

Creating PowerShell extensions in Visual Studio? Post here! Monitored by MVP Doug Finke.
Forum rules
1. Use the CODE or POWERSHELL buttons to format code and commands.
2. Avoid the use of obscure and punctuation aliases (like ? and %).
3. Don't apologize for being a "noob." We don't mind.
4. If we help you solve your question, please click the green SOLVED checkmark.

More forums tips & etiquette

Using PowerShell as a page handler with IIS?

Postby yooakim » Sat Aug 18, 2012 6:06 pm

I have searched the net but not been able to find anything. What I am looking for is to use PowerShell as a page handler for IIS. Wouldn't it be nice if one could write server code that emits it's output via IIS to the client?

Anyone know if this can/have been done?

/j
yooakim
 
Posts: 23
Joined: Wed Aug 15, 2012 9:10 am

Re: Using PowerShell as a page handler with IIS?

Postby JasonHelmick » Sat Aug 18, 2012 7:09 pm

Hi Yooakim!

I noticed your post regarding IIS and wanted to see if I could help. I'm more of an Admin than a dev, but have you looked at this?
http://devinfra-us.blogspot.com/2011/02 ... art-1.html

I would be interested in Doug's perspective on this, but I think this might help you.

Have a great day!

The Inadvertent IIS Admin,
Jason

Stop by the PowerShell and IIS forums!
viewforum.php?f=10
The Inadvertent IIS Admin,
Jason

Stop by the PowerShell and IIS forums!
viewforum.php?f=10
User avatar
JasonHelmick
Shareholder
Shareholder
 
Posts: 43
Joined: Sun Aug 12, 2012 7:08 pm

Re: Using PowerShell as a page handler with IIS?

Postby yooakim » Sat Aug 18, 2012 8:40 pm

Jason,
Thanks for the link, interesting but not entirely what I was thinking of. My intention is to let the IIS server be able to simply execute URLs with the PS1 extension, without ASP.NET! Iderally one should be able to do:

Code: Select all
http://myserver/get-iisstatus.ps1


And what would happen is that the get-iisstatus.ps1 would be executed on the IIS server and the output sent back to the webbrowser. Hmm... somone ought to have done that? Or else it's time to do it! ;-)

Cheers,
Joakim
yooakim
 
Posts: 23
Joined: Wed Aug 15, 2012 9:10 am

Re: Using PowerShell as a page handler with IIS?

Postby DougFinke » Sat Aug 18, 2012 9:34 pm

Thanks for the reply Jason. I was going to post that link and similar ones.

Thanks for the clarification Joakim, it helps us dial in on the question.

I need to dig a bit deeper, I've seen some http handlers written.

Here are some links we can have some discussion about. I played with this when the Windows Developer Preview became available. The Management OData IIS Extension requires work to set things up and looks promising.

  • Needs Windows Server 2012 Management ODATA Web Services Dev. Tools
    The Management OData IIS Extension is a piece of infrastructure to create an ASP.NET web service OData endpoint. An endpoint built on top of Management OData IIS extension, allows teams to expose access to management capabilities, currently realized through Powershell cmdlets and scripts. It does that by processing OData requests and converting them into PowerShell cmdlet invocation
  • I wrote this up PowerShell vNext – Web Service Entities
  • Adam Driscoll posted this Management OData and PowerShell
  • A CodePlex project that implements an http handler. I haven't tried this but could be a good launch point
Doug's Book | Doug's Blog | PowerShell MVP
User avatar
DougFinke
MVP
MVP
 
Posts: 11
Joined: Mon Aug 13, 2012 1:24 pm
Location: New York City

Re: Using PowerShell as a page handler with IIS?

Postby DonJ » Mon Aug 20, 2012 3:08 pm

Generally speaking, I'm not certain you'd WANT to execute a .PS1 directly like that... I can definitely think of a few downsides.

but, doing so would require a custom host to be built (since it'd need to know to send output to the Response HTTP stream, amongst other specializations). That said, embedding PowerShell code within a normal C# or VB ASP.NET page is easy-peasy. That's definitely how Microsoft envisioned people incorporating PowerShell commands into a Web page.
Don Jones - Microsoft MVP, VMware vExpert
My PowerShell Books . Twitter . LinkedIn . About me
User avatar
DonJ
Shareholder
Shareholder
 
Posts: 1067
Joined: Sat Aug 11, 2012 8:36 pm
Location: Las Vegas

Re: Using PowerShell as a page handler with IIS?  [SOLVED]

Postby yooakim » Sat Sep 08, 2012 7:30 am

Actually, after a bit of more research I found that there is an implementation of a custom IHttpHandler mapped to *.ps1x files that executes PS1 files, case closed!

http://www.powershellinside.com/powershell/asp/

I haven't had time to test this but it certainly looks like what I wanted.

Cheers,
Joakim
yooakim
 
Posts: 23
Joined: Wed Aug 15, 2012 9:10 am

Re: Using PowerShell as a page handler with IIS?

Postby JasonHelmick » Sat Sep 08, 2012 5:21 pm

Awesome! Nice catch! I'm going to sit down and try it out myself...let us know how results turn out!
The Inadvertent IIS Admin,
Jason

Stop by the PowerShell and IIS forums!
viewforum.php?f=10
User avatar
JasonHelmick
Shareholder
Shareholder
 
Posts: 43
Joined: Sun Aug 12, 2012 7:08 pm

Re: Using PowerShell as a page handler with IIS?

Postby DonJ » Sat Sep 08, 2012 5:32 pm

That would definitely be easier for admins than embedding PowerShell in an ASP.NET page, so I'm curious to see what you guys come up with.
Don Jones - Microsoft MVP, VMware vExpert
My PowerShell Books . Twitter . LinkedIn . About me
User avatar
DonJ
Shareholder
Shareholder
 
Posts: 1067
Joined: Sat Aug 11, 2012 8:36 pm
Location: Las Vegas


Return to PowerShell for Developers

Who is online

Users browsing this forum: No registered users and 1 guest