Step-by-Step Guide

PowerShell automation for Windows Server 2008

Windows PowerShell is quickly becoming a sought after skill set. A management platform designed by Microsoft, PowerShell allows administrators to automate tasks resulting in greater productivity and efficiency. Download, install and configure PowerShell in the following three easy steps.

Step 1: Download PowerShell
Unless you are running Windows 2008, Windows 7 or Windows 2008 R2 you will need to download PowerShell before you can get started:

    Requires Free Membership to View

Download PowerShell here.

Step 2: Install

 
Environment Install directions
Windows 2008 PowerShell ships as a feature on Windows 2008. To install PowerShell, simply add the feature (see figure 1.)
Vista,
Windows 2003,
Windows XP
Double-click the file downloaded previously and step through the wizard. This will install PowerShell in %SYSTEMROOT%System32WindowsPowerShellv1.0 and add the appropriate shortcuts.


Figure 1 Installing PowerShell in Windows 2008. (Click on image for enlarged view.)

Step 3: Configure
Following a successful PowerShell installation, three basic features need to be configured to get the most bang for your buck.

Execution Policy

By default, PowerShell will not run any scripts and the file association (for .PS1) is set to notepad. These are security measures that Microsoft implemented to protect you. There are four security levels:

  1. Restricted: No scripts will run (default).
  2. AllSigned: Only digitally signed scripts by a trusted CA will run.
  3. RemoteSigned: Scripts downloaded from the Internet Zone will need to be signed. All other scripts will run.
  4. Unrestricted: All scripts will run. You will still get prompted for "Internet Zone" scripts.

For more information:  get-help about_Execution_Policies

Profile

Profiles are like the autoexec.bat for PowerShell; they are used to setup the environment with customizations. There are two main locations for profiles:

  1. The global location, which affects all PowerShell sessions
  2. User specific and stored in the user's profile -- there is a default variable called $Profile that contains the path to the user's profile.ps1 file
For more information:  get-help about_profile

Prompt

One of the most common uses of a profile is to create a custom prompt. Every time a command is executed, a function called prompt is called. It is possible to overwrite this function with your own version. While this is useful, be careful -- remember, it gets called every time you run a command; therefore, you need to keep it simple and quick.

For more information:  get-help about_prompt

Useful Commands in PowerShell

 
Command Use
Get-Help This cmdlet provides help for any cmdlet. If you want to know what a cmdlet does and how to use it… this is your guy!
Get-Command This cmdlet will return a list of commands that PowerShell can use. By default it lists cmdlets and functions.
Get-PSSnapin This cmdlet will return a list of loaded snap-ins. If you want to see all snap-ins available use the -register parameter.
Get-Member This cmdlet will list all the members an object has to offer. You can use this to find out what properties and methods to use on the object returned from a cmdlet.

For free PowerShell scripts and more PowerShell information and news, I suggest checking out the following websites:

ABOUT THE AUTHOR:
Brandon Shell has been in the IT industry since 1994. He started out as a PC tech and general fix-it guy for numerous companies. In 2000, he joined Microsoft as contractor for the Directory Services team (the first of several times) until he became a full-time employee in 2002. In 2004, he left Microsoft to pursue a new position focusing on his real passion, PowerShell. In 2007 he joined the PowerShell MVP ranks and spent the last several years building his PowerShell knowledge and helping others build theirs.

This was first published in August 2009

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: