PowerShell入门指南

一,Windows PowerShell设计目标

     一)Windows PowerShell是特别为系统管理员设计的、全新的Windows命令行shell。

    二)和大多数接受并返回文本的shell不同,Windows PowerShell建立在.NET公共语言运行时(CLR)和.NET框架之上,它接受并返回.NET对象。

    三)Windows PowerShell引入了cmdlet的概念,这是内建在shell中的一个简单、单一功能的命令行工具。

    四)Windows PowerShell除了和大多数shell一样提供了对文件系统的访问外,还提供了对注册表、数字签名证书存储等其他数据存储的访问

二,Windows PowerShell简介

    一)Windows PowerShell不处理文本,它处理基于.NET平台的对象。

    二)Windows PowerShell提供了一大套具有一致接口的内建命令

    三)所有的shell命令使用同样的命令parser。

    四)可以同时使用传统的Windows工具

三,Windows PowerShell Cmdlets

    一)通过命名格式来识别cmdlets:动宾结构——动词+分隔符“-”+名词

    二)如何获得cmdlets的相关帮助:get-help <cmdlet-name> -detailed;该命令显示以下内容:cmdlet描述,命令语法,参数描述,cmdlet用法举例

四,为何需要一种新的脚本语言

    一)Windows PowerShell需要一种语言来管理.NET对象

    二)该语言需要为使用cmdlet提供一致的环境

    三)该语言需要支持复杂任务,而不是使简单任务复杂化

    四)该语言需要和用于.NET编程的高级语言——如C#——一致。

五,处理对象

    一)当你在Windows PowerShell中工作时,你在和.NET对象打交道

    二)get-service | get-member:把get-service命令中获取的对象发送给get-member命令,get-member显示service对象的相关信息,如对象的TypeName以及对象的属性和方法列表

    三)有关对象的类的信息,复制并粘贴TypeName到MSDN

    四)要查找特定对象——如schedule——的所有属性值:get-service schedule | format-list -properti *

六,对象管道

    一)Windows PowerShell提供了一个新的、基于对象的接口模型——而不是基于文本。例如:ipconfig | findstr "IP Address"

七,对脚本的支持

    一)Windows PowerShell完全支持脚本,完全支持脚本。

    二)Windows PowerShell脚本后缀为ps1,该后缀是可选项

    三)必须指明脚本文件所在的完整路径,即使脚本位于当前目录

    四)Windows PowerShell的安全策略——称为执行策略(execution policy)——让你决定脚本是否可以运行、是否必须包含一个数字签名

    五)Windows PowerShell中没有任何执行策略允许通过双击图标来运行脚本,更多信息:get-help about_signing
八,Windows PowerShell常用命令举例

    1. get-help/help/man

        get-help get-command

        get-help about_signing

        get-help get-command -detailed

        get-help get-command -full

        get-help get-command -examples

        get-help get-command -parameter totalcount

        get-help get-command -parameter *

        man get-command

        help get-command

        get-help get-*

        get-help about_wildcard

        get-help about_*

        get-help -name get-alias

        get-help get-alias

        get-help about_commonparameters

    2. get-command

        get-command *.exe

    3. get-process

    4. get-service

        get-service | get-member

        get-service | get-member -membertype *property

        (get-service alerter).canpauseandcontinue

        get-service alerter | format-list -property name, canpauseandcontinue

        get-service alerter | format-list -property *

        get-service | format-table -property name, canpauseandcontinue

        (get-service schedule).stop()

       

    5. get-eventlog

    6. get-date

    7. get-alias

        get-alias | where-object {$_.definition -eq "set-location"}

    8. get-wmiobject:绝对有用,因为它让你察看和更改远程计算机的组件

        get-wmiobject win32_bios -computername server01

    9. get-member

        get-service | get-member

    10. format-table

    11. format-list

    12. format-wide

    13. format-custom

    14. set-location

        set-location alias:

    15. get-childitem

        get-childitem alias:

    16. set-alias

        set-alias gh get-help

        set-alias np c:\windows\notepad.exe

    17. remove-item

        remove-item alias:np

    18. function
       
        function bi {notepad c:\boot.ini}

    19. get-psdrive

    20. new-psdrive

    21. test-path

posted on 2008-01-12 23:40 李亚 阅读(796) 评论(0)  编辑 收藏 引用 所属分类: PowerShell


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

公告

这世界并不会在意你的自尊,这世界指望你在自我感觉良好之前先要有所成就!

常用链接

留言簿(3)

随笔分类(32)

随笔档案(32)

相册

最新随笔

搜索

最新评论

阅读排行榜

评论排行榜