{"id":33394,"date":"2011-01-18T09:26:00","date_gmt":"2011-01-18T08:26:00","guid":{"rendered":"http:\/\/txj.lzuer.com\/?p=33394"},"modified":"2024-11-06T11:19:54","modified_gmt":"2024-11-06T03:19:54","slug":"powershell2-0%e4%b9%8bwindows%e6%8e%92%e9%94%99%e4%b8%89-%e6%a3%80%e6%9f%a5%e8%ae%be%e5%a4%87%e9%a9%b1%e5%8a%a8","status":"publish","type":"post","link":"http:\/\/www.fuhaijun.com\/?p=33394","title":{"rendered":"PowerShell2.0\u4e4bWindows\u6392\u9519(\u4e09) \u68c0\u67e5\u8bbe\u5907\u9a71\u52a8"},"content":{"rendered":"<p>&#160;&#160;&#160;&#160;&#160;&#160; \u8bbe\u5907\u9a71\u52a8\u548c\u670d\u52a1\u529f\u80fd\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u81ea\u52a8\u8fd0\u884c\u5e76\u63d0\u4f9b\u4e00\u5b9a\u529f\u80fd\u3002\u53ea\u662f\u8bbe\u5907\u9a71\u52a8\u66f4\u63a5\u8fd1\u4e8e\u786c\u4ef6\u5e95\u5c42\uff0c\u5e76\u4e0d\u50cf\u670d\u52a1\u90a3\u6837\u5bb9\u6613\u53d1\u73b0\u548c\u68c0\u67e5\u3002\u8bbe\u5907\u9a71\u52a8\u4e00\u65e6\u51fa\u73b0\u95ee\u9898\uff0c\u5f80\u5f80\u4f34\u968f\u67d0\u79cd\u8bbe\u5907\u529f\u80fd\u7684\u5931\u7075\uff0c\u6240\u4ee5\u5bf9\u4e8e\u7cfb\u7edf\u7ba1\u7406\u5458\u6765\u8bf4\u68c0\u67e5\u8bbe\u5907\u9a71\u52a8\u4e5f\u5f88\u91cd\u8981\u3002<\/p>\n<p>\u521b\u5efa\u7528\u4e8e\u68c0\u67e5\u786c\u4ef6\u9a71\u52a8\u7684\u811a\u672cCheckDeviceDrivers.ps1\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>param($computer=&quot;localhost&quot;, $a=&quot;h&quot;, [switch]$help)<\/p>\n<p>function funHelp()<\/p>\n<p>{<\/p>\n<p>$helpText=@&quot;<\/p>\n<p>DESCRIPTION:<\/p>\n<p>NAME: CheckDeviceDrivers.ps1 <\/p>\n<p>Displays a listing of system drivers that are set to <\/p>\n<p>automatic, manual, boot, system or all drivers<\/p>\n<p>PARAMETERS: <\/p>\n<p>-computer The name of the computer<\/p>\n<p>-a(ction) &lt; a(ll), r(unning), s(topped), b(oot),m(anual), au(to), sy(stem), h(elp) &gt; <\/p>\n<p>-help prints help file<\/p>\n<p>SYNTAX:<\/p>\n<p>CheckDeviceDrivers.ps1 -computer WebServer -a b<\/p>\n<p>Displays a listing of all device drivers that are set to start on boot on a computer named <a name=\"OLE_LINK3\"><\/a><a name=\"OLE_LINK2\">WebServer<\/a><\/p>\n<p>CheckDeviceDrivers.ps1 -a auto<\/p>\n<p>Displays a listing of all device drivers on local computer set to start up automatically<\/p>\n<p>CheckDeviceDrivers.ps1 -computer WebServer -a m<\/p>\n<p>Displays a listing of all device drivers<\/p>\n<p>that are set to start manually on a computer named WebServer<\/p>\n<p>CheckDeviceDrivers.ps1 -help ?<\/p>\n<p>Displays the help topic for the script<\/p>\n<p>&quot;@<\/p>\n<p>$helpText<\/p>\n<p>exit<\/p>\n<p>}<\/p>\n<p>if($help){ &quot;Obtaining help &#8230;&quot; ; funhelp }<\/p>\n<p>switch($a)<\/p>\n<p>{ <\/p>\n<p>&quot;a&quot; { <\/p>\n<p>&quot;Retrieving all device drivers&quot; <\/p>\n<p>$filter = &quot;started = &#8216;true&#8217; or started = &#8216;false&#8217;&quot;<\/p>\n<p>}<\/p>\n<p>&quot;r&quot; { <\/p>\n<p>&quot;Retrieving all running device drivers&quot;<\/p>\n<p>$filter = &quot;started = &#8216;true&#8217;&quot;<\/p>\n<p>}<\/p>\n<p>&quot;s&quot; {<\/p>\n<p>&quot;Retrieving all stopped device drivers&quot;<\/p>\n<p>$filter = &quot;started = &#8216;false&#8217;&quot;<\/p>\n<p>}<\/p>\n<p>&quot;b&quot; {<\/p>\n<p>&quot;Retrieving boot device drivers&quot;<\/p>\n<p>$filter = &quot;startmode = &#8216;boot&#8217;&quot;<\/p>\n<p>}<\/p>\n<p>&quot;m&quot; {<\/p>\n<p>&quot;Retrieving manual device drivers&quot;<\/p>\n<p>$filter = &quot;startmode = &#8216;manual&#8217;&quot;<\/p>\n<p>}<\/p>\n<p>&quot;au&quot; {<\/p>\n<p>&quot;Retrieving auto device drivers&quot;<\/p>\n<p>$filter = &quot;startmode = &#8216;auto&#8217;&quot;<\/p>\n<p>}<\/p>\n<p>&quot;sy&quot; {<\/p>\n<p>&quot;Retrieving system device drivers&quot;<\/p>\n<p>$filter = &quot;startmode = &#8216;system&#8217;&quot;<\/p>\n<p>}<\/p>\n<p>&quot;h&quot; { <\/p>\n<p>&quot;You need to specify an action. The -a parameter is required&quot; <\/p>\n<p>&quot;Try this: &quot; + $MyInvocation.MyCommand.Definition + &quot; -h&quot;<\/p>\n<p>exit<\/p>\n<p>}<\/p>\n<p>DEFAULT <\/p>\n<p>{ <\/p>\n<p>&quot;You need to specify an action. The -a parameter is required&quot; <\/p>\n<p>&quot;Try this: &quot; + $MyInvocation.MyCommand.Definition + &quot; -h&quot;<\/p>\n<p>exit<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>$wmi = Get-WmiObject -Class win32_systemdriver `<\/p>\n<p>-computername $computer -filter $filter<\/p>\n<p>format-table -InputObject $wmi -property `<\/p>\n<p>displayname, pathname, name -autosize<\/p>\n<p>\u8be5\u811a\u672c\u901a\u8fc7param\u8bed\u53e5\u5b9a\u4e49\u4e86-computer\uff0c-a\u548c-help\u53c2\u6570\u3002\u5176\u4e2d-a\u6307\u5b9a\u8981\u6267\u884c\u7684\u64cd\u4f5c\uff0c\u9ed8\u8ba4\u4e3ah\uff0c\u5373\u663e\u793a\u5e2e\u52a9\u4fe1\u606f\u3002<\/p>\n<p>\u8be5\u811a\u672c\u901a\u8fc7switch\u8bed\u53e5\u5b9a\u4e49\u4e86\u4e3b\u8981\u64cd\u4f5c\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u5141\u8bb8\u7528\u6237\u6307\u5b9a\u4e00\u7cfb\u5217\u4e0d\u540c\u4e14\u76f8\u5173\u7684\u8bbe\u5907\u9a71\u52a8\u3002switch\u8bed\u53e5\u663e\u793a\u4e00\u6761\u5f53\u524d\u64cd\u4f5c\u72b6\u6001\u4fe1\u606f\uff0c\u7136\u540e\u901a\u8fc7\u8bbe\u5b9a$filter\u53d8\u91cf\u503c\uff0c\u4e3aGet-WmiObject cmdlet\u521b\u5efafilter\uff08\u7b5b\u9009\uff09\u53c2\u6570\u3002<\/p>\n<p>\u8be5\u811a\u672c\u4e2d\u8c03\u7528\u4e86\u53ef\u4ee5\u5728\u591a\u4e2aswitch\u8bed\u53e5\u4e2d\u4f7f\u7528\u7684$MyInvocation.MyCommand.Definition\u547d\u4ee4\uff0c\u7528\u4e8e\u5728\u8f93\u51fa\u4fe1\u606f\u4e2d\u5f15\u7528\u6b63\u5728\u8fd0\u884c\u7684\u811a\u672c\u3002\u5176\u6838\u5fc3\u529f\u80fd\u662f\u901a\u8fc7Get-WmiObject cmdlet\u67e5\u8be2Win32_SystemDriver WMI\u7c7b\uff0c\u901a\u8fc7\u6307\u5b9a$computer\u53d8\u91cf\u67e5\u8be2\u6307\u5b9a\u7684\u8ba1\u7b97\u673a\uff0c\u7136\u540e\u53ef\u4ee5\u4f7f\u7528\u901a\u8fc7switch\u8bed\u53e5\u521b\u5efa\u7684\u7b5b\u9009\u5668\u5e76\u5c06\u67e5\u8be2\u7ed3\u679c\u4fdd\u5b58\u5728$wmi\u53d8\u91cf\u4e2d\u3002\u4e3a\u4e86\u5728\u8f93\u51fa\u65f6\u683c\u5f0f\u5316\u8be5\u53d8\u91cf\uff0c\u4f7f\u7528\u4e86\u5e26-InputObject\u53c2\u6570\u7684Format-Table cmdlet\u3002\u540c\u65f6\u4fdd\u5b58$wmi\u53d8\u91cf\u4e2d\u7684management\u5bf9\u8c61\uff0c\u6267\u884c\u7ed3\u679c\u5982\u56fe1\u6240\u793a\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image36.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px\" height=\"435\" alt=\"image\" src=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image_thumb36.png\" width=\"672\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe1 \u6267\u884c\u7ed3\u679c<\/p>\n<p>&#160;<\/p>\n<p>\u4f5c\u8005: \u4ed8\u6d77\u519b    <br \/>\u7248\u6743\uff1a\u672c\u6587\u7248\u6743\u5f52\u4f5c\u8005\u6240\u6709     <br \/>\u8f6c\u8f7d\uff1a\u6b22\u8fce\u8f6c\u8f7d\uff0c\u4e3a\u4e86\u4fdd\u5b58\u4f5c\u8005\u7684\u521b\u4f5c\u70ed\u60c5\uff0c\u8bf7\u6309\u8981\u6c42\u3010\u8f6c\u8f7d\u3011\uff0c\u8c22\u8c22     <br \/>\u8981\u6c42\uff1a\u672a\u7ecf\u4f5c\u8005\u540c\u610f\uff0c\u5fc5\u987b\u4fdd\u7559\u6b64\u6bb5\u58f0\u660e\uff1b\u5fc5\u987b\u5728\u6587\u7ae0\u4e2d\u7ed9\u51fa\u539f\u6587\u8fde\u63a5\uff1b\u5426\u5219\u5fc5\u7a76\u6cd5\u5f8b\u8d23\u4efb     <br \/>\u4e2a\u4eba\u7f51\u7ad9: <a href=\"http:\/\/txj.lzuer.com\/\">http:\/\/txj.lzuer.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#160;&#160;&#160;&#160;&#160;&#160; \u8bbe\u5907\u9a71\u52a8\u548c\u670d\u52a1\u529f\u80fd\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u81ea\u52a8\u8fd0\u884c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,1],"tags":[],"class_list":["post-33394","post","type-post","status-publish","format-standard","hentry","category-powershell","category-default"],"_links":{"self":[{"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33394"}],"collection":[{"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33394"}],"version-history":[{"count":1,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33394\/revisions"}],"predecessor-version":[{"id":33754,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33394\/revisions\/33754"}],"wp:attachment":[{"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33394"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}