{"id":33381,"date":"2011-01-15T16:57:57","date_gmt":"2011-01-15T15:57:57","guid":{"rendered":"http:\/\/txj.lzuer.com\/?p=33381"},"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%b9%9d%e7%a3%81%e7%9b%98%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"http:\/\/www.fuhaijun.com\/?p=33381","title":{"rendered":"PowerShell2.0\u4e4b\u684c\u9762\u8ba1\u7b97\u673a\u7ef4\u62a4(\u4e5d)\u78c1\u76d8\u7ba1\u7406"},"content":{"rendered":"<p><strong>1 \u5904\u7406\u78c1\u76d8\u5206\u533a<\/strong><\/p>\n<p>PC\u901a\u5e38\u53ea\u4f1a\u6709\u4e00\u4e2a\u78c1\u76d8\uff0cWindows\u7684\u7ba1\u7406\u7b56\u7565\u4f1a\u4ee5\u5206\u533a\u5f62\u5f0f\u7ba1\u7406\u78c1\u76d8\uff0c\u8fd9\u6837\u5373\u53ef\u5c06\u7269\u7406\u786c\u4ef6\u4ece\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u62bd\u8c61\u51fa\u6765\u3002\u5206\u533a\u6982\u5ff5\u5bf9\u4e8e\u9ad8\u6548\u7387\u5730\u7ef4\u62a4\u7cfb\u7edf\u548c\u6587\u4ef6\u5f88\u6709\u597d\u5904\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u201c\u8ba1\u7b97\u673a\u7ba1\u7406\u201d\u7684\u201c\u78c1\u76d8\u7ba1\u7406\u201d\u5de5\u5177\u4e2d\u67e5\u770b\u78c1\u76d8\u548c\u78c1\u76d8\u5206\u533a\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u5982\u56fe23\u6240\u793a\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image27.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=\"442\" alt=\"image\" src=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image_thumb27.png\" width=\"673\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe1 \u8f93\u51fa\u78c1\u76d8\u4fe1\u606f<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image28.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=\"363\" alt=\"image\" src=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image_thumb28.png\" width=\"644\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe2 \u78c1\u76d8\u548c\u78c1\u76d8\u5206\u533a\u7684\u5173\u7cfb<\/p>\n<p>\u521b\u5efa\u540d\u4e3a\u201cReportDiskPartition.ps1\u201d\u7684\u811a\u672c\uff0c\u7528\u4e8e\u83b7\u53d6\u7cfb\u7edf\u4e2d\u5b58\u5728\u7684\u5206\u533a\u5c5e\u6027\u3002\u5176\u4e2d\u5c06\u68c0\u67e5\u53d8\u91cf$args\u7684\u503c\uff0c\u4ee5\u5224\u65ad\u6267\u884c\u811a\u672c\u65f6\u662f\u5426\u4f20\u9012\u53c2\u6570\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8be5\u53d8\u91cf\uff0c\u5219\u8868\u660e\u5728\u8fd0\u884c\u811a\u672c\u65f6\u672a\u63d0\u4f9b\u53c2\u6570\u3002\u6b64\u65f6\u811a\u672c\u4f1a\u4f5c\u4e3a\u672c\u5730\u8ba1\u7b97\u673a\u5904\u7406\uff0c\u5373\u4f20\u9012localhost\u7ed9$args\u53d8\u91cf\u3002\u5982\u679c\u4f20\u9012\u95ee\u53f7\u7ed9\u811a\u672c\uff0c\u5219\u8fd4\u56de\u5f53\u524d\u811a\u672c\u7684\u5e2e\u52a9\u4fe1\u606f\uff0c\u8be5\u811a\u672c\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>if(!$args) <\/p>\n<p>{<\/p>\n<p>Write-Host -foregroundcolor green `<\/p>\n<p>&#8216;Querying localhost &#8230;&#8217;<\/p>\n<p>$args = &#8216;localhost&#8217; <\/p>\n<p>}<\/p>\n<p>if($args -eq &quot;?&quot;)<\/p>\n<p>{ &quot;<\/p>\n<p>ReportDiskPartition.ps1<\/p>\n<p>DESCRIPTION:<\/p>\n<p>This script can take a single argument, computer name.<\/p>\n<p>It will display drive configuration on either a local<\/p>\n<p>or a remote computer. You can supply either a ? or a<\/p>\n<p>name of a local machine. <\/p>\n<p>EXAMPLE:<\/p>\n<p>ReportDiskPartition.ps1 remoteComputerName<\/p>\n<p>reports on disk partition information on a computer named<\/p>\n<p>remoteComputerName<\/p>\n<p>The script will also display this help file. This is<\/p>\n<p>done via the ? argument as seen here.<\/p>\n<p>ReportDiskPartition.ps1 ?<\/p>\n<p>&quot;<\/p>\n<p>}<\/p>\n<p>Get-WmiObject -Class Win32_DiskPartition `<\/p>\n<p>-computer $args<\/p>\n<p>\u5176\u4e2d\u4f7f\u7528Get-WmiObject cmdlet\u53ca-class\u53c2\u6570\u641c\u7d22Win32_DiskPartition WMI\u7c7b\uff0c\u5e76\u83b7\u5f97\u78c1\u76d8\u5206\u533a\u7684\u914d\u7f6e\u4fe1\u606f\u548c\u503c\u3002\u5982\u679c\u4f7f\u7528$args\u53c2\u6570\u63d0\u4f9b\u4e86\u8981\u67e5\u8be2\u78c1\u76d8\u5206\u533a\u4fe1\u606f\u7684\u8ba1\u7b97\u673a\u540d\uff0c\u5219\u53ef\u4f7f\u7528-computer\u53c2\u6570\u4e3aGet-WmiObject\u63d0\u4f9b\u8ba1\u7b97\u673a\u540d\uff0c\u6267\u884c\u7ed3\u679c\u5982\u56fe24\u6240\u793a\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image29.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=\"442\" alt=\"image\" src=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image_thumb29.png\" width=\"673\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe3 \u6267\u884c\u7ed3\u679c<\/p>\n<p><strong>2 \u5339\u914d\u78c1\u76d8\u548c\u5206\u533a<\/strong><\/p>\n<p>\u5339\u914d\u9a71\u52a8\u5668\u548c\u5206\u533a\u4e4b\u540e\uff0c\u8fd8\u9700\u8981\u76f8\u5e94\u5904\u7406\u78c1\u76d8\u548c\u5206\u533a\u7684\u811a\u672c\uff0c\u56e0\u4e3a\u6709\u65f6\u9700\u8981\u7279\u5b9a\u9a71\u52a8\u5668\u7684\u5206\u533a\u4fe1\u606f\u3002\u521b\u5efa\u540d\u4e3a\u201cReportSpecificDiskPartition.ps1\u201d\u7684\u811a\u672c\u6765\u83b7\u53d6\u786c\u76d8\u7279\u5b9a\u5206\u533a\u7684\u914d\u7f6e\u4fe1\u606f\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>param($computer=&quot;localhost&quot;,$disk=&quot;\u78c1\u76d8 #0\uff0c\u5206\u533a #0&quot;,$help)<\/p>\n<p>if($computer) <\/p>\n<p>{<\/p>\n<p>Write-Host -foregroundcolor green `<\/p>\n<p>&quot;Querying $computer &#8230;&quot;<\/p>\n<p>}<\/p>\n<p>if($disk) <\/p>\n<p>{<\/p>\n<p>Write-Host -foregroundcolor green `<\/p>\n<p>&quot;Querying $disk for partition information &#8230;&quot;<\/p>\n<p>}<\/p>\n<p>if($help)<\/p>\n<p>{ &quot;<\/p>\n<p>ReportSpecificDiskPartition.ps1<\/p>\n<p>DESCRIPTION:<\/p>\n<p>This script can take a multiple arguments, computer name, <\/p>\n<p>drive number and help.<\/p>\n<p>It will display partition configuration on either a local<\/p>\n<p>or a remote computer. You can supply either help, drive and<\/p>\n<p>name of a local or remote machine. <\/p>\n<p>EXAMPLE:<\/p>\n<p>ReportSpecificDiskPartition.ps1 -computer remoteComputername<\/p>\n<p>reports on disk partition on drive 0 on a computer named<\/p>\n<p>remoteComputerName<\/p>\n<p>ReportSpecificDiskPartition.ps1 -computer remoteComputername -disk &#8216;\u78c1\u76d8 #0\uff0c\u5206\u533a #0&#8217;<\/p>\n<p>reports on disk partition on drive 1 on a computer named<\/p>\n<p>remoteComputerName<\/p>\n<p>ReportSpecificDiskPartition.ps1 -help y<\/p>\n<p>Prints out the help information seen here.<\/p>\n<p>&quot;<\/p>\n<p>Exit<\/p>\n<p>}<\/p>\n<p>Get-WmiObject -Class Win32_DiskPartition `<\/p>\n<p>-computer $computer | Where-Object { $_.name -match $Disk } | <\/p>\n<p>format-list [a-z]*<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image30.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_thumb30.png\" width=\"673\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe4 \u6267\u884c\u7ed3\u679c<\/p>\n<p>\u8fd9\u4e2a\u811a\u672c\u76843\u4e2a\u53c2\u6570\u5206\u522b\u662f-computer\u3001-disk\u548c-help\uff0c\u5176\u4e2d-computer\u9ed8\u8ba4\u4e3alocalhost\uff0c\u5373\u67e5\u8be2\u672c\u673a\u7684\u5206\u533a\u4fe1\u606f\uff1b-disk\u6307\u5b9a\u7279\u5b9a\u78c1\u76d8\u5206\u533a\u4fe1\u606f\uff0c\u8fd9\u91cc\u5c06\u9ed8\u8ba4\u503c\u8bbe\u7f6e\u4e3a\u201c\u78c1\u76d8#0\uff0c\u5206\u533a#0\u201d\uff0c\u5373\u7b2c1\u5757\u786c\u76d8\u7684\u7b2c1\u4e2a\u5206\u533a\uff1b-help\u8f93\u51fa\u811a\u672c\u7684\u540d\u79f0\u3001\u63cf\u8ff0\u4fe1\u606f\u53ca\u8bed\u6cd5\u8303\u4f8b\uff0c\u8f93\u51fa\u5e2e\u52a9\u4fe1\u606f\u540e\u5c06\u4f1a\u4f7f\u7528exit\u8bed\u53e5\u9000\u51fa\u811a\u672c\u3002\u8be5\u811a\u672c\u7684\u6267\u884c\u7ed3\u679c\u5982\u56fe25\u6240\u793a\u3002<\/p>\n<p><strong>3 \u5904\u7406\u903b\u8f91\u78c1\u76d8<\/strong><\/p>\n<p>\u4e3a\u4e86\u80fd\u591f\u83b7\u5f97\u8ba1\u7b97\u673a\u4e2d\u6709\u5173\u903b\u8f91\u78c1\u76d8\u7684\u914d\u7f6e\u4fe1\u606f\uff0c\u9700\u8981\u4f7f\u7528Get-WmiObject cmdlet\u3002\u7136\u540e\u4f7f\u7528-class\u53c2\u6570\u67e5\u8be2Win32_LogicalDisk WMI\u7c7b\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u8bbe\u5b9a-computer\u53c2\u6570\u67e5\u8be2\u6307\u5b9a\u8ba1\u7b97\u673a\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u6240\u6709\u53c2\u6570\u901a\u8fc7$args\u53d8\u91cf\u4f20\u9012\u5230\u811a\u672c\u4e2d\uff0c\u5982\u679c\u8be5\u53d8\u91cf\u4e0d\u5b58\u5728\uff0c\u5219\u6839\u636e\u9ed8\u8ba4\u503c\u83b7\u53d6\u7b2c1\u4e2a\u903b\u8f91\u78c1\u76d8\u7684\u4fe1\u606f\u3002\u521b\u5efa\u540d\u4e3a\u201cReportLogicalDiskConfiguration.ps1\u201d\u7684\u811a\u672c\u67e5\u8be2\u7cfb\u7edf\u4e2d\u5b58\u5728\u7684\u903b\u8f91\u78c1\u76d8\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>param($computer=&quot;localhost&quot;,$disk=&quot;C:&quot;,$help)<\/p>\n<p>if($computer) <\/p>\n<p>{<\/p>\n<p>Write-Host -foregroundcolor green `<\/p>\n<p>&#8216;Querying localhost &#8230;&#8217;<\/p>\n<p>}<\/p>\n<p>if($disk) <\/p>\n<p>{<\/p>\n<p>Write-Host -foregroundcolor green `<\/p>\n<p>&#8216;Querying $disk for logical disk info&#8230;&#8217;<\/p>\n<p># $args = &#8216;localhost&#8217; <\/p>\n<p>}<\/p>\n<p>if($help)<\/p>\n<p>{ &quot; <\/p>\n<p>ReportLogicalDiskConfiguration.ps1<\/p>\n<p>DESCRIPTION:<\/p>\n<p>This script can take a single argument, computer name.<\/p>\n<p>It will display logical disk configuration on either a local<\/p>\n<p>or a remote computer. You can supply either a ? or a<\/p>\n<p>name of a local machine. <\/p>\n<p>EXAMPLE:<\/p>\n<p>ReportLogicalDiskConfiguration.ps1 remoteComputerName<\/p>\n<p>reports on logical disk configuration on a computer named<\/p>\n<p>remoteComputerName<\/p>\n<p>The script will also display this help file. This is<\/p>\n<p>done via the ? argument as seen here.<\/p>\n<p>ReportLogicalDiskConfiguration.ps1 ?<\/p>\n<p>&quot;<\/p>\n<p>}<\/p>\n<p>Get-WmiObject -Class Win32_LogicalDisk `<\/p>\n<p>-computer $computer | Where-Object {$_.deviceID -match $Disk} |<\/p>\n<p>Format-List [a-z]*<\/p>\n<p>\u6b64\u811a\u672c\u7684\u6267\u884c\u7ed3\u679c\u5982\u56fe26\u6240\u793a\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image31.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=\"442\" alt=\"image\" src=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image_thumb31.png\" width=\"673\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe5 \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>1 \u5904\u7406\u78c1\u76d8\u5206\u533a PC\u901a\u5e38\u53ea\u4f1a\u6709\u4e00\u4e2a\u78c1\u76d8\uff0cWindows\u7684\u7ba1\u7406\u7b56\u7565\u4f1a\u4ee5\u5206\u533a\u5f62\u5f0f\u7ba1\u7406\u78c1\u76d8\uff0c\u8fd9\u6837\u5373\u53ef\u5c06\u7269\u7406\u786c\u4ef6\u4ece\u64cd [&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-33381","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\/33381"}],"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=33381"}],"version-history":[{"count":1,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33381\/revisions"}],"predecessor-version":[{"id":33757,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33381\/revisions\/33757"}],"wp:attachment":[{"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33381"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}