{"id":33351,"date":"2011-01-10T18:40:17","date_gmt":"2011-01-10T17:40:17","guid":{"rendered":"https:\/\/www.fuhaijun.com\/?p=33351"},"modified":"2024-11-06T11:19:54","modified_gmt":"2024-11-06T03:19:54","slug":"powershell2-0%e4%b9%8b%e6%a1%8c%e9%9d%a2%e8%ae%a1%e7%ae%97%e6%9c%ba%e7%bb%b4%e6%8a%a4%e4%ba%94%e7%ae%a1%e7%90%86%e6%a1%8c%e9%9d%a2%e7%94%b5%e6%ba%90%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"http:\/\/www.fuhaijun.com\/?p=33351","title":{"rendered":"PowerShell2.0\u4e4b\u684c\u9762\u8ba1\u7b97\u673a\u7ef4\u62a4(\u4e94)\u7ba1\u7406\u684c\u9762\u7535\u6e90\u8bbe\u7f6e"},"content":{"rendered":"<p>\u4fbf\u643a\u5f0f\u8ba1\u7b97\u673a\u7684\u4f9b\u7535\u662f\u4e2a\u5f88\u91cd\u8981\u7684\u95ee\u9898\uff0c\u56e0\u5176\u76f4\u63a5\u5173\u7cfb\u5230\u4fbf\u643a\u5f0f\u8bbe\u5907\u7684\u53ef\u79fb\u52a8\u6027\u3002Windows\u6709\u591a\u4e2a\u7ec4\u4ef6\u4e0e\u7535\u6e90\u7ba1\u7406\u7684\u914d\u7f6e\u7b56\u7565\u76f8\u5173\uff0c\u5728Windows Server 2008\u4e2d\u7684\u7535\u6e90\u7b56\u7565\u8bbe\u7f6e\u754c\u9762\u5982\u56fe1\u6240\u793a\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image19.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=\"429\" alt=\"image\" src=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image_thumb19.png\" width=\"644\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe1 Windows Server 2008\u4e2d\u7684\u7535\u6e90\u7b56\u7565\u8bbe\u7f6e\u754c\u9762<\/p>\n<p>\u521b\u5efa\u540d\u4e3a\u201cReportPowerConfig.ps1\u201d\u7684\u811a\u672c\uff0c\u6839\u636e\u7528\u6237\u63d0\u4f9b\u7684\u5982\u4e0b\u53c2\u6570\u63d0\u4f9b\u76f8\u5e94\u7684\u7535\u6e90\u914d\u7f6e\u4fe1\u606f\u3002<\/p>\n<ol>\n<li>a\uff1a\u5f53\u524d\u4e3b\u673a\u4e2d\u6d3b\u52a8\u7684\u7535\u6e90\u8bbe\u7f6e\u3002 <\/li>\n<li>l\uff1a\u5f53\u524d\u4e3b\u673a\u4e2d\u7684\u6240\u6709\u7535\u6e90\u914d\u7f6e\u3002 <\/li>\n<li>q\uff1a\u5f53\u524d\u4e3b\u673a\u4e2d\u7684\u6240\u6709\u53ef\u7528\u4f11\u7720\u72b6\u6001\u3002 <\/li>\n<li>w\uff1a\u5f53\u524d\u4e3b\u673a\u4e2d\u7684\u4e0a\u6b21\u5524\u9192\u4e8b\u4ef6\u3002 <\/li>\n<li>d\uff1a\u5f53\u524d\u4e3b\u673a\u4e2d\u7684\u6240\u6709\u7684\u8bbe\u5907\u3002 <\/li>\n<li>dv\uff1a\u5f53\u524d\u4e3b\u673a\u4e2d\u7684\u6240\u6709\u8bbe\u5907\u7684\u8be6\u7ec6\u4fe1\u606f\u3002 <\/li>\n<li>dwa\uff1a\u5f53\u524d\u4e3b\u673a\u4e2d\u5df2\u914d\u7f6e\u4e14\u53ef\u5524\u9192\u5f53\u524d\u4e3b\u673a\u7684\u8bbe\u5907\u3002 <\/li>\n<li>dwp\uff1a\u5f53\u524d\u4e3b\u673a\u4e2d\u6240\u6709\u914d\u7f6e\u4e3a\u53ef\u4ece\u7761\u7720\u4e2d\u5524\u9192\u8ba1\u7b97\u673a\u7684\u8bbe\u5907\u3002 <\/li>\n<\/ol>\n<p>\u8be5\u811a\u672c\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>param($a=&quot;a&quot;, $help)<\/p>\n<p>function funline ($strIN)<\/p>\n<p>{<\/p>\n<p>$num = $strIN.length<\/p>\n<p>for($i=1 ; $i -le $num ; $i++)<\/p>\n<p>{ $funline += &quot;=&quot; }<\/p>\n<p>Write-Host -ForegroundColor yellow `n$strIN <\/p>\n<p>Write-Host -ForegroundColor darkYellow $funline<\/p>\n<p>}<\/p>\n<p>function funHelp()<\/p>\n<p>{<\/p>\n<p>$helpText=@&quot;<\/p>\n<p>DESCRIPTION:<\/p>\n<p>NAME: ReportPowerConfig.ps1 <\/p>\n<p>Prints power config on a local machine.<\/p>\n<p>PARAMETERS: <\/p>\n<p>-a(ction) action to perform &lt;a(ctive scheme), l(ist), <\/p>\n<p>q(uery), d(evice), dv(evice verbose),<\/p>\n<p>dwa(evice wake armed), dwp(evice wake programable)&gt;<\/p>\n<p>-help prints help file<\/p>\n<p>SYNTAX:<\/p>\n<p>ReportPowerConfig.ps1 <\/p>\n<p>Lists power configuration on local computer<\/p>\n<p>ReportPowerConfig.ps1 -a a<\/p>\n<p>Lists active power configuration on local computer<\/p>\n<p>ReportPowerConfig.ps1 -a l<\/p>\n<p>Lists all power configuration on local computer<\/p>\n<p>ReportPowerConfig.ps1 -a q<\/p>\n<p>Lists all available sleep states on local computer<\/p>\n<p>ReportPowerConfig.ps1 -a w<\/p>\n<p>Lists last wake event on local computer<\/p>\n<p>ReportPowerConfig.ps1 -a d<\/p>\n<p>Lists all devices on local computer<\/p>\n<p>ReportPowerConfig.ps1 -a dv<\/p>\n<p>Lists all devices on local computer &#8211; verbose<\/p>\n<p>ReportPowerConfig.ps1 -a dwa<\/p>\n<p>Lists devices configured to wake the local computer<\/p>\n<p>ReportPowerConfig.ps1 -a dwp<\/p>\n<p>Lists devices that are user confiurable to wake the<\/p>\n<p>computer from sleep on local computer<\/p>\n<p>ReportPowerConfig.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){funline(&quot;Obtaining help &#8230;&quot;) ; funhelp }<\/p>\n<p>$computer = (New-Object -ComObject WScript.Network).computername<\/p>\n<p>funline(&quot;Power configuration on: $($computer)&quot;)<\/p>\n<p>switch($a)<\/p>\n<p>{<\/p>\n<p>&quot;a&quot; { POWERCFG -GETACTIVESCHEME ; &quot;`r&quot;}<\/p>\n<p>&quot;l&quot; { powercfg -LIST }<\/p>\n<p>&quot;q&quot; { powercfg -AVAILABLESLEEPSTATES }<\/p>\n<p>&quot;w&quot; { powercfg -lastwake }<\/p>\n<p>&quot;d&quot; { powercfg -devicequery all_devices }<\/p>\n<p>&quot;dv&quot; { powercfg -devicequery all_devices_verbose }<\/p>\n<p>&quot;dwa&quot; { powercfg -devicequery wake_armed }<\/p>\n<p>&quot;dwp&quot; { powercfg -devicequery wake_programmable }<\/p>\n<p>}<\/p>\n<p>\u5728\u811a\u672c\u4e2d\u9996\u5148\u4f7f\u7528param\u8bed\u53e5\u5b9a\u4e49\u4e86\u4e24\u4e2a\u547d\u4ee4\u884c\u53c2\u6570-a\u548c-help\uff0c-a\u6307\u5b9a\u811a\u672c\u6267\u884c\u7684\u64cd\u4f5c\uff0c\u9ed8\u8ba4\u503c\u4e3aa\uff1b-help\u6307\u5b9a\u663e\u793a\u5e2e\u52a9\u4fe1\u606f\uff0c\u5305\u62ec\u63cf\u8ff0\u3001\u53c2\u6570\u53ca\u8bed\u6cd5\u8303\u4f8b\u3002\u8981\u5f3a\u8c03\u7684\u662f\u8fd9\u4e2a\u811a\u672c\u65e0\u6cd5\u5728\u8fdc\u7a0b\u6267\u884c\u3002<\/p>\n<p>\u83b7\u53d6\u8ba1\u7b97\u673a\u540d\u79f0\u65f6\u53ef\u4ee5\u4f7f\u7528WScript.Network COM\u5bf9\u8c61\uff0c\u5e76\u4f7f\u7528New-Object cmdlet\u521b\u5efa\u8be5\u5bf9\u8c61\uff0c\u7136\u540e\u63d0\u4f9b-comobject\u53c2\u6570\u3002\u9009\u62e9ComputerName\u5c5e\u6027\uff0c\u8ba1\u7b97\u673a\u540d\u81ea\u52a8\u4fdd\u5b58\u5728$computer\u53d8\u91cf\u4e2d\u3002\u8be5\u811a\u672c\u4e2d\u7684\u5927\u90e8\u5206\u7684\u903b\u8f91\u63a7\u5236\u5728switch\u8bed\u53e5\u4e2d\u5b8c\u6210\uff0c\u8fd9\u4e9b\u8bed\u53e5\u901a\u8fc7\u5224\u65ad\u547d\u4ee4\u884c\u4e2d\u7684$a\u53d8\u91cf\u503c\u9009\u62e9\u76f8\u5e94\u7684\u5206\u652f\u3002\u5982\u679c\u503c\u4e3aa\uff0c\u5219\u4f7f\u7528Powercfg\u5de5\u5177\u83b7\u53d6\u5f53\u524d\u7535\u6e90\u8ba1\u5212\u3002\u6267\u884c\u7ed3\u679c\u5982\u56fe2\u548c\u56fe3\u6240\u793a\uff0c\u53ef\u4ee5\u770b\u5230\u5f53\u524d\u8ba1\u7b97\u673a\u53ef\u4ee5\u7531\u7f51\u5361\u8fdc\u7a0b\u5524\u9192\u3002\u9700\u8981\u5f3a\u8c03\u7684\u662f\u7531\u4e8eWindows XP\u548cWindows Server 2008\u7684powercfg\u5de5\u5177\u7684\u5de5\u4f5c\u73af\u5883\u4e0d\u540c\uff0c\u6240\u4ee5\u5c06-a\u53c2\u6570\u7684a\u6216q\u9009\u9879\u4f20\u9012\u7ed9\u811a\u672c\u4f7f\u5c06\u4f1a\u629b\u51fa\u201c\u53c2\u6570\u65e0\u6548\uff0c\u952e\u5165&quot;\/?&quot;\u5f97\u5230\u5e2e\u52a9\u201d\u7684\u63d0\u793a\u4fe1\u606f\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image20.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=\"423\" alt=\"image\" src=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image_thumb20.png\" width=\"644\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe2 \u5217\u51fa\u5f53\u524d\u7cfb\u7edf\u4e2d\u53ef\u7528\u7684\u7535\u6e90\u8ba1\u5212<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image21.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=\"423\" alt=\"image\" src=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image_thumb21.png\" width=\"644\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe3 \u83b7\u53d6\u53ef\u4ece\u7761\u7720\u4e2d\u5524\u9192\u8ba1\u7b97\u673a\u7684\u8bbe\u5907<\/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>\u4fbf\u643a\u5f0f\u8ba1\u7b97\u673a\u7684\u4f9b\u7535\u662f\u4e2a\u5f88\u91cd\u8981\u7684\u95ee\u9898\uff0c\u56e0\u5176\u76f4\u63a5\u5173\u7cfb\u5230\u4fbf\u643a\u5f0f\u8bbe\u5907\u7684\u53ef\u79fb\u52a8\u6027\u3002Windows\u6709\u591a\u4e2a\u7ec4\u4ef6\u4e0e\u7535\u6e90\u7ba1\u7406\u7684\u914d [&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-33351","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\/33351"}],"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=33351"}],"version-history":[{"count":1,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33351\/revisions"}],"predecessor-version":[{"id":33761,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33351\/revisions\/33761"}],"wp:attachment":[{"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33351"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}