Friday, August 17, 2012

Running PowerShell code from a web page

As PowerShell gets used more and more in the IT industry, its not unusual to begin growing libraries of scripts and commands, and even automate some of the scripts to run automatically. After a while, I have developed a method of organizing my library so I can find my scripts as needed, and even include some rudimentary version control.
The growing library becomes an issue when multiple people in your organization are using PowerShell as well. Each person begins growing a library, each person handles versioning independently, and each person may schedule the scripts to run automatically. Suddenly there is a lot of tribal knowledge (i.e. I don't know how to do that, go talk to X).
I had always felt that having some centralized web portal that allowed me to see my organizations scripting library would be ideal. Additionally, it would be awesome if I could simply click a button on a form and make a PowerShell script execute.

  • Need a VM? Fill out this online form and click create.
  • Reboot a host? Select the system to reboot and click go.
  • Restart services? Select the system and service and click Restart.

The first major hurdle to this is getting PowerShell to run through a web page, it turns out this has been around for some time at The example simply imports System.Management.Automation from PowerShell and creates a PowerShell object. Once created, use PowerShell.Commands.AddScript() to import the PS code, and PowerShell.Invoke() to execute.

What next? Add security, tie it into a database to act as the library, maybe add some scheduling...

No comments: