By David Wiseman (Administrator)published 06 Feb 2008, modified 05 Nov 2009
My Rating:
Vote
Rating:
Not Rated
Views:7646

PowerShell Introduction

What is PowerShell?

PowerShell is a new scripting language built on the .NET framework and designed specifically for system administrators.  PowerShell is supported on Windows XP (SP2), Windows 2003 Server (SP1), Windows 2003 Server R2 and Windows Vista.  Although it is supported on the aforementioned operating systems it is a separate download that must be installed.  Windows 2008 will be the first operating system that ships with PowerShell already installed.

How do I create a PowerShell Script?

PowerShell scripts are text files saved with a "ps1" file extension.  This means that you can create PowerShell scripts using Notepad.  When you save a PowerShell script in notepad be sure to enclose the name in double quotes. e.g. "MyScript.ps1".  The double quotes will ensure that the file gets saved with the right extension (instead of MyScript.ps1.txt).

Although you can use notepad to develop PowerShell scripts, programs like NotePad++ can help with PowerShell script development.  NotePad++ can highlight syntax and displays the line number, both of which can be useful when developing scripts.  PowerShell is available as a user defined language in the current version of NotePad++.

How Do I Run a PowerShell Script?

To run a PowerShell script you need to have the .NET framework 2.0 installed as a prerequisite.  You will also need to download and install PowerShell.  The default security policy does not allow you to run PowerShell scripts so you will need to modify this policy to allow your scripts to run.  Open a PowerShell console (you should have a shortcut in your start menu after the installation).  Type the following command to view your current setting:

get-executionpolicy
 
You use the set-executionpolicy command to change your security setting.  Use the following command for more information and a list of available options.:

set-executionpolicy -?
 
To turn off security completely, you can run the following command:
 
set-executionpolicy unrestricted

To run your powershell script, set the current directory to the folder containing your PowerShell script.  You can use the normal MS-DOS commands to change the current folder.  If your script was called "MyScript.ps1" you would execute the script by typing the following command:

.\MyScript

Note that you can ommit the "ps1" file extension but you must type ".\" before the filename to run the script.

Further Reading

This has been a very breif introduction to PowerShell so I would suggest some additional reading.  Microsoft's website is a good place to start:

Windows PowerShell 

Find a PowerShell Script 




  Post Comment
Order By:  
User Comments
      
Be the first to post a comment!