{"id":33410,"date":"2011-01-22T17:00:35","date_gmt":"2011-01-22T16:00:35","guid":{"rendered":"http:\/\/txj.lzuer.com\/?p=33410"},"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%b8%80%e6%9f%a5%e7%9c%8b%e7%bd%91%e7%bb%9c%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.fuhaijun.com\/?p=33410","title":{"rendered":"PowerShell2.0\u4e4b\u7ef4\u62a4\u7f51\u7edc(\u4e00)\u67e5\u770b\u7f51\u7edc\u8bbe\u7f6e"},"content":{"rendered":"<p>\u672c\u6587\u5c06\u4f1a\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PowerShell\u7ba1\u7406\u7f51\u7edc\uff0c\u5305\u62ec\u8bbe\u7f6e\u548cTCP\/IP\u5806\u6808\u6709\u5173\u7684\u9009\u9879\uff1b\u901a\u8fc7\u4e0d\u540c\u811a\u672c\u63d0\u4f9b\u7f51\u7edc\u9002\u914d\u5668\u7684\u72b6\u6001\u4fe1\u606f\uff0c\u7f51\u7edc\u9002\u914d\u5668\u7684\u8fde\u63a5\u72b6\u6001\u53ca\u5c5e\u6027\uff1b\u8bbe\u7f6e\u9759\u6001IP\u3001\u542f\u52a8DHCP\u53ca\u914d\u7f6eDNS\u670d\u52a1\u5668\uff1b\u83b7\u53d6\u9632\u706b\u5899\u8bbe\u7f6e\u4fe1\u606f\u5e76\u8bbe\u7f6e\u6709\u5173\u9009\u9879\u4ee5\u542f\u7528\u8fdc\u7a0b\u7ba1\u7406\uff0c\u4ee5\u53ca\u8fdc\u7a0b\u5171\u4eab\u6587\u4ef6\u7b49\u3002<\/p>\n<p>Windows Vista\u5f00\u59cb\u5728\u7f51\u7edc\u529f\u80fd\u65b9\u9762\u6709\u4e86\u5f88\u5927\u6539\u5584\uff0c\u5305\u62ec\u65b0\u7684\u9632\u706b\u5899\u670d\u52a1\u53caIPv6\u534f\u8bae\u7684\u589e\u5f3a\u652f\u6301\u7b49\u3002\u540c\u65f6\u4eceWindows Vista\u5f00\u59cbWMI\u4e2d\u589e\u52a0\u4e86\u5f88\u591a\u7528\u4e8e\u64cd\u4f5c\u9632\u706b\u5899\u548cIPv6\u7684\u65b0\u7279\u6027\u548c\u8ba1\u6570\u5668\uff0c\u53ef\u4ee5\u663e\u793a\u548c\u4f7f\u7528IPv6\u5730\u5740\u3002<\/p>\n<p>Windows Vista\u548cWindows Server 2008\u4e2d\u5305\u62ec\u5f3a\u5927\u7684\u7f51\u7edc\u529f\u80fd\uff0c\u5141\u8bb8\u7528\u6237\u4ee5\u7b80\u5355\u4e14\u4fbf\u6377\u7684\u65b9\u5f0f\u64cd\u4f5c\u7f51\u7edc\u3002\u4f46\u662f\u7ed9\u7f51\u7edc\u7ba1\u7406\u5458\u5e26\u6765\u5927\u91cf\u9ebb\u70e6\uff0c\u5982\u7ba1\u7406\u5927\u91cf\u7f51\u7edc\u9002\u914d\u5668\uff0c\u5982\u56fe1\u6240\u793a\u3002<\/p>\n<p align=\"center\"><a href=\"http:\/\/txj.shell.tor.hu\/wp-content\/uploads\/2011\/01\/image41.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_thumb41.png\" width=\"672\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe1 \u9700\u8981\u7ba1\u7406\u5927\u91cf\u7f51\u7edc\u9002\u914d\u5668<\/p>\n<p>\u4e3a\u4e86\u6709\u6548\u5730\u7ba1\u7406\u7f51\u7edc\u8bbe\u5907\uff0c\u521b\u5efa\u540d\u4e3a\u201cGetNetAdapterStatus.ps1\u201d\u7684\u811a\u672c\u7528\u4e8e\u68c0\u6d4b\u7f51\u7edc\u9002\u914d\u5668\u7684\u72b6\u6001\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>param($computer=&quot;localhost&quot;,$help)<\/p>\n<p>function funStatus($status)<\/p>\n<p>{<\/p>\n<p>switch($status)<\/p>\n<p>{<\/p>\n<p>0 { &quot; Disconnected&quot; }<\/p>\n<p>1 { &quot; Connecting&quot; } <\/p>\n<p>2 { &quot; Connected&quot; }<\/p>\n<p>3 { &quot; Disconnecting&quot; } <\/p>\n<p>4 { &quot; Hardware not present&quot; } <\/p>\n<p>5 { &quot; Hardware disabled&quot; } <\/p>\n<p>6 { &quot; Hardware malfunction&quot; } <\/p>\n<p>7 { &quot; Media disconnected&quot; } <\/p>\n<p>8 { &quot; Authenticating&quot; } <\/p>\n<p>9 { &quot; Authentication succeeded&quot; } <\/p>\n<p>10 { &quot; Authentication failed&quot; } <\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>function funHelp()<\/p>\n<p>{<\/p>\n<p>$helpText=@&quot;<\/p>\n<p>DESCRIPTION:<\/p>\n<p>NAME: GetNetAdapterStatus.ps1<\/p>\n<p>Produces a listing of network adapters and status on a local or remote machine.<\/p>\n<p>PARAMETERS: <\/p>\n<p>-computerName Specifies the name of the computer upon which to run the script<\/p>\n<p>-help prints help file<\/p>\n<p>SYNTAX:<\/p>\n<p>GetNetAdapterStatus.ps1 -computer WebServer<\/p>\n<p>Lists all the network adapters and status on a computer named WebServer<\/p>\n<p>GetNetAdapterStatus.ps1 <\/p>\n<p>Lists all the network adapters and status on local computer<\/p>\n<p>GetNetAdapterStatus.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>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 = $funline + &quot;=&quot; }<\/p>\n<p>Write-Host -ForegroundColor yellow $strIN <\/p>\n<p>Write-Host -ForegroundColor darkYellow $funline<\/p>\n<p>}<\/p>\n<p>if($help) { &quot;Printing help now&#8230;&quot; ; funHelp }<\/p>\n<p>$objWMI=Get-WmiObject -Class win32_networkadapter -computer $computer<\/p>\n<p>funline(&quot;Network adapters and status on $computer&quot;)<\/p>\n<p>foreach($net in $objWMI)<\/p>\n<p>{<\/p>\n<p>Write-Host &quot;$($net.name)&quot;<\/p>\n<p>funstatus($net.netconnectionstatus)<\/p>\n<p>}<\/p>\n<p>\u4e3a\u4e86\u83b7\u53d6\u7f51\u7edc\u9002\u914d\u5668\u7684\u72b6\u6001\uff0c\u5728\u8be5\u811a\u672c\u4e2d\u4f7f\u7528Win32_NetWorkAdapter WMI\u7c7b\u8fd4\u56de\u72b6\u6001\u4ee3\u7801\u3002\u5e76\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a\u201cfunStatus\u201d\u7684\u51fd\u6570\uff0c\u901a\u8fc7switch\u8bed\u53e5\u7684\u4ee3\u7801\u5757\u5305\u62ecWin32_NetWorkAdapterWMI\u7c7b\u5b9a\u4e49\u7684\u6240\u6709\u53ef\u80fd\u7684\u72b6\u6001\u4ee3\u7801\u3002\u72b6\u6001\u4ee3\u7801\u53ca\u5176\u542b\u4e49\u5728Windows\u8f6f\u4ef6\u5f00\u53d1\u5305\uff08SDK\uff09\u4e2d\u6709\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u8bf4\u660e\u5982\u4e0b\u3002<\/p>\n<p>\u00d8 0\uff1aDisconnected\uff08\u65ad\u5f00\uff09\u3002<\/p>\n<p>\u00d8 1\uff1aConnecting\uff08\u8fde\u63a5\u4e2d\uff09\u3002<\/p>\n<p>\u00d8 2\uff1aConnected\uff08\u5df2\u8fde\u63a5\uff09\u3002<\/p>\n<p>\u00d8 3\uff1aDisconnecting\uff08\u65ad\u5f00\u4e2d\uff09\u3002<\/p>\n<p>\u00d8 4\uff1aHardware not present\uff08\u786c\u4ef6\u4e0d\u5b58\u5728\uff09\u3002<\/p>\n<p>\u00d8 5\uff1aHardware disabled\uff08\u786c\u4ef6\u5df2\u7981\u7528\uff09\u3002<\/p>\n<p>\u00d8 6\uff1aHardware malfunction\uff08\u786c\u4ef6\u6545\u969c\uff09\u3002<\/p>\n<p>\u00d8 7\uff1aMedia disconnected\uff08\u5a92\u4ecb\u65ad\u5f00\uff09\u3002<\/p>\n<p>\u00d8 8\uff1aAuthenticating\uff08\u6743\u9650\u8ba4\u8bc1\u4e2d\uff09\u3002<\/p>\n<p>\u00d8 9\uff1aAuthentication succeeded\uff08\u6743\u9650\u8ba4\u8bc1\u6210\u529f\uff09\u3002<\/p>\n<p>\u00d8 10\uff1aAuthentication failed\uff08\u6743\u9650\u8ba4\u8bc1\u5931\u8d25\uff09\u3002<\/p>\n<p>\u5728\u8be5\u811a\u672c\u4e2d\u901a\u8fc7funStatus\u51fd\u6570\u5c06\u72b6\u6001\u503c\u8f6c\u6362\u4e3a\u4fbf\u4e8e\u7406\u89e3\u7684\u5185\u5bb9\uff0c\u5176\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\/image42.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_thumb42.png\" width=\"672\" border=\"0\" \/><\/a> <\/p>\n<p align=\"center\">\u56fe2 \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>\u672c\u6587\u5c06\u4f1a\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PowerShell\u7ba1\u7406\u7f51\u7edc\uff0c\u5305\u62ec\u8bbe\u7f6e\u548cTCP\/IP\u5806\u6808\u6709\u5173\u7684\u9009\u9879\uff1b\u901a\u8fc7\u4e0d\u540c\u811a\u672c\u63d0\u4f9b\u7f51\u7edc\u9002 [&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-33410","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\/33410"}],"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=33410"}],"version-history":[{"count":1,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33410\/revisions"}],"predecessor-version":[{"id":33750,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33410\/revisions\/33750"}],"wp:attachment":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}