{"id":33417,"date":"2011-01-23T16:58:12","date_gmt":"2011-01-23T15:58:12","guid":{"rendered":"http:\/\/txj.lzuer.com\/?p=33417"},"modified":"2024-11-06T11:19:54","modified_gmt":"2024-11-06T03:19:54","slug":"powershell2-0%e4%b9%8b%e7%bb%b4%e6%8a%a4%e7%bd%91%e7%bb%9c%e4%ba%8c%e5%a4%84%e7%90%86%e9%80%82%e9%85%8d%e5%99%a8%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.fuhaijun.com\/?p=33417","title":{"rendered":"PowerShell2.0\u4e4b\u7ef4\u62a4\u7f51\u7edc(\u4e8c)\u5904\u7406\u9002\u914d\u5668\u914d\u7f6e"},"content":{"rendered":"<p>\u5728\u5904\u7406\u6240\u6709\u9002\u914d\u5668\u7684\u72b6\u6001\u540e\uff0c\u8fd8\u53ef\u4ee5\u67e5\u8be2\u6bcf\u4e2a\u7f51\u7edc\u9002\u914d\u5668\u7684\u8be6\u7ec6\u914d\u7f6e\u4fe1\u606f\u3002\u53ef\u4ee5\u901a\u8fc7\u9009\u62e9\u201c\u63a7\u5236\u9762\u677f\u201d|\u201c\u7f51\u7edc\u548c\u5171\u4eab\u4e2d\u5fc3\u201d|\u201c\u7f51\u7edc\u8fde\u63a5\u201d\u9009\u9879\uff0c\u6253\u5f00\u201c\u7f51\u7edc\u8fde\u63a5\u201d\u7a97\u53e3\u3002\u5728\u5176\u4e2d\u663e\u793a\u6bcf\u4e2a\u9002\u914d\u5668\u7684\u8be6\u7ec6\u4fe1\u606f\u5e76\u505a\u76f8\u5e94\u8c03\u6574\uff0c\u5982\u56fe1\u6240\u793a\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image43.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=\"360\" alt=\"image\" src=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image_thumb43.png\" width=\"704\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe1 \u5728\u201c\u7f51\u7edc\u8fde\u63a5\u201d\u7a97\u53e3\u4e2d\u67e5\u770b\u6bcf\u4e2a\u9002\u914d\u5668\u7684\u8be6\u7ec6\u4fe1\u606f<\/p>\n<p>\u521b\u5efa\u540d\u4e3a\u201cGetNetAdapterConfig.ps1\u201d\u7684\u811a\u672c\u6536\u96c6\u7279\u5b9a\u7f51\u7edc\u9002\u914d\u5668\u7684\u7528\u4e8e\u6392\u9519\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5e76\u4e14\u901a\u8fc7\u6307\u5b9a\u5173\u952e\u5b57\u4ec5\u8fd4\u56de\u6709\u5173\u7f51\u7edc\u9002\u914d\u5668\u7684\u7279\u5b9a\u914d\u7f6e\u4fe1\u606f\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>param($computer=&quot;localhost&quot;,$query,$help)<\/p>\n<p>function funHelp()<\/p>\n<p>{<\/p>\n<p>$helpText=@&quot;<\/p>\n<p>DESCRIPTION:<\/p>\n<p>NAME: GetNetAdapterConfig.ps1<\/p>\n<p>Produces a listing of network adapter configuration information<\/p>\n<p>on a local or remote machine.<\/p>\n<p>PARAMETERS: <\/p>\n<p>-computer Specifies the name of the computer to run the script<\/p>\n<p>-help prints help file<\/p>\n<p>-query the type of query &lt; ip, dns, dhcp, all &gt;<\/p>\n<p>SYNTAX:<\/p>\n<p>GetNetAdapterConfig.ps1 -computerName WebServer<\/p>\n<p>Lists default network adapter configuration on a <\/p>\n<p>computer named WebServer<\/p>\n<p>GetNetAdapterConfig.ps1 -computerName WebServer -query IP<\/p>\n<p>Lists IPaddress, IPsubnet, DefaultIPgateway, MACAddress <\/p>\n<p>on a computer named WebServer<\/p>\n<p>GetNetAdapterConfig.ps1 -computerName WebServer -query DNS<\/p>\n<p>Lists DNSDomain, DNSDomainSuffixSearchOrder, DNSServerSearchOrder, <\/p>\n<p>DomainDNSRegistrationEnabled on a computer named WebServer<\/p>\n<p>GetNetAdapterConfig.ps1 -computerName WebServer -query DHCP<\/p>\n<p>Lists Index,DHCPEnabled, DHCPLeaseExpires, DHCPLeaseObtained, <\/p>\n<p>DHCPServer on a computer named WebServer<\/p>\n<p>GetNetAdapterConfig.ps1 -computerName WebServer -query ALL<\/p>\n<p>Lists all network adapter configuration information on a computer <\/p>\n<p>named WebServer<\/p>\n<p>GetNetAdapterConfig.ps1 -help ?<\/p>\n<p>Prints 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;Printing help now&#8230;&quot; ; funHelp }<\/p>\n<p>$class=&quot;win32_networkadapterconfiguration&quot;<\/p>\n<p>$IPproperty=&quot;IPaddress, IPsubnet, DefaultIPgateway, MACAddress&quot;<\/p>\n<p>$dnsProperty=&quot;DNSDomain, DNSDomainSuffixSearchOrder, `<\/p>\n<p>DNSServerSearchOrder, DomainDNSRegistrationEnabled&quot;<\/p>\n<p>$dhcpProperty=&quot;Index,DHCPEnabled, DHCPLeaseExpires, `<\/p>\n<p>DHCPLeaseObtained, DHCPServer&quot;<\/p>\n<p>if($query)<\/p>\n<p>{<\/p>\n<p>switch($query)<\/p>\n<p>{<\/p>\n<p>&quot;ip&quot; { $query=&quot;Select $IPproperty from $class&quot; }<\/p>\n<p>&quot;dns&quot; { $query=&quot;Select $dnsProperty from $class&quot; }<\/p>\n<p>&quot;dhcp&quot; { $query=&quot;Select $dhcpProperty from $class&quot; }<\/p>\n<p>&quot;all&quot; { <\/p>\n<p>$query = &quot;Select * from $class&quot; ; `<\/p>\n<p>Get-WmiObject -Query $query | format-list * ; <\/p>\n<p>exit<\/p>\n<p>}<\/p>\n<p>DEFAULT { <\/p>\n<p>$query = &quot;Select * from $class&quot; ; `<\/p>\n<p>Get-WmiObject -Query $query ; exit<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>ELSE<\/p>\n<p>{ <\/p>\n<p>$query = &quot;Select * from $class&quot; ; `<\/p>\n<p>Get-WmiObject -Query $query ; exit <\/p>\n<p>}<\/p>\n<p>Get-WmiObject -query $query | format-table [a-z]* -AutoSize<\/p>\n<p>\u8be5\u811a\u672c\u4f7f\u7528param\u8bed\u53e5\u5b9a\u4e49\u4e863\u4e2a\u53c2\u6570\uff0c\u5373-computer\u3001-query\u53ca-help\u3002\u5176\u4e2d\u8bbe\u7f6e-computer\u7684\u9ed8\u8ba4\u503c\u4e3alocalhost\u3002\u5982\u679c\u7528\u6237\u672a\u6307\u5b9a\u8ba1\u7b97\u673a\uff0c\u5219\u9ed8\u8ba4\u8fd4\u56de\u672c\u5730\u8ba1\u7b97\u673a\u7684\u7f51\u7edc\u914d\u7f6e\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u9488\u5bf9\u5e2e\u52a9\u4fe1\u606f\u521b\u5efa\u7684funhelp\u51fd\u6570\u7528\u4e8e\u8f93\u51fa\u5e2e\u52a9\u4fe1\u606f\uff0c\u5f53\u7528\u6237\u672a\u8f93\u5165\u53c2\u6570\u6216\u8f93\u5165\u9519\u8bef\u7684\u53c2\u6570\u65f6\uff0c\u8c03\u7528\u8be5\u51fd\u6570\u63d0\u793a\u8f93\u5165\u7684\u9519\u8bef\u53ca\u6b63\u786e\u7684\u8f93\u5165\u3002\u811a\u672c\u4e2d\u4f7f\u7528if\u8bed\u53e5\u68c0\u67e5$help\u53d8\u91cf\u662f\u5426\u5b58\u5728\uff0c\u56e0\u4e3a\u53ea\u6709\u7528\u6237\u5728\u8c03\u7528\u811a\u672c\u65f6\u6307\u5b9a\u4e86-help\u53c2\u6570\uff0c\u8be5\u53d8\u91cf\u624d\u4f1a\u5b58\u5728\u3002\u968f\u540e\u521d\u59cb\u5316\u7528\u4e8eWMI\u67e5\u8be2\u7684\u53d8\u91cf\uff0c\u8fd9\u4e9b\u53d8\u91cf\u7684\u5b58\u5728\u662f\u4e3a\u4e86\u4fbf\u4e8e\u5728\u540e\u9762\u5bf9\u547d\u4ee4\u884c\u5e94\u7528\u4e2d\u5b9e\u73b0\u7075\u6d3b\u8c03\u7528\u3002\u5728\u7528\u6237\u8f93\u5165\u7684\u53c2\u6570\u4e2d\u5305\u62ec-query\u53c2\u6570\u65f6\uff0c\u811a\u672c\u5c06\u4f1a\u8c03\u7528switch\u8bed\u53e5\u5224\u65ad$query\u53d8\u91cf\u503c\u3002\u5e76\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\uff0c\u8f93\u51faip\u3001dns\u3001dhcp\u548c\u6240\u6709\u6761\u76ee\u7684\u4fe1\u606f\u3002\u5728$query\u53d8\u91cf\u65e0\u8f93\u5165\u7684\u60c5\u51b5\u4e0b\u8fd8\u7279\u522b\u4f7f\u7528ELSE\u8bed\u53e5\u5c06WMI\u5bf9\u8c61\u4e2d\u7684\u6240\u6709\u5c5e\u6027\u53d1\u9001\u7ed9Get-WmiObject cmdlet\u67e5\u8be2\uff0c\u5728\u63a7\u5236\u53f0\u8f93\u51fa\u5f53\u524d\u8ba1\u7b97\u673a\u4e2d\u7684\u6240\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u4fe1\u606f\u3002\u5728\u4ee3\u7801\u7684\u6700\u540e\u5c06Get-WmiObject cmdlet\u67e5\u8be2\u7684\u7ed3\u679c\u901a\u8fc7\u7ba1\u9053\u4f20\u9012\u7ed9Format-Table cmdlet\u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u5728\u4f7f\u7528Format-Tables\u65f6\u9700\u8981\u6307\u5b9a\u7b26\u5408Get-WmiObject cmdlet\u8f93\u51fa\u4ee3\u7801\u683c\u5f0f\u7684\u53c2\u6570\u3002\u8be5\u811a\u672c\u7684\u6267\u884c\u7ed3\u679c\u5982\u56fe2\u548c\u56fe3\u6240\u793a\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image44.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_thumb44.png\" width=\"673\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe2 \u67e5\u8be2\u5f53\u524d\u4e3b\u673aDHCP\u4fe1\u606f<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image45.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_thumb45.png\" width=\"673\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe3 \u672a\u6307\u5b9a\u68c0\u7d22\u9879\u9ed8\u8ba4\u4f1a\u8f93\u51fa\u6240\u6709\u7684\u7f51\u7edc\u9002\u914d\u5668\u4fe1\u606f<\/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>\u5728\u5904\u7406\u6240\u6709\u9002\u914d\u5668\u7684\u72b6\u6001\u540e\uff0c\u8fd8\u53ef\u4ee5\u67e5\u8be2\u6bcf\u4e2a\u7f51\u7edc\u9002\u914d\u5668\u7684\u8be6\u7ec6\u914d\u7f6e\u4fe1\u606f\u3002\u53ef\u4ee5\u901a\u8fc7\u9009\u62e9\u201c\u63a7\u5236\u9762\u677f\u201d|\u201c\u7f51\u7edc\u548c\u5171\u4eab\u4e2d\u5fc3\u201d [&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-33417","post","type-post","status-publish","format-standard","hentry","category-powershell","category-default"],"_links":{"self":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33417"}],"collection":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33417"}],"version-history":[{"count":1,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33417\/revisions"}],"predecessor-version":[{"id":33749,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33417\/revisions\/33749"}],"wp:attachment":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}