1. PoweShell -- 什么是PowerShell,get_ruuningdir

1. What is Windows PowerShell

  • Windows PowerShell is a new Windows command-line shell designed especially for system administrators. The Windows PowerShell includes an interactive prompt and a scripting environment that can be used independently or in combination.


  • Unlike most shells, which accept and return text, Windows PowerShell is built on top of the .NET Framework common language runtime (CLR) and the .NET Framework, and accepts and returns .NET Framework objects


  • 中文解释

    PowerShell是一个由微软的提供的全新shell程序,使用了全新的命令提示和脚本环境。使用PowerShell会给系统管理员带来什么?学习PowerShell的好处又是什么?如果你已经有了管理并使用VBScript的经验,相信你已经知道答案了。Active Directory域现在已经变得更加庞大和复杂,对于那些被束缚在GUI和Microsoft管理控制台上的管理员们,PowerShell将使他们获得自由!

    不知道各位有没有登陆到每个server、client修改注册表的体验,或者批量处理文件,批量配置……当你遇到这些问题,会怎么做?手动配置?还是运行一个脚本来解决问题?经常使用VBScript的人当然会选择后者,但是他们会问,为什么我还要学习PowerShell?

    答案很简单:PowerShell使用了面向对象方法,基于.Net,这是VBScript所不能提供或者支持的。


    PowerShell是基于对象而不是基于文本

    如果你已经熟练使用cmd.exe和批处理脚本,那么我认为你需要一些时间进行概念性的转变。PowerShell与那些使用VBScript和其他编程语言的概念有着根本性的区别,传统的命令提示符的输出是基于文本的,而在PowerShell中则不会。它看起来像文本,但它实际上是一个对象。这就是为什么我说PowerShell强大的原因,因为一个PowerShell命令(对象)的输出可以输入到另一个命令中去,而无需加入额外的代码。而在传统的脚本语言中,如果你想让一个命令传递到另一个命令,就需要额外的代码来把需要传递的命令转换成第二个命令可以理解的数据与格式。另外牵扯到一个问题,什么是对象?这个听起来很熟悉,“在Active Directory域内的一切都是对象。”例如我们的服务器、电脑、打印机、安全组、组策略、用户等,有了PowerShell,我们就可以很轻松的与这些对象进行互动:查看信息,以及创建、修改或删除。


    对PowerShell命令进行自定义

    PowerShell命令被称为的cmdlet。PowerShell自带有超过100个cmdlet。PowerShell的开发团队利用他们无穷的想象力为这些cmdlet创造了别名,使我们能够尽可能的利用我们已经习惯的传统的命令来操作,如:dir、 cd、 del、 copy等等。即使是UNIX的上的老手,也可以轻松使用诸如ls、man等命令。为了最大程度上迎合用户习惯,简化操作,PowerShell允许用户为cmdlet创建自己定义的别名,甚至创建自己的cmdlet。


    PowerShell是一个命令行解释器和脚本环境

    概括地讲就是PowerShell具有两全其美。DOS仅仅是一个命令行解释器,输入命令,然后得到输出,当然,也可以使用批处理文件,但批处理文件从本质上只是对输入的命令这一操作的简化。在VBScript中,可以利用WSH(Windows脚本主机),但是并不能在命令提示符状态下输入VBScript代码。PowerShell与它们都不同却又相似,它不仅可以输入命令,而且可以在命令行构建脚本。PowerShell的一个强大功能是能够在命令提示符下建立和测试代码。


2. PowerShell Version


  • Version 1.0

Version 1.0 was released in 2006 for Windows XP SP2/SP3, Windows Server 2003, and Windows Vista. For Windows Server 2008, it is included as an optional feature.

  • Version 2.0

Version 2.0 is integrated with Windows 7 and Windows Server 2008 R2 and is released for Windows XP with Service Pack 3, Windows Server 2003 with Service Pack 2 and Windows Vista with Service Pack 1.

  • Version 3.0

A new community technology preview 2 (CTP 2) version of Windows Management Framework 3.0 was released by Microsoft in December, 2011


3. Scripts Tools:

  • Windows PowerShell ISE:

    操作步骤:

    Windows PowerShell 集成脚本环境 (ISE) 是 Windows PowerShell 的主机应用程序。启动 Windows PowerShell ISE  在 Windows PowerShell 控制台 Cmd.exe 或“运行”框中,键入 powershell_ise.exe。

  • PowerShell Script Editor:  (PowerGUI.2.3.0.1503)

    Download from here :

    http://powergui.org/index.jspa

    http://winsystem.ctocio.com.cn/358/9167858.shtml

    http://www.xdowns.com/soft/6/56/2013/Soft_105129.html

    PowerGUI, a graphical user interface and script editor for Microsoft Windows PowerShell!


$runningdir = Split-Path -parent $MyInvocation.MyCommand.Definition | select -first 1

 


4. 参考文献:

https://msdn.microsoft.com/en-us/library/ee809360.aspx

http://marui.blog.51cto.com/1034148/289823

本文出自 “Ricky's Blog” 博客,转载请与作者联系!

你可能感兴趣的:(windows,powershell)