Powershell Overview

Scripting has been around for a long time in virtually every major Operating System since the 1970’s. The humble DOS batch file is probably the most well known and widely used scripting technology in Windows. VB Script improved Windows scripting and is definitely a big step up from the batch file.

The latest scripting technology for the Microsoft platform is PowerShell which can be found at the heart of Windows 2008 Server and many of the latest generation of Microsoft products. Practically every command that can be done via the GUI interface can be scripted and in many cases the GUI will actually show you the PowerShell commands to do the task.

Before you decide to replace your old login script with something new check that you environment meets the requirement of Windows XP SP2 or Windows 2003 SP1 or later. If everything is in order, downloaded PowerShell from here: www.microsoft.com/technet/scriptcenter/topics/msh/download.mspx

Once you have PowerShell installed on your client devices it’s time to start upgrading your login script. Here is a short example that maps a network drive:

# MyScript.ps1
$DriveLetter = “F:”
# Create the Com object
$net = New-Object -com WScript.Network;
# Disconnect the drive if it exists
# Map the network drive
# Open the folder with Windows Explorer
$shell = new-object -comObject Shell.Application

Powershell commands can be called using the command below from other scripts or as a Group Policy script.

  • powershell.exe  \\server\share\myscript.ps1

The script above is a simple example. The real power of PowerShell comes from more advanced automation e.g. scripting the configuration of an Exchange 2007 or MOSS 2007 environment or create backup jobs in DPM 2007. PowerShell scripts can be used to build a system and then repeat the process in a consistent way. PowerShell is also leveraged by a number of third-party developers to build management functionality into their products e.g Quest and F5 Networks.

If you are serious about developing in PowerShell a number of useful third-party tools are available to help with development. PrimalScript is a power editor with debugging capabilities. PowerGadgets is a library that does many graphical functions including the creation of Vista Sidebar Gadgets.

Powershell Resources: