Thursday, March 21, 2013

Push Sitecore solutions to the servers with PowerShell and WinRM

It's hard to beleive it, but just a year ago I didn't even think about automating deployment of Sitecore solutions. It seemed to be impossible, especially for highly customized project I was working on.

With PowerCore framework, automated deployment can be setup in an hour, and it makes a great difference!
The time goes fast, and just a few days ago I've realized that I can now press a single button to:
  1. Create a VM on Windows Azure / System Center VMM / whatever
  2. Setup required OS features / frameworks
  3. Push my Sitecore solution to the server
And this is where it becomes really interesting...

Initial version of the PowerCore sample assumes that you copy your deployment script to the server, and execute it manually. But what if there are hundreds of servers in your cloud? And you want to scale them automatically? And...

PowerShell has a solution for that and it is called WinRM. You can remotely manage hundreds of servers nearly with the same effort as managing local server. It lets you execute PowerShell commands at remote server, uses firewall-friendly protocol, and it is just awesome. All you need to do is to wrap your commandlets:

$commands = {
  # Commands here will be executed at remote server

and send them to any Windows-based server:

$session = New-PSSession -computerName "%server FQDN here %"  
Invoke-Command -Session $session -Scriptblock $commands

Yes, it is as simple! Of course, there are some tricks required to use framework remotely or pass variables, but you don't need to worry about, as I've just published updates to the PowerCore, which include WinRM - based script example (see Sample - WinRM.ps1). There was also some refactoring after the initial release, all framework files where rewritten as modules. Enjoy! 

No comments:

Post a Comment