Windows PowerShell - Microsoft's New Scripting LanguageIntroduction to Windows PowerShellMy mission is to two fold. Firstly, to encourage a new generation of script writers to learn PowerShell; secondly I want to provide experienced scripters with a bank of example scripts so that they can convert to PowerShell. To newbies I want to say: 'It really will be easy to get started. You will be surprised by how many tasks on your Windows computer benefit from a PowerShell script'. To the experienced scripters I say, 'I want to build a reference library for that moment when you have forgotten the syntax for a particular PowerShell command'. To help you discover the benefits of PowerShell, I will not only provide
real life tasks, but also I will add learning points.
One of my greatest joys is when you modify the
code in my PowerShell tutorials to fit your
situation.
In September 2007 Microsoft released PowerShell 1.0 RTW (Release to Web). To check which version
you have, launch PowerShell and type these five characters: Windows PowerShell Sections
Individual PowerShell Tutorials
˚
Getting started with Windows PowerShellOne trigger for dabbling with Windows PowerShell is so that you can configure Exchange Server 2007. However, I believe that the pressing reason for learning PowerShell is for issuing WMI commands. When you want to interrogate your Microsoft operating system, three lines of PowerShell will replace twenty lines of VBScript. PowerShell is free, therefore all you need is a spare half hour to experiment with the potent new verb-noun pairs at the PowerShell command line. Before you install PowerShell, make sure that you have the correct version for your XP, Vista or Windows Server 2003 operating system.
Four reasons to learn Windows PowerShell
Note: Existing Windows executables, such as Ipconfig and ping, perform in the PS Shell just as they do in the old CMD 'DOS box'. Simple PowerShell ExamplesPreamble, Start, Run PowerShell. get-service Here is another example, type: I first realised the ability of PowerShell when I saw three lines of PowerShell replace about twenty lines of VBScript. The task is to interrogate Win32_classes, we can either use the traditional VBScript and WMI, or the new PowerShell with its verb-noun commands.
Microsoft refer to this new PowerShell command style as 'task-based'. As with other scripting language, PowerShell lends itself to automating repetitive tasks, especially as you can store the lines of code in cmdlets scripts to reuse latter. For programmers and developers, PowerShell offers the ability to manipulate the operating system's objects, it is to gain this ability that you need to first install .Net Framework 2.0 (or 3.0). PowerShell InstallationHere are the three stages to get up and running with Windows PowerShell: 1) Download, then install .Net Framework 2.0 2) Get a copy of PowerShell RC2 or the Vista Version of PowerShell (See here for detailed instructions) 3) Once you have installed the downloaded executables, press the Windows key +r, this launches the Run command (even in Vista), now type in the dialog box: PowerShell. Visit Microsoft's Windows PowerShell download center Getting Started - PowerShell StructureThe situation is that you are at the PowerShell prompt, and you want to get started. The basic PowerShell command consists of two-word sentences. Start with a verb, follow with a hyphen and end with a noun. Naturally, you press carriage return when you have finished the command. Try these PowerShell examples: get-Process (Correct). get - process (Wrong no spaces required next to the hyphen). With time, and
plenty of practice, you will soon increase your
vocabulary. A good place to start is with nouns such as eventlog,
process and service. For example: From the above example, we learn that the hyphen has a second, or complimentary role, namely to act as a modifier, switch or as PowerShell calls it a -parameter. If we study this command structure, the role of a space, or lack of a space, becomes obvious, even intuitive, for example -list tells the command to display all the event logs. However, after get-Eventlog the code needs a breather, hence a space BEFORE the -list modifier. get-Eventlog - list (Wrong) Perhaps the most useful command for beginners is: get-help.
Alternatively, you could try plain: help. Incidentally, from this we deduce that the default verb is 'get'. Test this theory by typing just a noun that
PowerShell understands for example: In each case 'get-' is assumed. (get-Process, get-help or get-Eventlog) Other common verbs are: set, start, stop, new, add, copy and out (out as in output file). PowerShell is a potent language, in this section I am just scratching the surface. Once you get going, then you can create more complex scripts by employing the usual scripting structures such as functions, loops and 'where' clauses. Abilities of Microsoft PowerShellIf PowerShell were a car, so far we have only driven in first gear and I have barely touched the accelerator. For now, you will either have to trust me when I say PowerShell has power, depth and flexibility, or else you can research for your self. To give you one example, with PowerShell you can create new objects for example, DirectoryServices.DirectoryEntry or the simpler, system.DateTime. Keep in mind that it is thanks to .Net Framework that PowerShell allows you to build such objects. Summary of Windows PowerShellPowerShell is a friendly new scripting language for administering Windows and Exchange servers. Even in its RC2 form, PowerShell makes tasks such as interrogating WMI objects easier. Moreover, one day PowerShell will be Microsoft's standard scripting shell, meanwhile my PowerShell tutorials will make it easier for you to configure Exchange 2007, and also Active Directory in Windows Server 2008. See more Microsoft PowerShell tutorials• PowerShell Home • Introduction • Dreams • 3 Key Commands • Cmdlet scripts • Real life tasks • Remote PowerShell • WinRm and WSMan • Invoke-Command • Jobs and -asJob Please write in if you see errors of any kind. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.
*
|
||||||||||