{"id":33386,"date":"2011-01-16T16:47:23","date_gmt":"2011-01-16T15:47:23","guid":{"rendered":"http:\/\/txj.lzuer.com\/?p=33386"},"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%80%e5%90%af%e5%8a%a8%e6%95%85%e9%9a%9c%e6%8e%92%e9%94%99","status":"publish","type":"post","link":"http:\/\/www.fuhaijun.com\/?p=33386","title":{"rendered":"PowerShell2.0\u4e4bWindows\u6392\u9519(\u4e00)\u542f\u52a8\u6545\u969c\u6392\u9519"},"content":{"rendered":"<p>\u5982\u679cWindows Vista\u548cWindows Server 2008\u65e0\u6cd5\u6b63\u5e38\u542f\u52a8\uff0c\u5219\u53ef\u4ee5\u68c0\u67e5\u5f15\u5bfc\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u51fa\u73b0\u9519\u8bef\uff1b\u53e6\u5916\u53ef\u4ee5\u68c0\u67e5\u542f\u52a8\u670d\u52a1\u53ca\u5176\u4f9d\u5b58\u6027\u3002Windows\u4e2d\u7684\u4e00\u4e9b\u670d\u52a1\u4f9d\u8d56\u4e8e\u5176\u4ed6\u670d\u52a1\u3001\u7cfb\u7edf\u9a71\u52a8\u7a0b\u5e8f\u548c\u7ec4\u4ef6\u7684\u52a0\u8f7d\u987a\u5e8f\u3002\u5982\u679c\u7cfb\u7edf\u7ec4\u4ef6\u88ab\u505c\u6b62\u6216\u8fd0\u884c\u4e0d\u6b63\u5e38\uff0c\u5219\u4f9d\u8d56\u4e8e\u5b83\u7684\u670d\u52a1\u4f1a\u53d7\u5230\u5f71\u54cd\u3002<\/p>\n<p><strong>\uff081\uff09\u68c0\u67e5\u5f15\u5bfc\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<p>\u68c0\u67e5\u8fd0\u884cWindows Vista\u548cWindows Server 2008\u7684\u8ba1\u7b97\u673a\u5f15\u5bfc\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u53ef\u4ee5\u4e3a\u7528\u6237\u89e3\u51b3\u5f15\u5bfc\u6709\u5173\u7684\u95ee\u9898\uff0c\u63d0\u4f9b\u5f88\u591a\u6709\u4ef7\u503c\u7684\u4fe1\u606f\u3002\u7c7b\u4f3c\u5f15\u5bfc\u5206\u533a\u3001\u5f15\u5bfc\u76ee\u5f55\uff0c\u4ee5\u53caWindows\u76ee\u5f55\u7b49\u4fe1\u606f\u5f80\u5f80\u90fd\u5bf9\u6392\u9664\u6545\u969c\u5f88\u6709\u7528\uff0c\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u901a\u8fc7VBS\u811a\u672c\u83b7\u53d6\u8fd9\u4e9b\u4fe1\u606f\u9700\u8981\u82b1\u8d39\u5f88\u591a\u65f6\u95f4\u3002<\/p>\n<p>\u521b\u5efa\u540d\u4e3a\u201cDisplayBootConfig.ps1\u201d\u811a\u672c\u8bfb\u53d6\u5f15\u5bfc\u914d\u7f6e\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>param($computer=&quot;localhost&quot;, [switch]$help)<\/p>\n<p>function funHelp()<\/p>\n<p>{<\/p>\n<p>$helpText=@&quot;<\/p>\n<p>DESCRIPTION:<\/p>\n<p>NAME: DisplayBootConfig.ps1 <\/p>\n<p>Displays a boot up configuration of a Windows system<\/p>\n<p>PARAMETERS: <\/p>\n<p>-computer The name of the computer<\/p>\n<p>-help prints help file<\/p>\n<p>SYNTAX:<\/p>\n<p>DisplayBootConfig.ps1 -computer WebServer <\/p>\n<p>Displays boot up configuration of a computer named WebServer<\/p>\n<p>DisplayBootConfig.ps1<\/p>\n<p>Displays boot up configuration on local computer <\/p>\n<p>DisplayBootConfig.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>$wmi = Get-WmiObject -Class win32_BootConfiguration `<\/p>\n<p>-computername $computer <\/p>\n<p>format-list -InputObject $wmi [a-z]*<\/p>\n<p>\u8be5\u811a\u672c\u4f7f\u7528param\u8bed\u53e5\u5b9a\u4e49\u4e86$computer\u548c$help\u53d8\u91cf\uff0c\u524d\u8005\u7684\u9ed8\u8ba4\u503c\u4e3alocalhost\u3002\u8bbe\u7f6e-help\u53c2\u6570\u4e3aswitch\uff0c\u5373\u5728\u4f7f\u7528\u8be5\u53c2\u6570\u65f6\u4e0d\u9700\u8981\u63d0\u4f9b\u989d\u5916\u4fe1\u606f\uff0c\u5e76\u4e14\u4f7f\u7528Get-WmiObject cmdlet\u4eceWin32_BootConfiguration WMI\u7c7b\u4e2d\u83b7\u53d6\u4fe1\u606f\u3002\u5982\u679c\u9700\u8981\uff0c\u53ef\u4ee5\u5c06$computer\u53d8\u91cf\u4e2d\u7684\u503c\u63d0\u4f9b\u7ed9-computername\u53c2\u6570\u3002\u8fd9\u6837\u53ef\u4ee5\u901a\u8fc7Get-WmiObject cmdlet\u8fde\u63a5\u5230\u8fdc\u7a0b\u8ba1\u7b97\u673a\uff0c\u6700\u7ec8\u5c06\u8fd4\u56de\u7684management\u5bf9\u8c61\u4f20\u9012\u7ed9Format-List cmdlet\u3002\u4f7f\u7528\u8303\u56f4\u8fd0\u7b97\u7b26\uff08range operator\uff09[a-z]*\u9009\u62e9\u5b57\u7b26\u5f00\u5934\u7684\u5c5e\u6027\uff0c\u4ee5\u8fc7\u6ee4\u62a5\u544a\u4e2d\u7684\u6240\u6709\u7cfb\u7edf\u5c5e\u6027\uff08\u56e0\u4e3a\u7cfb\u7edf\u5c5e\u6027\u5747\u4ee5\u4e0b\u753b\u7ebf\u5f00\u5934\uff09\u3002<\/p>\n<p>\u8be5\u811a\u672c\u7684\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\/image32.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_thumb32.png\" width=\"672\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe1 \u83b7\u53d6Windows\u5f15\u5bfc\u914d\u7f6e\u4fe1\u606f<\/p>\n<p><strong>\uff082\uff09\u68c0\u67e5\u542f\u52a8\u8fdb\u7a0b<\/strong><\/p>\n<p>\u5728Windows Vista\u548cWindows Server 2008\u7cfb\u7edf\u4e2d\u6709\u90e8\u5206\u7a0b\u5e8f\u4f34\u968f\u7cfb\u7edf\u542f\u52a8\uff0c\u5b83\u4eec\u4ee5\u4e0d\u540c\u542f\u52a8\u7ec4\u7684\u5f62\u5f0f\u5b58\u5728\u3002\u5f88\u591a\u6076\u610f\u8f6f\u4ef6\u548c\u75c5\u6bd2\u4ee5\u8fd9\u79cd\u5f62\u5f0f\u542f\u52a8\uff0c\u5f53\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8\u51fa\u73b0\u95ee\u9898\u65f6\u9700\u8981\u68c0\u67e5\u8fd9\u4e9b\u542f\u52a8\u7ec4\u3002<\/p>\n<p>\u521b\u5efa\u540d\u4e3a\u201cDetectStartupPrograms.ps1\u201d\u7684\u811a\u672c\u663e\u793a\u672c\u5730\u6216\u8fdc\u7a0b\u8ba1\u7b97\u673a\u7684\u81ea\u52a8\u8fd0\u884c\u7a0b\u5e8f\u7684\u72b6\u6001\uff0c\u5e76\u67e5\u770b\u57fa\u672c\u6216\u5b8c\u6574\u7684\u7a0b\u5e8f\u4fe1\u606f\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>param($computer=&quot;localhost&quot;, [switch]$full, [switch]$help)<\/p>\n<p>function funHelp()<\/p>\n<p>{<\/p>\n<p>$helpText=@&quot;<\/p>\n<p>DESCRIPTION:<\/p>\n<p>NAME: DetectStartUpPrograms.ps1 <\/p>\n<p>Displays a listing of programs that automatically start<\/p>\n<p>PARAMETERS: <\/p>\n<p>-computer the name of the computer<\/p>\n<p>-full prints detailed information<\/p>\n<p>-help prints help file<\/p>\n<p>SYNTAX:<\/p>\n<p>DetectStartUpPrograms.ps1 -computer WebServer -full<\/p>\n<p>Displays name, command, location, and user information<\/p>\n<p>about programs that automatically start on a computer named WebServer<\/p>\n<p>DetectStartUpPrograms.ps1 -full<\/p>\n<p>Displays name, command, location, and user information<\/p>\n<p>about programs that automatically start on the local computer<\/p>\n<p>DetectStartUpPrograms.ps1 -computer WebServer<\/p>\n<p>Displays a listing of programs that automatically start on a computer named WebServer<\/p>\n<p>DetectStartUpPrograms.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>if($full)<\/p>\n<p>{ $property = &quot;name&quot;, &quot;command&quot;, &quot;location&quot;, &quot;user&quot; }<\/p>\n<p>else<\/p>\n<p>{ $property = &quot;name&quot; }<\/p>\n<p>Get-WmiObject -Class win32_startupcommand -computername $computer |<\/p>\n<p>Sort-Object -property name | <\/p>\n<p>format-list -property $property<\/p>\n<p>\u8be5\u811a\u672c\u4e2d\u4f7f\u7528param\u8bed\u53e5\u5b9a\u4e49\u4e86$computer\u3001$full\u548c$help\u53d8\u91cf\uff0c\u5206\u522b\u7528\u4e8e\u6307\u5b9a\u811a\u672c\u4f5c\u7528\u7684\u8ba1\u7b97\u673a\u53ca\u5e2e\u52a9\u4fe1\u606f\u3002\u968f\u540e\u5b9a\u4e49\u4e86\u4e24\u4e2aswitch\u53c2\u6570\uff0c\u5176\u4e2d-full\u7528\u4e8e\u8f93\u51fa\u5b8c\u6574\u7684\u542f\u52a8\u7a0b\u5e8f\u4fe1\u606f\uff1b-help\u7528\u4e8e\u8f93\u51fa\u5e2e\u52a9\u4fe1\u606f\u3002<\/p>\n<p>\u5982\u679c\u5728\u811a\u672c\u8fd0\u884c\u65f6\u63d0\u4f9b\u4e86-full\u53c2\u6570\uff0c\u5219\u8f93\u51fa\u7a0b\u5e8f\u7684\u540d\u79f0\u3001\u53ef\u6267\u884c\u6587\u4ef6\u3001\u8def\u5f84\u53ca\u7528\u6237\u540d\u7b49\u4fe1\u606f\uff1b\u5426\u5219\u4ec5\u663e\u793a\u540d\u79f0\u3002\u811a\u672c\u4e2d\u901a\u8fc7\u8c03\u7528Get-WmiObject cmdlet\u83b7\u5f97\u6240\u6709\u7684\u81ea\u52a8\u8fd0\u884c\u7a0b\u5e8f\uff0c\u5c06\u7ed3\u679c\u5bf9\u8c61\u7528\u7ba1\u9053\u53d1\u9001\u7ed9Sort-Object cmdlet\uff0c\u540c\u65f6\u5206\u7c7b\u5c5e\u6027\u540d\u79f0\u3002\u6700\u540e\u4f7f\u7528Format-List cmdlet\u9009\u62e9\u7531$property\u53d8\u91cf\u6307\u5b9a\u7684\u5c5e\u6027\u8f93\u51fa\uff0c\u8be5\u811a\u672c\u7684\u6267\u884c\u7ed3\u679c\u5982\u56fe2\u6240\u793a\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image33.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_thumb33.png\" width=\"672\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe2 \u6267\u884c\u7ed3\u679c<\/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>\u5982\u679cWindows Vista\u548cWindows Server 2008\u65e0\u6cd5\u6b63\u5e38\u542f\u52a8\uff0c\u5219\u53ef\u4ee5\u68c0\u67e5\u5f15\u5bfc\u914d\u7f6e\u6587\u4ef6\u662f\u5426 [&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-33386","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\/33386"}],"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=33386"}],"version-history":[{"count":1,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33386\/revisions"}],"predecessor-version":[{"id":33756,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33386\/revisions\/33756"}],"wp:attachment":[{"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33386"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}