PowerGist – Source Control for Powershell ISE with Github Gists

 

 

Install

Get Chocolatey (awesome command line installer for windows)

Open powershell as administrator and type:

C:\> choco install powergist

Once that’s done simply type ISE and you’ll see it pop up on the right.

Login to your Github account and away you go.

*Warning – This was a quick project and should be considered Alpha quality to see if it was possible and/or useful. If you find a bug or issue head over to the github repo site to report it or fix it in a pull request*

About

One of the reasons I always advise people writing software to provide an API’s or a plugin model is that it allows end users to enhance the functionality of the product. If it doesn’t do what they want they can add it making your product better for free. It’s also a nice way to POC new features, internally, off the critical path.

So when I sat next to @StuartLeeks and said “I wish Powershell ISE integrated with some kind of source control” he pointed me to the addin model for ISE and said “Bet you can’t do it” (well known as a stealth motivation tactic for me within the team). So I set about trying.

The addin model is awesome. It’s nice and quick to get up and running and I was done writing a simple integration for Githubs Gist service (if you’ve never used it think git repos but for snippets) inside a day. I’ll go into a bit of detail on how to write addins in a future post, in the meantime feel free to have a look at the source.

Gracefully Drain Session from IIS Before Restarting/Stopping

I needed to do this recently when working with a team to automated releases of several websites.

The team have a fairly common setup. They’ve got more than one web server behind a load balancer, the load balancer calls a keep alive page to see if the servers are behaving and if they fail to respond stops sending them traffic until they’re healthy again.

What I wanted to do was rename the keep alive page, so the box stops getting new traffic, then wait for the existing sessions to complete and finally start updating it.

The second bit is key here, you don’t want customers using the site to get dropped mid-upload or form post.

I set about seeing what could be done with powershell and put together this little sample. It uses the IIS CmdLets to see how many sessions are still active and waits for them to complete before stopping IIS.

Thought it was a neat little sample worth sharing.

EDIT: I realized that the current script only looked at inflight http requests, I’ve put together a more complex script to interrogate the Active ASP Net sessions on a given IIS Website. See second file in the gist below, hopefully useful.

Chocolatey, PowerShell DSC and Azure IAAS – Automating dev box creation

Hi,

So back in 2013 I wrote a post on automating the creation of a Virtual Machine, and installation of all my loved bits of software, using Chocolaty and Remote Powershell. Well things have moved on in the Azure IAAS world and we have a nice new way to automate installation and configuration of VM’s.

PowerShell DSC (desired state configuration) gives you a nice declarative way to define the setup of your machine. It also allows you to write custom modules to extend its functionality, which is just what I’ve done for Chocolatey. It’s here on GitHub.  

So now you can add in all the nice apps you want on the box is one simple DSC config, along with windows features etc.

Below is an example of using the cChoco module to install Git on a new Azure VM. I’ve broken down the script into sections with a full version at the bottom.

Brief description of Sections:

  1. This is an example of a simple DSC config that installs IIS on the machine where it runs, for reference.
  2. Pulls down the custom cChoco module from Github, this needs to be copied onto your box so it can be used later.
  3. Creates a DSC config using the module which installs git from Chocolatey. You can add more “cChocoPackageInstaller” nodes, changing the Name parameter to be the package you’d like to install or add “WindowsFeature” nodes to install IIS and other bits.
  4. Takes this DSC config and pushing it up to Azure, ready to apply to my nice new VM.
  5. Create a VM adding in the DSC extension and providing the DSC Config name and file from step 4

Finally at the bottom of the Gist is a full script that will combine all these steps and do some extra checks and goodness.

Happy Automating!

@lawrencegripper

PS. You can check on the install progress through the portal, screenshot below the Gist.

Review Progress in Preview Portal:

DSCStatus

Follow

Get every new post delivered to your Inbox.

Join 309 other followers