{"id":33114,"date":"2010-11-23T17:09:06","date_gmt":"2010-11-23T16:09:06","guid":{"rendered":"https:\/\/www.fuhaijun.com\/?p=33114"},"modified":"2024-11-06T11:22:38","modified_gmt":"2024-11-06T03:22:38","slug":"windows-powershell-2-0%e4%b9%8b%e5%87%bd%e6%95%b0%e5%92%8c%e8%84%9a%e6%9c%ac%e5%9d%97%e5%85%b1%e5%ad%98","status":"publish","type":"post","link":"https:\/\/www.fuhaijun.com\/?p=33114","title":{"rendered":"Windows PowerShell 2.0\u4e4b\u51fd\u6570\u548c\u811a\u672c\u5757\u5171\u5b58"},"content":{"rendered":"<p>\u5c06\u51fd\u6570\u548c\u811a\u672c\u5757\u7ed3\u5408\u8d77\u6765\u662f\u5f88\u5f3a\u5927\u7684\u7f16\u7a0b\u65b9\u6cd5\uff0c\u901a\u8fc7\u5408\u5e76\u51fd\u6570\u548c\u52a8\u6001\u7279\u6027\u7684\u811a\u672c\u5757\u521b\u5efa\u65b0\u7684\u547d\u4ee4\u53ef\u63a5\u8fd1\u4e8e\u5185\u7f6e\u7684PowerShell\u8bed\u6cd5\u7ed3\u6784\u3002\u8c03\u7528\u63a5\u53d7\u5355\u4e2a\u811a\u672c\u5757\u7684\u51fd\u6570\u7c7b\u4f3c\u4f7f\u7528if\uff0cwhile\u6216\u8005switch\u8bed\u53e5\uff0c\u8fd9\u6837\u505a\u7684\u597d\u5904\u5728\u4e8e\u80fd\u591f\u4f7f\u4ee3\u7801\u4fbf\u4e8e\u9605\u8bfb\u3001\u7406\u89e3\u548c\u7ef4\u62a4\u3002\u52a0\u4e4b\u8bed\u6cd5\u7684\u6709\u6548\u6027\uff0c\u4f7f\u811a\u672c\u5757\u6210\u4e3a\u4e86\u901a\u8fc7\u51fd\u6570\u6267\u884c\u5c01\u88c5\u64cd\u4f5c\u548c\u7b56\u7565\u7684\u597d\u5de5\u5177\u3002 <\/p>\n<p><b>\u51fd\u6570\u548c\u811a\u672c\u5757<\/b><\/p>\n<p><b>\u5b9e\u73b0\u65b0\u7684\u63a7\u5236\u7ed3\u6784<\/b><\/p>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5faa\u73af\u9700\u8981\u6709\u4f7f\u7a0b\u5e8f\u9010\u6b65\u8d8b\u4e8e\u7ed3\u675f\u7684\u9000\u51fa\u6761\u4ef6\u3002\u5faa\u73af\u7684\u89c4\u8303\u662f\u6309\u7167\u4e0b\u9762\u7684\u5f62\u5f0f\u4f7f\u7528while\u548cfor\u5faa\u73af\uff1a <\/p>\n<pre>PS&gt; while ($true)\n{\n\t\tWrite-Host \u201cLooping\u2026\u201d\n\t\t#something triggers the exit condition\n\t\tBreak\n}\n\nPS&gt; for (;;)\n{\n\t\tWrite-Host  \u201cLooping\u2026\u201d\n\t\t#something triggers the exit condition\n\t\tBreak\n}<\/pre>\n<p>\u4e3a\u4e86\u4fbf\u6377\uff0c\u5176\u4e2d\u5f15\u5165\u4e00\u4e2a\u65b0\u7684\u8bed\u53e5loop\u3002\u8fd9\u4e2a\u8bed\u53e5\u53ef\u4ee5\u6709\u6761\u4ef6\u5730\u91cd\u590d\u6267\u884c\u4e00\u4e2a\u811a\u672c\u5757\uff0c\u5728\u5185\u90e8\u4f7f\u7528\u9690\u85cf\u7684while\u5faa\u73af\u591a\u6b21\u6267\u884c\u811a\u672c\u5757\uff0c\u5982\uff1a <\/p>\n<pre>PS&gt; function loop($code)\n{\n\t\tWhile($true)\n\t\t{\n\t\t\t&amp;$code\n}\n}\nPS&gt; loop{\n\tWrite-Host \u201cLooping\u2026\u201d\n\tbreak;\n}<\/pre>\n<p>\u8fd9\u6837\u7684\u8bed\u6cd5\u7ed3\u6784\u4e0e\u6b63\u5e38\u7684\u63a7\u5236\u6d41\u8bed\u53e5\u76f8\u4f3c\uff0c\u4e0d\u540c\u662f\u9700\u8981\u628a\u6267\u884c\u8bed\u53e5\u5199\u5230\u540c\u4e00\u884c\u6216\u4f7f\u7528\u53cd\u5f15\u53f7\uff08`\uff09\u5c06\u591a\u884c\u8bed\u53e5\u8f6c\u4e49\u4e3a\u4e00\u884c\uff0c\u8fd9\u6837Shell\u5c06\u6267\u884c\u811a\u672c\u5757\u5e76\u5c06\u5176\u4f20\u9012\u5230loop\u51fd\u6570\u4e2d\u3002\u5b9e\u9645\u811a\u672c\u5757\u5728while\u5faa\u73af\u4e2d\u6267\u884c\uff0c\u8fd9\u6837\u5141\u8bb8\u4f7f\u7528\u4e0e\u5faa\u73af\u76f8\u5173\u7684\u5de5\u4f5c\u6d41\u63a7\u5236\u8bed\u53e5\uff0c\u5982break\u548ccontinue\u3002 <\/p>\n<p>\u53e6\u5916\u4e00\u4e2a\u65b9\u4fbf\u7684\u6269\u5c55\u662f\u5b9a\u4e49\u80fd\u9759\u9ed8\u5ffd\u7565\u6240\u6709\u9519\u8bef\u7684\u64cd\u4f5c\u3002\u5982\u4e0b\u4ee3\u7801\u5b9a\u4e49\u4e00\u4e2aignore\u51fd\u6570\uff0c\u5728\u6267\u884c\u811a\u672c\u5757\u65f6\u6355\u83b7\u6240\u6709\u811a\u672c\u5757\u629b\u51fa\u7684\u5f02\u5e38\u5e76\u9759\u9ed8\u7ee7\u7eed\u3002\u5176\u4e2d\u4f1a\u5206\u522b\u6f14\u793a\u5bb9\u9519\u548c\u672a\u5bb9\u9519\u5904\u7406\u7684\u6267\u884c\u7ed3\u679c\uff1a <\/p>\n<pre>PS C:\\&gt; function ignore($code)\n&gt;&gt; {\n&gt;&gt;         trap\n&gt;&gt;         {\n&gt;&gt;             continue\n&gt;&gt;         }\n&gt;&gt;         &amp;$code\n&gt;&gt; }\n&gt;&gt;\nPS C:\\&gt; $numbers = 2..0\nPS C:\\&gt; foreach ($number in $numbers)\n&gt;&gt; {\n&gt;&gt;      ignore {\n&gt;&gt;             5 \/ $number\n&gt;&gt;      }\n&gt;&gt; }\n&gt;&gt;\n2.5\n5\nPS C:\\&gt; foreach ($number in $numbers)\n&gt;&gt;      { \n&gt;&gt;        5 \/ $number\n&gt;&gt;      }\n&gt;&gt;\n2.5\n5\nAttempted to divide by zero.\nAt line:2 char:11\n+      { 5 \/ &lt;&lt;&lt;&lt;  $number\n    + CategoryInfo          : NotSpecified: (:) [], RuntimeException\n    + FullyQualifiedErrorId : RuntimeException<\/pre>\n<p>\u4e0a\u8ff0\u51fd\u6570\u4e2d\u521b\u5efa\u4e86\u5f02\u5e38\u6355\u83b7\u9677\u9631\uff0c\u5f53\u9519\u8bef\u53d1\u751f\u65f6\u4e0d\u5904\u7406\u5f02\u5e38\u800c\u7ee7\u7eed\u6267\u884c\u3002\u5176\u4e2d\u4f7f\u7528ignore\u51fd\u6570\u5ffd\u7565\u5728\u9664\u6cd5\u64cd\u4f5c\u65f6\u53d1\u751f\u7684\u9519\u8bef\uff0c\u5728\u7ed3\u679c\u4e2d\u80fd\u770b\u5230\u4e24\u4e2a\u8fd4\u56de\u503c\u3002\u56e0\u4e3a\u7b2c3\u4e2a\u8fd0\u7b97\u53d1\u751f\u4e86\u96f6\u9664\u9519\u8bef\uff0c\u56e0\u800c\u629b\u51fa\u5f02\u5e38\u5e76\u88ab\u5f02\u5e38\u9677\u9631\u6240\u6355\u83b7\u800c\u672a\u73b0\u5b9e\u51fa\u9519\u4fe1\u606f\u3002\u66f4\u591a\u8be6\u7ec6\u7684\u5f02\u5e38\u5904\u7406\u548c\u8c03\u8bd5\u7684\u8ba8\u8bba\u8bf7\u53c2\u89c1\u7b2c11\u7ae0\u3002 <\/p>\n<p>\u53e6\u5916\u4e00\u79cd\u6709\u7528\u7684\u6269\u5c55\u662f\u521b\u5efa\u80fd\u5e2e\u52a9\u7528\u6237\u83b7\u53d6\u67d0\u4e2a\u547d\u4ee4\u7684\u8bca\u65ad\u4fe1\u606f\u3002\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u4e3a\u4e86\u786e\u8ba4\u4e00\u6bb5\u4ee3\u7801\u786e\u5b9e\u6267\u884c\uff0c\u9700\u8981\u5728\u4ee3\u7801\u6bb5\u524d\u540e\u5206\u522b\u589e\u52a0Write-Host\u8bed\u53e5\u3002\u5219\u5982\u679c\u6267\u884c\u4ee3\u7801\u5757\u524d\u7684\u8be5\u8bed\u53e5\uff0c\u80af\u5b9a\u8981\u6267\u884c\u5176\u540e\u7684\u4ee3\u7801\u5757\uff1b\u5982\u679c\u6267\u884c\u4e86\u540e\u9762\u7684\u8bed\u53e5\uff0c\u5219\u5176\u524d\u9762\u7684\u4ee3\u7801\u5757\u6ca1\u6709\u53d1\u751f\u4efb\u4f55\u9519\u8bef\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u51fd\u6570\u6765\u6dfb\u52a0\u8c03\u8bd5\u4fe1\u606f\uff0c\u8fd9\u4e2a\u51fd\u6570\u5e26\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u5373\u5f53\u524d\u64cd\u4f5c\u7684\u63cf\u8ff0\u53ca\u64cd\u4f5c\u672c\u8eab\u7684\u4ee3\u7801\u3002\u5e76\u5728\u8c03\u7528\u88ab\u8c03\u8bd5\u7a0b\u5e8f\u524d\u540e\u5206\u522b\u6253\u5370\u63cf\u8ff0\u4fe1\u606f\uff1a <\/p>\n<pre>PS C:\\&gt; function trace($description, $code)\n&gt;&gt; {\n&gt;&gt;     Write-Host &quot;Before:$description&quot;\n&gt;&gt;     &amp;$code\n&gt;&gt;     Write-Host &quot;After:$description&quot;\n&gt;&gt; }\n&gt;&gt;\nPS C:\\&gt; trace &quot;dir Command&quot;{\n&gt;&gt;         dir *.txt\n&gt;&gt; }\n&gt;&gt;\nBefore:dir Command\n\n    Directory: C:\\\n\nMode                LastWriteTime     Length Name\n----                -------------     ------ ----\n-a---          2009\/1\/3     14:31         12 digit.txt\n-a---          2009\/1\/3      6:06      12100 largetext.txt\n-a---          2009\/1\/3      6:07       6949 smalltext.txt\n-ar--          2009\/1\/3      6:27         13 test.txt\n-a---          2009\/1\/3      6:28          9 test2.txt\nAfter:dir Command\nPS C:\\&gt; trace &quot;division&quot; {\n&gt;&gt;         $denominator = 0\n&gt;&gt;         5 \/ $denominator\n&gt;&gt; }\n&gt;&gt;\nBefore:division\nAttempted to divide by zero.\nAt line:3 char:12\n+         5 \/ &lt;&lt;&lt;&lt;  $denominator\n    + CategoryInfo          : NotSpecified: (:) [], RuntimeException\n    + FullyQualifiedErrorId : RuntimeException\n\nAfter:division<\/pre>\n<p>trace\u51fd\u6570\u4f7f\u5f97\u8c03\u8bd5\u4fe1\u606f\u51fa\u73b0\u5728\u811a\u672c\u5757\u4e2d\u4efb\u4f55\u8bed\u53e5\u7684\u4e24\u4fa7\uff0c\u8fd9\u4e9b\u4ee3\u7801\u5728\u6267\u884c\u65f6\u4f1a\u5c06\u65e5\u5fd7\u8f93\u51fa\u5230\u63a7\u5236\u53f0\u4e2d\u3002\u5982\u679c\u4f7f\u7528\u5d4c\u5957\u5f62\u5f0f\u7ec4\u5408ignore\u548ctrace\uff0c\u5219\u53ef\u8ffd\u8e2a\u9664\u96f6\u64cd\u4f5c\u5e76\u5ffd\u7565\u6240\u6709\u9519\u8bef\uff0c\u5982\uff1a <\/p>\n<pre>PS C:\\&gt; trace &quot;division&quot; {\n&gt;&gt;     ignore {\n&gt;&gt;     $denominator = 0\n&gt;&gt;     5 \/  $denominator\n&gt;&gt;     }\n&gt;&gt; }\n&gt;&gt;\nBefore:division\nAfter:division<\/pre>\n<p>\u5728\u8c03\u8bd5\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u4f7f\u7528\u7c7b\u4f3ctrace\u51fd\u6570\u7684\u65b9\u5f0f\u5199\u5165\u6587\u4ef6\uff0c\u4ece\u800c\u68c0\u6d4b\u51fd\u6570\u7684\u6267\u884c\u3002 <\/p>\n<p><b>\u811a\u672c\u5757\u7b56\u7565<\/b><\/p>\n<p>PowerShell\u5728\u96c6\u5408\u53ca\u64cd\u4f5c\u7ba1\u9053\u65b9\u9762\u7684\u529f\u80fd\u5341\u5206\u5f3a\u5927\u3002\u5f88\u591a\u65f6\u5019\u9700\u8981\u5904\u7406\u590d\u6742\u65b9\u5f0f\u7ec4\u7ec7\u7684\u6570\u636e\uff0c\u5bf9\u96c6\u5408\u8fdb\u884c\u5b8c\u5168\u7684\u904d\u5386\u5e76\u4e0d\u662f\u89e3\u51b3\u95ee\u9898\u7684\u6700\u597d\u529e\u6cd5\u3002\u5047\u8bbe\u5f53\u524d\u9700\u8981\u904d\u5386\u6587\u4ef6\u7cfb\u7edf\u6216\u8005XML\u6587\u6863\u6811\uff0c\u8fd9\u4e24\u4e2a\u5bf9\u8c61\u62e5\u6709\u5c42\u6b21\u7ed3\u6784\uff0c\u6700\u597d\u901a\u8fc7\u9012\u5f52\u6765\u5b9e\u73b0\u3002\u4f46\u662fPowerShell\u4e0d\u63d0\u4f9b\u5bf9\u6811\u7684\u5185\u7f6e\u904d\u5386\u7b97\u6cd5\u3002\u5047\u8bbe\u8fd9\u91cc\u9700\u8981\u904d\u5386\u4e00\u4e2a\u5f88\u5927\u7684XML\u6587\u4ef6\uff0c\u5e76\u4ece\u4e2d\u63d0\u53d6\u6570\u6240\u9700\u7279\u5b9a\u6761\u4ef6\u7684\u4e0d\u540c\u8282\u70b9\u7684\u6570\u636e\u3002\u4e3a\u4e86\u4fbf\u4e8e\u6f14\u793a\uff0c\u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u7c7b\u4f3cHTML\u6587\u6863\u7684\u540d\u4e3a\u201cdata.xml\u201d\u7684XML\u6587\u4ef6\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a <\/p>\n<pre>&lt;body&gt;\nsome text and an unordered list\n&lt;ul&gt;\n&lt;li&gt;&lt;a href=&quot;doc1.xml&quot;&gt;doc1&lt;\/a&gt;&lt;\/li&gt;\n&lt;li&gt;&lt;a href=&quot;doc2.xml&quot;&gt;doc2&lt;\/a&gt;&lt;\/li&gt;\n&lt;li&gt;EMPTY&lt;\/li&gt;\n&lt;\/ul&gt;\n&lt;\/body&gt;<\/pre>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5feb\u901f\u5bfc\u5165XML\u6587\u6863\uff1a <\/p>\n<pre>PS C:\\PowerShell\\CHAPTER07&gt; $doc = [xml](Get-Content data.xml)\nPS C:\\PowerShell\\CHAPTER07&gt; $doc\n\nbody\n----\nBody<\/pre>\n<p>\u5982\u679c\u8981\u83b7\u53d6\u7b2c1\u4e2a\u5305\u542b<a>\u6807\u7b7e\u7684 <\/a><\/p>\n<li>\u5143\u7d20\uff0c\u5219\u521b\u5efa\u4e00\u4e2a\u9012\u5f52\u51fd\u6570\u4ece\u5143\u7d20\u5f00\u59cb\u904d\u5386\u5176\u6240\u6709\u5b50\u5143\u7d20\u3002\u7136\u540e\u904d\u5386\u5b50\u5143\u7d20\u7684\u5b50\u5143\u7d20\uff0c\u76f4\u5230\u627e\u51fa\u8981\u67e5\u627e\u7684\u5143\u7d20\u4e3a\u6b62\u3002\u4ee5\u4e0b\u662f\u51fd\u6570\u7684\u4ee3\u7801\uff1a\n<pre>PS C:\\PowerShell\\CHAPTER07&gt;function Find-LiAnchor($root)\n&gt;&gt; {\n&gt;&gt; \t$name = $root.PSBase.Name\n&gt;&gt; \tif ($name -eq &quot;li&quot; -and $root.a -ne $null)\n&gt;&gt; \t{\n&gt;&gt; \t\treturn $root\n&gt;&gt; \t}\n&gt;&gt; \telse\n&gt;&gt; \t{\n&gt;&gt; \t\tforeach ($child in $root.PSBase.ChildNodes)\n&gt;&gt; \t\t{\n&gt;&gt; \t\t\t$result = Find-LiAnchor -root $child -strategy $strategy\n&gt;&gt; \t\t\tif ($result)\n&gt;&gt; \t\t\t{\n&gt;&gt; \t\t\t\treturn $result\n&gt;&gt; \t\t\t}\n&gt;&gt; \t\t}\n&gt;&gt; \t}\n&gt;&gt; }\n&gt;&gt; \nPS C:\\PowerShell\\CHAPTER07&gt; find-lianchor($doc.body)\n\na\n-\na<\/pre>\n<p>\u8be5\u51fd\u6570\u5c06\u4f1a\u8fd4\u56de\u53d1\u73b0\u7684\u7b2c1\u4e2aXML\u5143\u7d20\u7684\uff0c\u5176\u4e2d\u901a\u8fc7\u68c0\u6d4b\u5b50\u5143\u7d20\u662f\u5426\u5b58\u5728\u5c06\u8981\u641c\u7d22\u6761\u4ef6\u7684\u6807\u51c6\u6765\u786e\u5b9a\u662f\u5426\u9000\u51fa\u9012\u5f52\u3002\u9700\u8981\u5f3a\u8c03\u7684\u662f\u9700\u8981\u4f7f\u7528PSBase\u5c5e\u6027\u83b7\u53d6\u539f\u59cb\u4e14\u672a\u88abXML\u7c7b\u578b\u9002\u914d\u5668\u5904\u7406\u7684XML\u5143\u7d20\u5bf9\u8c61\u53ca\u5176\u5c5e\u6027\u3002XML\u7c7b\u578b\u9002\u914d\u5668\u4e0d\u5141\u8bb8\u7528\u6237\u901a\u8fc7Name\u5c5e\u6027\u76f4\u63a5\u83b7\u53d6\u5230\u6807\u7b7e\u540d\u3002\u4e3a\u4e86\u80fd\u591f\u641c\u7d22\u5230\u7b2c1\u4e2a<\/p>\n<p>\u5143\u7d20\u5305\u542b\u7684 <a>\u6807\u7b7e\uff0c\u53ef\u4ee5\u770b\u5230\u5d4c\u5957\u90e8\u5206\u7684\u5185\u5bb9\u903b\u8f91\u5373\u662f\u91cd\u590d\u5d4c\u5957\u51fd\u6570\u672c\u8eab\u8981\u6267\u884c\u7684\u64cd\u4f5c\uff0c\u8fd9\u6837\u5d4c\u5957\u7684\u597d\u5904\u5728\u4e8e\u53ef\u4ee5\u4e0d\u7528\u8003\u8651\u67e5\u627e\u7684\u5185\u5bb9\u5728\u7b2c\u51e0\u5c42\u6807\u7b7e\u4e2d\u51fa\u73b0\u3002\u5f53\u53d1\u73b0\u67e5\u627e\u5185\u5bb9\u65f6\u5c06\u4f1a\u8fd4\u56de$true\u503c\uff1b\u5982\u679c\u5728\u6574\u4e2a\u6587\u4ef6\u4e2d\u6ca1\u6709\u53d1\u73b0\u5219\u67e5\u627e\u76ee\u6807\uff0c\u5219\u8fd4\u56de$false\u3002\u4ee5\u4e0b\u7684\u4ee3\u7801\u65f6\u5c06\u641c\u7d22\u7b56\u7565\u5c01\u88c5\u5728\u4e00\u4e2a\u811a\u672c\u5757\u4e2d\uff1a <\/a><\/p>\n<pre>PS C:\\PowerShell\\CHAPTER07&gt; function Find-Node($root, $strategy)\n&gt;&gt; {\n&gt;&gt;     $foundNode = &amp;$strategy -node $root\n&gt;&gt;     if ($foundNode)\n&gt;&gt;     {\n&gt;&gt;         return $root\n&gt;&gt;     }\n&gt;&gt;     else\n&gt;&gt;     {\n&gt;&gt;         foreach ($child in $root.PSBase.ChildNodes)\n&gt;&gt;         {\n&gt;&gt;             $result = Find-Node -root $child -strategy $strategy\n&gt;&gt;             if ($result)\n&gt;&gt;             {\n&gt;&gt;                 return $result\n&gt;&gt;             }\n&gt;&gt;         }\n&gt;&gt;     }\n&gt;&gt; }\n&gt;&gt;\nPS C:\\PowerShell\\CHAPTER07&gt; $emptyLI = Find-Node -root $doc.body -strategy {\n&gt;&gt; param($node)\n&gt;&gt; return ($node.PSBase.Name -eq &quot;li&quot;) -and ($node.a -eq $null)\n&gt;&gt; }\n&gt;&gt;\nPS C:\\PowerShell\\CHAPTER07&gt; Write-Host $emptyLI\nli<\/pre>\n<p>\u6709\u4e86\u8fd9\u4e2aFindNode\u51fd\u6570\uff0c\u641c\u7d22\u5143\u7d20\u53d8\u5f97\u5f88\u7b80\u5355\uff0c\u7528\u6237\u53ea\u9700\u8981\u5c06\u641c\u7d22\u6761\u4ef6\u786e\u5b9a\u5230\u4e00\u4e24\u884c\u7684\u4ee3\u7801\u4e2d\u5373\u53ef\u3002\u4e0b\u4f8b\u4e2d\u67e5\u627e\u7b2c1\u4e2a\u5305\u542b\u975e\u7a7ahref\u5c5e\u6027\u7684<\/p>\n<\/p>\n<p>  <a>\u6807\u7b7e\uff1a <\/a><\/p>\n<pre>PS C:\\PowerShell\\CHAPTER07&gt; $anchor = Find-Node -root $doc.body -strategy {\n&gt;&gt; param($node)\n&gt;&gt; return ($node.PSBase.Name -eq &quot;a&quot;) -and `\n&gt;&gt; ($node.PSBase.GetAttribute(&quot;href&quot;) -ne $null)\n&gt;&gt; }\n&gt;&gt;\nPS C:\\PowerShell\\CHAPTER07&gt; Write-Host $anchor.href\ndoc1.xml<\/pre>\n<p>\u540c\u6837\u53ef\u4ee5\u4f7f\u7528PSBase\u83b7\u53d6\u539f\u59cb\u7684Name\u5c5e\u6027\u53caGetAttribute()\u65b9\u6cd5\uff0c\u53ef\u4ee5\u4f7f\u7528GetAttribute()\u65b9\u6cd5\u68c0\u67e5\u5143\u7d20\u662f\u5426\u5305\u542b\u7279\u5b9a\u7684\u5c5e\u6027\u3002 <\/p>\n<p><b>\u603b \u7ed3<\/b><\/p>\n<p>\u672c\u6587\u8ba8\u8bba\u4e86\u5728PowerShell\u4e2d\u5c06\u51fd\u6570\u548c\u811a\u672c\u5757\u7ed3\u5408\u8d77\u6765\u4f7f\u5176\u53d1\u6325\u5404\u81ea\u7684\u957f\u5904\uff0c\u4f7f\u51fd\u6570\u7684\u529f\u80fd\u66f4\u52a0\u7b26\u5408\u5b9e\u9645\u7684\u5e94\u7528\u73af\u5883\uff0c\u901a\u8fc7\u8fd9\u6837\u7684\u624b\u6bb5\u7528\u6237\u53ef\u4ee5\u5c01\u88c5\u4e0ePowerShell\u5185\u7f6e\u51fd\u6570\u6781\u5176\u76f8\u4f3c\u7684\u901a\u7528\u51fd\u6570\u6a21\u5757\u3002\u5c06\u51fd\u6570\u548c\u811a\u672c\u5757\u7ed3\u5408\u8d77\u6765\u662f\u5f88\u5f3a\u5927\u7684\u7f16\u7a0b\u65b9\u6cd5\uff0c\u901a\u8fc7\u5408\u5e76\u51fd\u6570\u548c\u52a8\u6001\u7279\u6027\u7684\u811a\u672c\u5757\u521b\u5efa\u65b0\u7684\u547d\u4ee4\u53ef\u63a5\u8fd1\u4e8e\u5185\u7f6e\u7684PowerShell\u8bed\u6cd5\u7ed3\u6784\u3002 <\/p>\n<\/p>\n<p>\u8d5b\u8fea\u7f51\u5730\u5740\uff1a<a title=\"http:\/\/news.ccidnet.com\/art\/32857\/20100617\/2089233_1.html\" href=\"http:\/\/news.ccidnet.com\/art\/32857\/20100617\/2089233_1.html\">http:\/\/news.ccidnet.com\/art\/32857\/20100617\/2089233_1.html<\/a><\/p>\n<p>\u4f5c\u8005: \u4ed8\u6d77\u519b<br \/>\n    <br \/>\u7248\u6743\uff1a\u672c\u6587\u7248\u6743\u5f52\u4f5c\u8005\u6240\u6709<\/p>\n<p>\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<\/p>\n<p>\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 <\/p>\n<p>\u4e2a\u4eba\u7f51\u7ad9: <a href=\"http:\/\/txj.shell.tor.hu\/\">http:\/\/txj.shell.tor.hu\/<\/a><\/p>\n<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u5c06\u51fd\u6570\u548c\u811a\u672c\u5757\u7ed3\u5408\u8d77\u6765\u662f\u5f88\u5f3a\u5927\u7684\u7f16\u7a0b\u65b9\u6cd5\uff0c\u901a\u8fc7\u5408\u5e76\u51fd\u6570\u548c\u52a8\u6001\u7279\u6027\u7684\u811a\u672c\u5757\u521b\u5efa\u65b0\u7684\u547d\u4ee4\u53ef\u63a5\u8fd1\u4e8e\u5185\u7f6e\u7684PowerS [&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],"tags":[],"class_list":["post-33114","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33114"}],"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=33114"}],"version-history":[{"count":1,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33114\/revisions"}],"predecessor-version":[{"id":33802,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33114\/revisions\/33802"}],"wp:attachment":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}