Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Execute a powershell script from a webpage

4,574 views
Skip to first unread message

BZP

unread,
Sep 9, 2008, 5:23:20 AM9/9/08
to
Hello,

I wonder if it is possible to execute a powershell script and show the
result in a the page from a IIS website (6.0 on a W2003 R2 Ent SP2).

Thanks for your help.

--
P.J.A.

Marco Shaw [MVP]

unread,
Sep 9, 2008, 7:39:44 AM9/9/08
to

These links should help:

http://www.powershelltoys.com/
3 part series:
http://devinfra-us.blogspot.com/2008/05/powershell-and-aspnet-part-3.html

There are even more options...

Marco

--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

alexandair

unread,
Sep 9, 2008, 7:45:20 AM9/9/08
to


PowerShellASP (http://powershelltoys.com/) might be the right thing
for you.

What is PowerShell ASP?

"PowerShellASP is an ASP-like template language for Web Applications;
templates contain a mixture of markup (HTML, XML or whatever you want
to generate) and inline PowerShell code. At runtime, templates/pages
are fully translated to PowerShell code and executed as a single unit
inside a PowerShell pipeline, with the results sent to the client
browser.

PowerShellASP runs off the ASP.NET platform, implemented as a custom
IHttpHandler mapped to *.ps1x files. Because of this, you can mix
PowerShellASP pages alongside any ASP.NET application. This provides a
great way to leverage PowerShellASP inside your existing applications
as needed or you can create complete applications from scratch based
only on *.ps1x pages."

-aleksandar
http://powershellers.blogspot.com

Hal Rottenberg

unread,
Sep 9, 2008, 8:19:23 AM9/9/08
to
BZP wrote:
> I wonder if it is possible to execute a powershell script and show the
> result in a the page from a IIS website (6.0 on a W2003 R2 Ent SP2).

Check out PowershellASP and PoshBoard

http://powershelltoys.com/
http://www.codeplex.com/Poshboard

Also, we talk about this subject on Episode 34, and in Episode 36, we interview
a guy from /n software, the guys who created PowersShellASP.

http://powerscripting.wordpress.com/?s=powershellasp

--
Author, Tech Prosaic blog (http://halr9000.com)
Webmaster, Psi (http://psi-im.org)
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast (http://powerscripting.net)

BZP

unread,
Sep 9, 2008, 10:10:40 AM9/9/08
to
Thanks, PowerShellASP is great !

Regards,

--
P.J.A.

kjhoff123

unread,
Sep 22, 2008, 1:46:04 PM9/22/08
to
I configured PowerShellASP, does anyone have any idea on how to add the
Exchange Snap in to this tool? I haven't found anything online and am not a
programmer. But this would be a great tool especially for those non IE users
that need to see their exchange quota?

Marco Shaw [MVP]

unread,
Sep 22, 2008, 1:53:26 PM9/22/08
to
kjhoff123 wrote:
> I configured PowerShellASP, does anyone have any idea on how to add the
> Exchange Snap in to this tool? I haven't found anything online and am not a
> programmer. But this would be a great tool especially for those non IE users
> that need to see their exchange quota?


I'll try to help you out... I'm assuming you're trying to use this *on*
an Exchange server? Just so we don't have to go through the
requirements of installing the Exchange cmdlets remotely...

kjhoff123

unread,
Sep 22, 2008, 2:06:00 PM9/22/08
to

My ultimate goal here was to be able to allow users that do not use IE the
ability to request their Quota via the PowerShell command

get-mailboxfolderstatistics "mailboxname" | ft FolderPath, ItemsInFolder,
@{Label="FolderSize(MB)";expression={$_.FolderSize.ToMB()} } -auto

kjhoff123

unread,
Sep 22, 2008, 2:05:01 PM9/22/08
to

Actually right now I have it configured locally, I have exchange shell and
management locally installed. I have it running and can execute the supplied
ps1 wmiasset script without issue for local and remote clients. I believe
after many hours of learing that the code needs to call the Exchange SnapIN
within the code so Powershell within the scripting understands the Exchange
calls? If you want copies of the scripts or any files let me know. This is a
pretty much plain jane install of PowerShellASP, I am not changing any code
at this point just changing the PS1 file with a basic "Get-mailbox" call and
a fixed name smithj. If i run this from the Exchange Mgt shell on the system
the ASP site is installed on it returns results. If I run it in the PS1 file
it returns nothing and the script never finishes.

Marco Shaw [MVP]

unread,
Sep 22, 2008, 2:14:40 PM9/22/08
to
kjhoff123 wrote:
> Actually right now I have it configured locally, I have exchange shell and
> management locally installed. I have it running and can execute the supplied
> ps1 wmiasset script without issue for local and remote clients. I believe
> after many hours of learing that the code needs to call the Exchange SnapIN
> within the code so Powershell within the scripting understands the Exchange
> calls? If you want copies of the scripts or any files let me know. This is a
> pretty much plain jane install of PowerShellASP, I am not changing any code
> at this point just changing the PS1 file with a basic "Get-mailbox" call and
> a fixed name smithj. If i run this from the Exchange Mgt shell on the system
> the ASP site is installed on it returns results. If I run it in the PS1 file
> it returns nothing and the script never finishes.

Oh, you may be in for a long battle with user permissions before being
able to actually run the Exchange cmdlets...

Marco Shaw [MVP]

unread,
Sep 22, 2008, 2:17:33 PM9/22/08
to
kjhoff123 wrote:
> I configured PowerShellASP, does anyone have any idea on how to add the
> Exchange Snap in to this tool? I haven't found anything online and am not a
> programmer. But this would be a great tool especially for those non IE users
> that need to see their exchange quota?

Oh, you migth only need to just do something like this in your code:
Add-PsSnapin Microsoft.Exchange.Management.PowerShell.Admin

I was thinking you'd need to do some C#.

Keith

unread,
Sep 22, 2008, 2:28:00 PM9/22/08
to
I am not too woried about that. I believe I have the PowerShellASP running
via Windows Auth right now. So I can get the information from remote systems
as well as local. Are you familiar with PowerShellASP? I believe in the
default.aspx.cs is where the code has to be put to allow it to fire up the
Exchange Admin Snapin but I am not familiar with the sequence. If you want me
to attach the file I can.

I have already created the local profile.ps1 an added Add-PSSnapin
Microsoft.Exchange.Management.PowerShell.Admin which works great for the
local user to lauch PowerShell with the Exchange Snapin loaded. But from my
findings this has to be lauched via this CS file or loaded into memory
somehow. I wish I was more adept to this type of programming.

Keith

unread,
Sep 22, 2008, 2:29:17 PM9/22/08
to
I believe I have the PowerShellASP running via Windows Auth right now. So I
can get the information from remote systems as well as local. Are you
familiar with PowerShellASP? I believe in the default.aspx.cs is where the
code has to be put to allow it to fire up the Exchange Admin Snapin but I am
not familiar with the sequence. If you want me to attach the file I can.

I have already created the local profile.ps1 an added Add-PSSnapin
Microsoft.Exchange.Management.PowerShell.Admin which works great for the
local user to lauch PowerShell with the Exchange Snapin loaded. But from my
findings this has to be lauched via this CS file or loaded into memory

somehow. I wish I was more adept to this type of programming but I am not
knowledgeable on C# at all.

Marco Shaw [MVP]

unread,
Sep 22, 2008, 2:37:59 PM9/22/08
to
Keith wrote:
> I believe I have the PowerShellASP running via Windows Auth right now. So I
> can get the information from remote systems as well as local. Are you
> familiar with PowerShellASP? I believe in the default.aspx.cs is where the
> code has to be put to allow it to fire up the Exchange Admin Snapin but I am
> not familiar with the sequence. If you want me to attach the file I can.

I know of PoshASP, but haven't tried it yet.

Have you tried simply adding this PowerShell code into your .ps1x page:
Add-PsSnapin Microsoft.Exchange.Management.PowerShell.Admin

Karl Mitschke

unread,
Sep 22, 2008, 2:41:09 PM9/22/08
to
Hello kjhoff123,

I am just starting to rewrite my ASP poages that use C# and powershell to
use powershellASP.

To add the Exchange snappin, do this:

<% add-pssnapin *exchange* %>

The web page will have to run in an application pool that is configured wtih
an account that hads the proper exchange permissions to gather the data that
you weant to return to the user.

Then, try this:

<head>
<style>
body,td,th { font-family: Arial, Helvetica, sans-serif; font-size:
14px; }
h1 { font-size: 26px; color: #0B4982; }
#left { float:left; margin:10px; width:180px; border:1px
solid gainsboro;font-weight:bold}
#left P { border-bottom:1px solid gainsboro;padding:4px;
margin-bottom:2px;margin-top:2px; }
#left UL { margin:2px; padding:0px; }
#left LI { list-style: none; margin:4px; }
</style>
</head>
<body>
<% add-pssnapin *exchange* %>
<% $mailboxname = $request['logon_user'].split("\")[1]%>
<% get-mailboxfolderstatistics $mailboxname | ft FolderPath, ItemsInFolder,
@{Label="FolderSize(MB)";expression={$_.FolderSize.ToMB()} } -auto %>
</body>


You will have toi fornat the results to your liking ;)


Karl Mitschke

unread,
Sep 22, 2008, 2:47:34 PM9/22/08
to
Hello kjhoff123,

My earlier reply was all sorts of ugly

I am just starting to rewrite my ASP poages that use C# and powershell to
use powershellASP.

To add the Exchange snappin, do this:

<% add-pssnapin *exchange* %>

The web page will have to run in an application pool that is configured wtih
an account that hads the proper exchange permissions to gather the data that
you weant to return to the user.

Then, try this:


kjhoff123

unread,
Sep 22, 2008, 3:15:01 PM9/22/08
to
Karl pointed out the ApplicationPool settings. I think I am going to start
over from there. I will post back with my results....

kjhoff123

unread,
Sep 23, 2008, 9:04:01 AM9/23/08
to
Thanks for everyones help, the Application Pool running in a user that had
the rights was the issues I was having. By putting in the Exchange Admin Snap
in is the PS1 file works perfectly. Thanks again!

janaarts

unread,
Jan 13, 2009, 5:05:08 AM1/13/09
to

kjhoff12

can you share more details?

I want to do the same

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng

0 new messages