jump to navigation

Lovin’ me some POSH… Thursday, 09/01/2011

Posted by Percy in Fun with Powershell, Technology.
Tags: ,
trackback

POwerSHell, that is.  Apparently the PS acronym is overused, so the folks at MS decided that PowerShell should be called POSH.

I started going through a PowerShell primer a few months ago, and while it’s a good start, you don’t really learn something until you start applying it.  At least, that’s usually how it works for me.  At the time, I didn’t really understand it, and so I didn’t understand how to apply it.

Then, about a six weeks ago, I started working on a task for my current project.  Basically, we were trying to figure out an easy way to set up our enterprise application which is fairly complicated.  I started by setting up the web piece locally, but quickly realized that I didn’t have all the necessary dependencies that I needed.  I was in a spiral of writing a console app to go through a directory of assemblies, load up each assembly to find all of it’s references, and make sure they all were downloaded.  Thank you, cyclic dependency in the .NET framework (System references System.Configuration, which references System, etc.)

After a few google searches, I came across an article describing a PowerShell script that could load up assemblies and query the references.  The article was describing a different problem then I was trying to solve, but I decided to see if I could tweak it to help us out.  The more I started playing with it, the more I started to realize the potential.

Long story short, I’ve been using PowerShell almost exclusively over the last six weeks, and I’m loving it.  So far, I’ve written scripts (including but not limited to)

  • …that will parse a directory of assemblies (.dlls and .exes) and, given a list of directories, will search and download any needed dependencies until all the dependencies are downloaded from the list of directories into the original directory (it’ll also search the GAC just to be sure) – it also validates that you are downloading a specific version
  • …that will download a core website, and the client customizations on top of it, download all the dependencies (see first script), create all the necessary virtual directories (configurable), create an app pool with custom authentication that can be passed in, links the website to the app pool, and updates your host file with the site name
  • …that will download all configuration files for both applications and websites and will drop them in the appropriate folder for our application
  • …that will look into all configuration files that are downloaded and make sure the data in them is accurate (database server, file locations, etc) for their purpose and environment
  • …that will change all configuration files for an entire environment of clients to be used in a local setting (changing any database reference to “localhost”, changing all file paths to a local version, etc.)
  • …that will query my google spreadsheets, download all the information, parse it, and return it to me in a format I can use for personal financial reporting
  • …that uses the producteev API, and will add tasks to a given dashboard based on whatever criteria I provide
  • …that will poll all of the websites on a machine and return all of the virtual directories in a common format
  • …that will parse the output from the virtual directory “audit” (above script) and will return data in a format that helps me determine what virtual directories are common and which ones are individual
  • …that, given a URL, will hit the URL at a frequent interval, and scrape the page to show updated information
  • …that, given a list of our clients (around 26), will get the latest successful build location from TFS, and download it to a common location for deployment, then checks all of the downloaded assemblies to make sure the version of the references are updated
  • …and a bunch of little scripts and commands here and there to help me gather information

I’m completely digging PowerShell.  So far, I haven’t seen a reason to write another console app – though it’s much more flexible and powerful than most of the console apps I’ve written.  You have access to full .NET objects, so the possibilities are really limitless.  It’s not just for IT Administrators.  It’s really for Devs and DBAs as well.  It’s not just a scripting language.  It’s definitely so much more.

Are you using PowerShell?  If so, how?  If not, why?  🙂

Comments»

No comments yet — be the first.

Leave a comment