﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-李亚@中国-随笔分类-PowerShell</title><link>http://www.cppblog.com/lilac/category/5989.html</link><description>做.成为.拥有.</description><language>zh-cn</language><lastBuildDate>Sat, 24 May 2008 20:36:33 GMT</lastBuildDate><pubDate>Sat, 24 May 2008 20:36:33 GMT</pubDate><ttl>60</ttl><item><title>PowerShell入门指南  </title><link>http://www.cppblog.com/lilac/archive/2008/01/12/41066.html</link><dc:creator>李亚</dc:creator><author>李亚</author><pubDate>Sat, 12 Jan 2008 15:40:00 GMT</pubDate><guid>http://www.cppblog.com/lilac/archive/2008/01/12/41066.html</guid><wfw:comment>http://www.cppblog.com/lilac/comments/41066.html</wfw:comment><comments>http://www.cppblog.com/lilac/archive/2008/01/12/41066.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lilac/comments/commentRss/41066.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lilac/services/trackbacks/41066.html</trackback:ping><description><![CDATA[一，Windows PowerShell设计目标<br><br>&nbsp;&nbsp;&nbsp;&nbsp; 一）Windows PowerShell是特别为系统管理员设计的、全新的Windows命令行shell。<br><br>&nbsp;&nbsp;&nbsp; 二）和大多数接受并返回文本的shell不同，Windows PowerShell建立在.NET公共语言运行时（CLR）和.NET框架之上，它接受并返回.NET对象。<br><br>&nbsp;&nbsp;&nbsp; 三）Windows PowerShell引入了cmdlet的概念，这是内建在shell中的一个简单、单一功能的命令行工具。<br><br>&nbsp;&nbsp;&nbsp; 四）Windows PowerShell除了和大多数shell一样提供了对文件系统的访问外，还提供了对注册表、数字签名证书存储等其他数据存储的访问<br><br>二，Windows PowerShell简介<br><br>&nbsp;&nbsp;&nbsp; 一）Windows PowerShell不处理文本，它处理基于.NET平台的对象。<br><br>&nbsp;&nbsp;&nbsp; 二）Windows PowerShell提供了一大套具有一致接口的内建命令<br><br>&nbsp;&nbsp;&nbsp; 三）所有的shell命令使用同样的命令parser。<br><br>&nbsp;&nbsp;&nbsp; 四）可以同时使用传统的Windows工具<br><br>三，Windows PowerShell Cmdlets<br><br>&nbsp;&nbsp;&nbsp; 一）通过命名格式来识别cmdlets：动宾结构——动词+分隔符&#8220;-&#8221;+名词<br><br>&nbsp;&nbsp;&nbsp; 二）如何获得cmdlets的相关帮助：<span style="COLOR: rgb(51,102,255)">get-help &lt;cmdlet-name&gt; -detailed</span>；该命令显示以下内容：cmdlet描述，命令语法，参数描述，cmdlet用法举例<br><br>四，为何需要一种新的脚本语言<br><br>&nbsp;&nbsp;&nbsp; 一）Windows PowerShell需要一种语言来管理.NET对象<br><br>&nbsp;&nbsp;&nbsp; 二）该语言需要为使用cmdlet提供一致的环境<br><br>&nbsp;&nbsp;&nbsp; 三）该语言需要支持复杂任务，而不是使简单任务复杂化<br><br>&nbsp;&nbsp;&nbsp; 四）该语言需要和用于.NET编程的高级语言——如C#——一致。<br><br>五，处理对象<br><br>&nbsp;&nbsp;&nbsp; 一）当你在Windows PowerShell中工作时，你在和.NET对象打交道<br><br>&nbsp;&nbsp;&nbsp; 二）<span style="COLOR: rgb(0,0,255)">get-service | get-member</span>：把get-service命令中获取的对象发送给get-member命令，get-member显示service对象的相关信息，如对象的TypeName以及对象的属性和方法列表<br><br>&nbsp;&nbsp;&nbsp; 三）有关对象的类的信息，复制并粘贴TypeName到MSDN<br><br>&nbsp;&nbsp;&nbsp; 四）要查找特定对象——如schedule——的所有属性值：get-service schedule | format-list -properti *<br><br>六，对象管道<br><br>&nbsp;&nbsp;&nbsp; 一）Windows PowerShell提供了一个新的、基于对象的接口模型——而不是基于文本。例如：<span style="COLOR: rgb(0,0,255)">ipconfig | findstr "IP Address"<br><br><span style="COLOR: rgb(0,0,0)">七，对脚本的支持<br><br>&nbsp;&nbsp;&nbsp; 一）Windows PowerShell完全支持脚本，完全支持脚本。<br><br>&nbsp;&nbsp;&nbsp; 二）Windows PowerShell脚本后缀为ps1，该后缀是可选项<br><br>&nbsp;&nbsp;&nbsp; 三）必须指明脚本文件所在的完整路径，即使脚本位于当前目录<br><br>&nbsp;&nbsp;&nbsp; 四）Windows PowerShell的安全策略——称为执行策略（execution policy）——让你决定脚本是否可以运行、是否必须包含一个数字签名<br><br>&nbsp;&nbsp;&nbsp; 五）Windows PowerShell中没有任何执行策略允许通过双击图标来运行脚本，更多信息：<span style="COLOR: rgb(0,0,255)">get-help about_signing<br><font color=#000000>八，Windows PowerShell常用命令举例<br><br>&nbsp;&nbsp;&nbsp; 1. get-help/help/man<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help get-command<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help about_signing<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help get-command -detailed<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help get-command -full<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help get-command -examples<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help get-command -parameter totalcount<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help get-command -parameter *<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; man get-command<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; help get-command<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help get-*<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help about_wildcard<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help about_*<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help -name get-alias<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help get-alias<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-help about_commonparameters<br><br>&nbsp;&nbsp;&nbsp; 2. get-command<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-command *.exe<br><br>&nbsp;&nbsp;&nbsp; 3. get-process<br><br>&nbsp;&nbsp;&nbsp; 4. get-service<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-service | get-member<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-service | get-member -membertype *property<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (get-service alerter).canpauseandcontinue<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-service alerter | format-list -property name, canpauseandcontinue<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-service alerter | format-list -property *<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-service | format-table -property name, canpauseandcontinue<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (get-service schedule).stop()<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; 5. get-eventlog<br><br>&nbsp;&nbsp;&nbsp; 6. get-date<br><br>&nbsp;&nbsp;&nbsp; 7. get-alias<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-alias | where-object {$_.definition -eq "set-location"}<br><br>&nbsp;&nbsp;&nbsp; 8. get-wmiobject：绝对有用，因为它让你察看和更改远程计算机的组件<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-wmiobject win32_bios -computername server01<br><br>&nbsp;&nbsp;&nbsp; 9. get-member<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-service | get-member<br><br>&nbsp;&nbsp;&nbsp; 10. format-table<br><br>&nbsp;&nbsp;&nbsp; 11. format-list<br><br>&nbsp;&nbsp;&nbsp; 12. format-wide<br><br>&nbsp;&nbsp;&nbsp; 13. format-custom<br><br>&nbsp;&nbsp;&nbsp; 14. set-location<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set-location alias:<br><br>&nbsp;&nbsp;&nbsp; 15. get-childitem<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get-childitem alias:<br><br>&nbsp;&nbsp;&nbsp; 16. set-alias<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set-alias gh get-help<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set-alias np c:\windows\notepad.exe<br><br>&nbsp;&nbsp;&nbsp; 17. remove-item<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; remove-item alias:np<br><br>&nbsp;&nbsp;&nbsp; 18. function<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; function bi {notepad c:\boot.ini}<br><br>&nbsp;&nbsp;&nbsp; 19. get-psdrive<br><br>&nbsp;&nbsp;&nbsp; 20. new-psdrive<br><br>&nbsp;&nbsp;&nbsp; 21. test-path</font><br></span></span></span>
<img src ="http://www.cppblog.com/lilac/aggbug/41066.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lilac/" target="_blank">李亚</a> 2008-01-12 23:40 <a href="http://www.cppblog.com/lilac/archive/2008/01/12/41066.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PowerShell简介</title><link>http://www.cppblog.com/lilac/archive/2008/01/12/41064.html</link><dc:creator>李亚</dc:creator><author>李亚</author><pubDate>Sat, 12 Jan 2008 15:37:00 GMT</pubDate><guid>http://www.cppblog.com/lilac/archive/2008/01/12/41064.html</guid><wfw:comment>http://www.cppblog.com/lilac/comments/41064.html</wfw:comment><comments>http://www.cppblog.com/lilac/archive/2008/01/12/41064.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lilac/comments/commentRss/41064.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lilac/services/trackbacks/41064.html</trackback:ping><description><![CDATA[<p>即开发代号为<a href="http://baike.baidu.com/view/58514.htm" target=_blank><u><font color=#0000ff>Monad</font></u></a>的命令行外壳和脚本系统管理工具。 <br><br>PowerShell是微软公司于2006年第四季度正式发布的. 它的出现标志着, 微软公司向服务器领域迈出了重要的一步, 拉近了与Unix, Linux等操作系统的距离. PowerShell的前身命名为Monad, 在2006年4月25日正式发布beta版时更名为PowerShell. <br><br>PowerShell是一款基于对象的shell, 建立在.Net框架之上, 目前支持.Net Framework 2.0. 能够运行在Windows XP SP2, Windows Vista, Windows 2003操作系统上. 能够同时支持WMI, COM, ADO.NET, ADSI等已有的Windows管理模型.<br><br>根据微软公司的计划, 2009年将会实现所有微软公司的GUI管理工具通过PowerShell作为中间层对服务程序进行管理, 现阶段例如Exchange 2007等已经支持PowerShell的管理. 可以预期, 使用PowerShell管理Windows服务器指日可待.<br></p>
<img src ="http://www.cppblog.com/lilac/aggbug/41064.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lilac/" target="_blank">李亚</a> 2008-01-12 23:37 <a href="http://www.cppblog.com/lilac/archive/2008/01/12/41064.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>