Introduction to scripting for Systems Administrators - PowerShell

by Dmitry Kirsanov 19. November 2011 13:28

There was a time, when IT specialists were mainly either systems administrators or developers. There was a time, when being Database Administrator would also mean having perfect knowledge of SQL. New generation of IT specialists don’t remember that time, and that only because technology evolved so greatly, it is considerably harder to possess the whole range of features offered by a monster product such as SQL Server 2008.

But this post is not about databases at all. It’s about how we can manage the growing complexities of enormous range of technologies that we have to use in business.

Today we have no MCDBA certification, but a range of certifications for SQL Server specialists – administrators, developers and business intelligence specialists. Now developers can’t do anything well unless they know enough about systems administration, and yes, you can’t be effective enterprise systems administrator without being able to script your tasks.

Scripts were always part of systems administrators job. In Windows world, that was VBScript in form of either vbs (Visual Basic Scripting edition) or wsh files (Windows Scripting Host, but that’s the same VBS, just with some advanced features), and while it wasn’t pleasant, it also wasn’t hard to become fluent in it. And effective.

But that was in the era of Windows Server 2003. Now, with Windows Server 2008 and Windows Server 8, your weapon of choice is PowerShell – object oriented scripting language empowered by .NET.

Now, before I am going to describe cons and pros of PowerShell over VBScript, I want to make it clear, that in the real world you don’t have much choice, and should learn both of them. It’s not only because there are legacy systems out there, but also because VBScript became a paramount element of many system components and there are still places, where it’s irreplaceable, whether you like it or not.

To name a few, the little annoying animated dog in windows search and whole search GUI are powered by scripts. Switch off either VBScript or JavaScript processing libraries, and your system’s behavior will change dramatically.

So, what is the main difference between PowerShell and Visual Basic or JavaScript scripting, and what makes it so special?
The answer is – .NET. PowerShell is able to use not only COM and WMI objects, like VBScript can, but also utilize the full power of .NET, which makes it’s possibilities much wider.

And if you are planning to deploy your PowerShell script to target environment, first thing to bear in mind is that PowerShell is not installed by default and you should install it using Control Panel in Windows Server 2008 or as separate software package in earlier systems, such as Windows Server 2003 or XP. But besides that, it’s much faster,  you can do much more with it and unlike the VBS, it has a perfect free code editor.

Developers don’t like scripting because comparing to real programming languages – even Visual Basic and Java themselves, scripting languages look weak and ugly. Systems Administrators, on the other hand, don’t like scripting because they don’t consider themselves to be programmers. So we have a dilemma here – both developers and systems administrators don’t want to script, because it’s too ugly for ones and too hard for others. Who should do it then?

According to Microsoft, scripting is part of the job of Systems Administrators. It was part of MCSE certification, although not paramount, and is a significant part of MCITP: Server Administrator program for Windows Server 2008.

So once understood who should do it, the only question left is – how? And what to begin with?

I decided to start a tale of PowerShell with dead simple example of it’s main principles. It’s rather short and I made it in one take, but if you have experience with either creating batch files or scripting using VBScript, you may find it interesting.

I am planning to create a series of about 10 walk-troughs about PowerShell, to cover various areas, hopefully deep enough.

So, here is the first walk-trough, enjoy!

Introduction to Microsoft Windows Powershell for Systems Administrators
blog comments powered by Disqus