Server efficiency: how PowerShell can help SMBs in time-saving automation

Thomas Lee Advice
26 Nov, 2012

PowerShell looks scary but it could prove to be a very useful tool for admins looking to automate their operations

Windows PowerShell is Microsoft’s task automation platform for IT professionals. It is designed to enable the automation of common IT tasks, including the control and management of just about every aspect of Windows and Microsoft’s Windows applications.

PowerShell is a key component in Windows Server 2012, and has been broadly adopted in the industry with companies like Cisco, EMC, and VMware jumping on the PowerShell bandwagon.

The technology first saw the light of day in September 2003 as an early beta product known in those days as Monad. The first formal release of PowerShell came with Windows Vista (and Server 2008. Version 2 came with Server 2008 R2 (and Windows 7). The most recent version ships with Windows 8 and Server 2012. Version 3 is also available for Server 2008/R2 and Windows 7.

PowerShell comes with a simple text-based shell, similar to Cmd.Exe and a graphical tool called the Integrated Scripting Environment (ISE). The ISE is an updated shell that handles Unicode. The text-based shell did not handle Unicode – which meant users in countries such as Japan and China could not easily use the shell. The ISE is also extensible and a great, free, development tool to help admins build and manage scripts.

PowerShell, both the shell and ISE, has three key constituents:

  • Cmdlets – these are, in effect, mini-programs that enable IT pros to do useful tasks, such as creating new Active Directory users, setting policies for Lync Server or creating Exchange policies. PowerShell comes with loads of cmdlets; adding applications of Server roles and features can add more.
  • Objects – Every ‘thing’ in PowerShell is an object – numbers, strings, Exchange mailboxes, SharePoint sites and IIS web sites are all represented as objects which drastically simplifies administration. This takes a bit of getting used to, but once you master it, objects really simplify building of automation scripts.
  • The Pipeline - this is a Unix/Linux concept which allows the output of a cmdlet (ie the objects produced by a cmdlet) to be consumed by other cmdlets. This dramatically simplifies writing scripts to do common administration functions.

PowerShell has been broadly embraced by all of the application teams at Microsoft as well as by Microsoft customers as the way forward for automation. PowerShell can also be used to manage on-line software packages such as Office 365.

PowerShell task automation – so what?
So far, so good but what’s in it for the smaller company? Legions of Windows Small Business Server users and administrators have managed their systems quite successfully for years – so why bother now? PowerShell experts may view the answer to be self-evident. But it does tax the minds of many who are seeing PowerShell for the first time and who don’t want to become programmers!

However, there’s a huge advantage in getting to grips with the technology. PowerShell enables companies to reliably automate pretty much any computing task in the Windows Platform. And with the advent of Version 3, the scope of what can be achieved widens to include products from companies like Cisco, EMC and VMware.

Every IT pro in any sized company is faced with performing repetitive tasks – simple things ranging from creating a new user (and removing that user when the employee leaves), changing passwords, adding users to groups, etc.

There are ways around this. Admins can fire up the Active Directory Users and Computers MMC, and click their way through the process of adding the new users. But with a little bit of effort it’s possible create a script that takes a CSV file (e produced using Excel) and adds/removes/updates user accounts. The time taken to write the script will be more than repaid in the speed of managing new users (see here for a sample script and a sample CSV file).

Of course, these days, a new employee does not just need an Active Directory account, but an Exchange Mailbox, a default home folder, access to Lync and SharePoint, etc. But it would be straightforward to extend this script to achieve these extra goals.

There’s a saying in IT circles that any Unix administrator worth his/her salt, faced with doing any task a third time will write a script to achieve it. With PowerShell this becomes true of Windows admins!

In addition to the productivity a PowerShell script can provide, using PowerShell to automate common tasks offers  two significant extra benefits:

  • Reliability – a PowerShell script does not get distracted and accidentally ‘forget’ to do some part of the automated task. So every time the  new-user provisioning script runs, it won’t accidentally forget, for example, to create an IIS Home Page for the new user.
  • Auditability – the actions a script takes can be audited so it’s possible to see what was done, and with a good script when it was done and by whom. This can provide better accountability.

Read more about: