1. Windows Powershell初接触
我们之中有些人是因为需要配置Exchange Server2007,才开始对Windows Powershell全新的学习。但是,我认为可以使用WMI命令是更为直接的一个原因。当你想查询你的操作系统信息的时候,三行的Powershell语句就可以取代20行的VBscript语句。Powershell是免费的,因此你只需要利用你的空余时间来熟悉Powershell命令行中的语句。在你安装Powershell之前,确认你在你的XP、Vista或2003操作系统上安装了正确的版本.

学习Powershell的4大理由
1. 通过学习Powershell,你会了解到使用Powershell来配置你的服务器,肯定比使用图形界面来配置要高效得多。使用Powershell脚本可以解决服务器的问题。通过Powershell你可以查询到很多图形界面所得不到的信息,运气好的话你可以使用脚本来直接发现问题——而这些都很神奇。
下面我们就以一个小例子来向你演示Powershell的实力。正如你所知道的,任务管理器可以显示所有的进程,而现在Powershell不但可以列出所有进程,它还可以把这些进程以公司名称来分组。而你继续简单的输入下面一行命令:
Get-process | group-object company

clip_p_w_picpath002
2. Powershell 可以达到和VBscript一样的效果,并且命令更少。比如,Powershell使得对WMI编程更简单,比如,输入:get-wmiobject win32_bios.
get-wmiobject win32_bios

clip_p_w_picpath004
另外你还可以通过使用Powershell来取代VBscript而对活动目录进行编程
3. 我预感到,老的CMD命令将会慢慢逝去,取而代之的是新的Powershell。更重要的是,新的Powershell语言将给你直接控制Windows操作系统的方法,这和Unix系统使用Bash语句来控制系统一样。
简单来说,Powershell就是Windows管理的明天。
4. 学习Powershell的主要理由是,你可以管理Exchange Server 2007, Longhorn Server (windows 2008).微软考虑到在如此复杂的产品中,比如Exchange和Windows 2008中有太多的菜单和子菜单去管理,我们需要另外一种简单办法,这就有了非常好用的脚本语言,它就是Powershell.
另外,现有的Windows可执行命令,比如IPconfig或者Ping, 你可以像在老的CMD Dos里面一样,在Powershell里面执行。

ping www.google.com

clip_p_w_picpath006


Powershell的简单实例
点击 开始-->运行,输入Powershell,回车,在命令行里面,输入get-service
get-service

clip_p_w_picpath008

另外一个小例子是,在命令行里面输入 get-wmiobject win32_computersystem
get-wmiobject win32_computersystem

clip_p_w_picpath010
从下面这个小例子,可以看到在Powershell只用三行语句就可以达到VBscript 20行的效果。我们的目标是查询Win32_classes,我们可以使用老办法(VBscript+WMI)或者使用新的Powershell。
VBScript语句
' Memory.vbs
' VBScript to discover how much RAM in computer
' -------------------------------------------------------'
Option Explicit
Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strComputer
strComputer = "."
Set objWMIService = GetObject( "winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
( "Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
Wscript.Echo "System Name: " & objComputer.Name _
& vbCr & "Total RAM " & objComputer.TotalPhysicalMemory
Next
WScript.Quit
' End of Sample Memory WMI / VBScript

Powershell 语句
# Windows PowerShell script
# Displays ComputerName and memory
$CompSys = get-WmiObject win32_computersystem
"System Name = " + $CompSys.name
"Memory = " + $CompSys.TotalPhysicalMemory


微软把新的Powershell命令行风格定为“基于任务的”,像其他的编程语言,Powershell可以让其自身来自动执行重复性的任务,特别的是,你可以把这些代码存在cmdlets脚本以供以后使用。对于程序员和开发者而言,Powershell提供了一种办法去执行操作系统对象,当然你首先需要安装好 .net framework 2.0 (或3.0)

Powershell安装方法
1. 安装.net framework 2.0
3. 在运行栏里面输入“Powershell”

Powershell构架初接触
基本的Powershell命令包含两个词的句子,一般都是以动词开始,中间有一“减号-",并且以一个名词结尾。请看下面的例子:
get-process (正确)
get - process (错误,没有空格)
通过足够多的时间和练习,你会马上增加你的词汇量的,推荐学习名词的地方是使用Eventlog, process 和service, 比如
get-eventlog -list

clip_p_w_picpath012
通过上面的例子,我们知道有两个减号,后面那个减号又称为开关或者在Powershell里面成为-参数。如果我们知道这些构架,空格的作用,我们就相当清楚了。比如, -list 告诉命令去显示所有的系统日志,但是,它需要和get-eventlog区分开,所以前面需要加空格
get-Eventlog - list (错误) 
get-Eventlog-list (错误) 
get-Eventlog -list (正确)
可能对所有的初学者而言最有用的命令就是,get-help, 或者,你可以简单的输入help,其实我们已经省略了默认动词”get“。以此类推,你可以直接运行下面的命令
Process
help
eventlog
每个都相当于默认加了前缀get-
其他常见的动词是Set, start, stop, new, add, copy 和Out(out 指的是输出文件)
help process

clip_p_w_picpath014
get-help process

clip_p_w_picpath016
Powershell是种非常强大的语言,在此,我只是把其中表面的一部分简单介绍了下。一旦你认真学习下去,你将能够创造出很多复杂的脚本,其中也可以加上函数、循环、以及”where“条件

PowerShell的学习
如果Powershell是辆车,我们也只是刚刚开头,只是碰到了油门。从现在开始,要么你就和我一起学这门强大、灵活的Powershell语言,或者你可以自学。举一个简单例子,通过Powershell你可以创建新的对象,比如Directoryservices.directoryentry或者简单点的,system.datetime. 请注意这些都是拜.Net framework所赐,我们才可以创建这些对象

Windows Powershell总结
Powershell是门新的用户友好的语言,我们可以用来管理Windows或者Exchange服务器。在Powershell的后续版本中,查询WMI对象将变得更加容易。总而言之,Powershell将会成为微软的标准编程语言,同时通过Powershell的学习,你将更加容易的去配置Exchange服务器,AD, Windows Server2008等。