|
Guy recommends: This CG will put you in charge of controlling changes to network routers and other SNMP devices. Download your free Config Generator |
Windows
PowerShell Tutorial
|
|||||||||
VBScript |
Windows PowerShell |
|
' Memory.vbs WScript.Quit ' End of Sample Memory WMI / VBScript |
# Windows PowerShell Tutorial script "System Name = " + $CompSys.name
|
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).

The Engineer's Toolset v10 provides a comprehensive console of utilities for troubleshooting computer problems. Guy says it helps me monitor what's occurring on the network, and the tools teach me more about how the system itself operates.
There are so many good gadgets, it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, discovery, diagnostic, and Cisco tools. Download your copy of the Engineer's Toolset v 10
Here 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 (See here for detailed instructions)
3a) 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
3b) Better still, if you have PowerShell 2.0 seek out the ISE (Integrated Scripting Engine) version.
The 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:
Get-Eventlog -list.
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.
# Windows PowerShell Tutorial
Get-Eventlog - list # (Wrong)
Get-Eventlog-list # (Wrong)
Get-Eventlog -list # (Correct)
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:
Process
help
eventlog
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.
If 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.
PowerShell is a friendly new scripting language for administering Windows and Exchange servers. In particular, it 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. I have prepared about 100 pages of Windows PowerShell tutorials for you to enjoy.
• PShell Home • Introduction • Dreams • 3 Key Commands • Cmdlet scripts • PowerShell examples
• Process example • Backtick • Get-Command • PowerShell ISE • Get-Member • Set-ExecutionPolicy
Please write in if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Download my ebook:
|
*
|
|
Guy
Recommends: WMI Monitor and It's Free!
|
|
Home Copyright © 1999-2010 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |