{"id":33140,"date":"2010-12-17T17:35:43","date_gmt":"2010-12-17T16:35:43","guid":{"rendered":"https:\/\/www.fuhaijun.com\/?p=33140"},"modified":"2024-11-06T11:21:15","modified_gmt":"2024-11-06T03:21:15","slug":"windows-powershell-2-0%e4%b9%8b%e8%bf%9b%e7%a8%8b%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.fuhaijun.com\/?p=33140","title":{"rendered":"Windows PowerShell 2.0\u4e4b\u8fdb\u7a0b\u7ba1\u7406"},"content":{"rendered":"<p>\u8fdb\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7528\u4e8e\u5904\u7406\u6570\u636e\u548c\u8fdb\u7a0b\u95f4\u7684\u4ea4\u6362\uff0cPowerShell\u7684\u8fdb\u7a0b\u548c\u670d\u52a1\u7ba1\u7406\u673a\u5236\u80fd\u5206\u6790\u8fdb\u7a0b\u4fe1\u606f\uff0c\u5e76\u4e14\u76f4\u63a5\u64cd\u4f5c\u8fdb\u7a0b\u5b9e\u4f8b\u6307\u5411\u7684\u5bf9\u8c61\u3002\u8fd9\u6837\u5bf9\u8c61\u5316\u7684\u547d\u4ee4\u4e3a\u7528\u6237\u5728\u63d0\u53d6\u6570\u636e\u53ca\u4fee\u6539\u72b6\u6001\u65b9\u9762\u63d0\u4f9b\u4e86\u65b9\u4fbf\uff0c\u7ba1\u9053\u547d\u4ee4\u7684\u4f18\u70b9\u7ed3\u5408\u5bf9\u8c61\u5316\u7684\u8fdb\u7a0b\u548c\u670d\u52a1\u53ef\u4ee5\u7b80\u5316\u590d\u6742\u7684\u547d\u4ee4\u3002\u672c\u6587\u5c06\u8bb2\u89e3\u5982\u4f55\u64cd\u4f5c\u8fdb\u7a0b\u53ca\u5176\u5c5e\u6027\uff0c\u5305\u62ec\u542f\u52a8\u548c\u7ec8\u6b62\u8fdb\u7a0b\uff0c\u4ee5\u53ca\u67e5\u8be2\u5e76\u663e\u793a\u8fdb\u7a0b\u4fe1\u606f\u3002<\/p>\n<p>\u5728PowerShell\u4e2d\u6240\u6709\u4e0e\u8fdb\u7a0b\u76f8\u5173\u7684\u64cd\u4f5c\u5747\u75315\u4e2acmdlet\u6765\u5b9e\u73b0\uff0c\u5373Get-Process\u3001Start-Process\u3001Stop-Process\u3001Debug-Process\u548cWait-Process\u3002\u4e0b\u4f8b\u83b7\u53d6\u6240\u6709\u4e0eProcess\u76f8\u5173\u7684cmdlet\u7684\u65b9\u6cd5\uff1a<\/p>\n<p>PS C:\\&gt; Get-Command -Noun Process<\/p>\n<p>CommandType Name Definition<\/p>\n<p>&#8212;&#8212;&#8212;&#8211; &#8212;- &#8212;&#8212;&#8212;-<\/p>\n<p>Cmdlet Debug-Process Debug-Process [-Name] &lt;Strin&#8230;<\/p>\n<p>Cmdlet Get-Process Get-Process [[-Name] &lt;String&#8230;<\/p>\n<p>Cmdlet Start-Process Start-Process [-FilePath] &lt;S&#8230;<\/p>\n<p>Cmdlet Stop-Process Stop-Process [-Id] &lt;Int32[]&gt;&#8230;<\/p>\n<p>Cmdlet Wait-Process Wait-Process [-Name] &lt;String&#8230;<\/p>\n<p><strong>1 \u83b7\u53d6\u8fdb\u7a0b\u5217\u8868<\/strong><\/p>\n<p>\u4efb\u52a1\u7ba1\u7406\u5668\u662f\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u4f46\u5176\u4ec5\u63d0\u4f9b\u4e86\u8fdb\u7a0b\u6e05\u5355\u3002PowerShell\u5141\u8bb8\u7528\u6237\u5feb\u901f\u751f\u6210\u5404\u79cd\u5173\u4e8e\u7cfb\u7edf\u7684\u62a5\u544a\uff0c\u5e76\u53ef\u4e3a\u7ba1\u9053\u4f20\u9012\u6240\u6709\u4fe1\u606f\u3002\u4e0b\u4f8b\u6309\u7167\u7279\u5b9a\u5c5e\u6027\u503c\u6392\u5e8f\u6240\u6709\u8fdb\u7a0b\u5e76\u8fd4\u56de\u9876\u7aef\u76845\u4e2a\uff1a<\/p>\n<p>PS C:\\&gt; Get-Process | sort VM -Descending | select -First 5<\/p>\n<p>Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName<\/p>\n<p>&#8212;&#8212;- &#8212;&#8212; &#8212;&#8211; &#8212;&#8211; &#8212;&#8211; &#8212;&#8212; &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p>1621 39 74556 12908 894 645.19 3360 JAVAW<\/p>\n<p>383 19 40448 50784 559 195.64 2684 WINWORD<\/p>\n<p>835 34 68928 92044 433 57.38 6912 explorer<\/p>\n<p>1292 38 140732 7976 379 &#8230;23.52 4620 msnmsgr<\/p>\n<p>542 18 33008 1600 243 320.83 5080 mysql<\/p>\n<p>\u5176\u4e2d\u6709\u4e9b\u7a0b\u5e8f\u5360\u7528\u4e86\u5927\u91cf\u5185\u5b58\uff0c\u4f46\u662f\u5e76\u4e0d\u662f\u5360\u7528\u5927\u91cf\u5185\u5b58\u7684\u7a0b\u5e8f\u5c31\u4e00\u5b9a\u662f\u5bfc\u81f4\u7cfb\u7edf\u53d8\u6162\u7684\u76f4\u63a5\u539f\u56e0\u3002\u8fd8\u9700\u8981\u5206\u6790\u66f4\u8be6\u7ec6\u7684\u6570\u636e\u624d\u80fd\u5f97\u51fa\u7ed3\u8bba\uff0c\u5982\u4e0b\u6309\u7167WS\uff08Working Set\uff09\u5c5e\u6027\u68c0\u67e5\u5de5\u4f5c\u533a\uff1a<\/p>\n<p>PS C:\\&gt; Get-Process | sort WS -Descending | select -First 5<\/p>\n<p>Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName<\/p>\n<p>&#8212;&#8212;- &#8212;&#8212; &#8212;&#8211; &#8212;&#8211; &#8212;&#8211; &#8212;&#8212; &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p>846 34 68940 92060 434 57.66 6912 explorer<\/p>\n<p>384 19 40568 51488 561 212.33 2684 WINWORD<\/p>\n<p>221 10 65320 44572 183 263.77 4612 AcroRd32<\/p>\n<p>705 22 23340 23932 141 2,824.16 1236 mysql<\/p>\n<p>1621 39 74472 20256 894 647.58 3360 JAVAW<\/p>\n<p>\u5982\u679c\u6000\u7591\u7531\u4e8e\u98a0\u7c38\uff08thrashing\uff09\u4f7f\u5f97\u673a\u5668\u901f\u5ea6\u53d8\u6162\uff0c\u5219\u9700\u8981\u5206\u522b\u4f7f\u7528PM\u548cNPM\u5c5e\u6027\u67e5\u770b\u5206\u9875\u548c\u672a\u5206\u9875\u5185\u5b58\u6570\u3002<\/p>\n<p>-\u3010\u63d0\u793a\u3011&#8212;&#8212;&#8212;<\/p>\n<p>\u98a0\u7c38\u662f\u4e0d\u6267\u884c\u4efb\u4f55\u5904\u7406\u7684\u8ba1\u7b97\u673a\u6d3b\u52a8\uff0c\u901a\u5e38\u662f\u56e0\u4e3a\u5185\u5b58\u6216\u5176\u4ed6\u8d44\u6e90\u8017\u5c3d\u6216\u6709\u9650\u800c\u65e0\u6cd5\u5b8c\u6210\u6240\u8981\u6267\u884c\u7684\u64cd\u4f5c\u3002\u5f53\u8fd9\u79cd\u60c5\u51b5\u53d1\u751f\u65f6\uff0c\u7a0b\u5e8f\u901a\u8fc7\u64cd\u4f5c\u7cfb\u7edf\u53d1\u51fa\u8bf7\u6c42\u3002\u64cd\u4f5c\u7cfb\u7edf\u5219\u8bd5\u56fe\u91ca\u653e\u5176\u4ed6\u7a0b\u5e8f\u4e2d\u5360\u7528\u7684\u8d44\u6e90\uff0c\u4ece\u800c\u5bfc\u81f4\u4e0d\u80fd\u54cd\u5e94\u65b0\u7684\u8bf7\u6c42\u3002\u5728\u865a\u62df\u5b58\u50a8\u7cfb\u7edf\uff08\u4f7f\u7528\u9875\u7ba1\u7406\u903b\u8f91\u5b58\u50a8\u6216\u5185\u5b58\u7684\u64cd\u4f5c\u7cfb\u7edf\uff09\u4e2d\uff0c\u98a0\u7c38\u5373\u53d1\u751f\u8fc7\u5ea6\u9875\u8bf7\u6c42\u64cd\u4f5c\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u53d1\u751f\u98a0\u7c38\u7684\u7cfb\u7edf\u88ab\u8ba4\u4e3a\u662f\u4e00\u4e2a\u8fd0\u884c\u975e\u5e38\u6162\u6216\u4e00\u4e2a\u8fdb\u5165\u6682\u505c\u72b6\u6001\u7684\u7cfb\u7edf\u3002<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>\u8fd9\u6837\u53ef\u4ee5\u83b7\u53d6\u6240\u6709\u5360\u7528\u8d85\u8fc750MB\u7269\u7406\u5185\u5b58\u7684\u8fdb\u7a0b\uff0c\u8fd9\u79cd\u7c7b\u578b\u7684\u64cd\u4f5c\u5728PowerShell\u4e2d\u9891\u7e41\u51fa\u73b0\uff0c\u6240\u4ee5PowerShell\u652f\u6301KB\u3001MB\u548cGB\u6b64\u7c7b\u7684\u6570\u5b57\u5355\u4f4d\u540e\u7f00\u3002\u4e0b\u4f8b\u4e3a\u6267\u884c\u7684\u64cd\u4f5c\uff1a<\/p>\n<p>PS C:\\&gt; Get-Process | where {$_.WS -ge 50MB}<\/p>\n<p>Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName<\/p>\n<p>&#8212;&#8212;- &#8212;&#8212; &#8212;&#8211; &#8212;&#8211; &#8212;&#8211; &#8212;&#8212; &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p>839 34 68096 191316 434 60.00 6912 JAVAW<\/p>\n<p>3062 32 61180 70812 237 88.36 7800 Mysql<\/p>\n<p>396 20 39556 56200 569 303.36 2684 WINWORD<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5f53\u524d\u7cfb\u7edf\u7531\u4e8eOracle\u6570\u636e\u5e93\uff08Oracle\u4f7f\u7528Java\u865a\u62df\u673a\u5b9e\u73b0\u8de8\u5e73\u53f0\u64cd\u4f5c\uff0c\u8fd9\u91cc\u7684javaw\u5373\u5176\u8fdb\u7a0b\uff09\u5360\u7528\u4e86\u5927\u91cf\u7684\u5206\u9875\u5185\u5b58\uff0c\u6240\u4ee5\u5bfc\u81f4\u7cfb\u7edf\u8fd0\u884c\u901f\u5ea6\u53d8\u6162\u3002<\/p>\n<p><strong>2 \u542f\u52a8\u548c\u505c\u6b62\u8fdb\u7a0b<\/strong><\/p>\n<p>PowerShell\u4e2d\u6240\u6709\u4e0e\u8fdb\u7a0b\u76f8\u5173\u7684\u64cd\u4f5c\u5747\u901a\u8fc7\u8c03\u7528.NET\u7684System.Diagnostics.Process\u5bf9\u8c61\u6765\u5b9e\u73b0\uff0c\u542f\u52a8\u8fdb\u7a0b\u53ea\u9700\u8981\u952e\u5165\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u6587\u4ef6\u540d\u3002\u4e3a\u83b7\u53d6\u8fdb\u7a0b\u5bf9\u8c61\u7684\u5b9e\u4f8b\u53e5\u67c4\uff0c\u4ee5\u4fbf\u540e\u9762\u5bf9\u5176\u8fdb\u884c\u64cd\u4f5c\uff0c\u6267\u884cGet-Process\u547d\u4ee4\uff1a<\/p>\n<p>PS C:\\&gt; notepad<\/p>\n<p>PS C:\\&gt; Get-Process notepad<\/p>\n<p>Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName<\/p>\n<p>&#8212;&#8212;- &#8212;&#8212; &#8212;&#8211; &#8212;&#8211; &#8212;&#8211; &#8212;&#8212; &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p>48 3 1668 4020 32 0.14 2400 notepad<\/p>\n<p>\u5982\u679c\u5df2\u7ecf\u542f\u52a8\u4e86\u591a\u4e2anotepad\u5b9e\u4f8b\uff0c\u5219\u83b7\u53d6\u5bf9\u5e94\u7684\u5b9e\u4f8b\u53ef\u4ee5\u901a\u8fc7\u8fdb\u7a0bID\u6216StartTime\u5c5e\u6027\uff0c\u4f46\u662f\u8fd9\u5e76\u4e0d\u662f\u6700\u5b89\u5168\u7684\u4e00\u79cd\u9014\u5f84\u3002\u5982\u5728\u542f\u52a8Notepad\u4e4b\u540e\uff0c\u8fd0\u884cGet-Process cmdlet\u4e4b\u524d\uff0c\u8ba1\u7b97\u673a\u7684\u5176\u4ed6\u7528\u6237\u542f\u52a8\u4e86Notepad\u5b9e\u4f8b\uff0c\u5219\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\u83b7\u53d6\u7684\u521a\u521a\u542f\u52a8\u7684\u8fdb\u7a0b\u5e76\u4e0d\u662f\u6240\u9700\u3002\u83b7\u53d6\u521a\u521a\u542f\u52a8\u8fdb\u7a0b\u53e5\u67c4\u7684\u6700\u5b89\u5168\u65b9\u6cd5\u662f\u5728\u542f\u52a8\u65f6\u4f7f\u7528Process.Start()\u9759\u6001\u65b9\u6cd5\uff0c\u5b83\u4f1a\u8fd4\u56de\u6700\u65b0\u542f\u52a8\u7684\u8fdb\u7a0b\u53e5\u67c4\uff0c\u5982\uff1a<\/p>\n<p>PS C:\\&gt; $notepad = [Diagnostics.Process]::Start(&quot;notepad.exe&quot;)<\/p>\n<p>PS C:\\&gt; $notepad<\/p>\n<p>Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName<\/p>\n<p>&#8212;&#8212;- &#8212;&#8212; &#8212;&#8211; &#8212;&#8211; &#8212;&#8211; &#8212;&#8212; &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p>44 3 1632 4000 32 0.19 2564 notepad<\/p>\n<p>\u5982\u679c\u4e0d\u8003\u8651\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u4f1a\u4e22\u5931\u6570\u636e\uff0c\u5219\u7ec8\u6b62\u8fdb\u7a0b\u53ef\u4ee5\u4f7f\u7528\u8fdb\u7a0b\u7684Kill\u65b9\u6cd5$notepad.Kill()\u6216\u8005\u4f20\u9012\u8fdb\u7a0b\u5b9e\u4f8b\u7ed9Stop-Process cmdlet\u6740\u6b7b\u8fdb\u7a0b\uff0c\u5982Get-Process notepad | Stop-Process\u3002\u5728\u4e0d\u4e22\u5931\u6570\u636e\u7684\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5c1d\u8bd5\u8c03\u7528CloseMainWindow\u65b9\u6cd5\u901a\u77e5\u8fdb\u7a0b\u5728\u9000\u51fa\u4e4b\u524d\u63d0\u793a\u4fdd\u5b58\u3002\u5982\u679c\u5df2\u7ecf\u4fdd\u5b58\uff0c\u5219\u76f4\u63a5\u7ec8\u6b62\u8be5\u8fdb\u7a0b\u3002\u4e0b\u4f8b\u5c1d\u8bd5\u5173\u95edNotepad\u7a97\u53e3\uff0c\u7b49\u5f855\u79d2\u3002\u5982\u679c\u6ca1\u6709\u4fdd\u5b58\uff0c\u5219\u9000\u51fa\u65f6\u4f1a\u63d0\u793a\u4fdd\u5b58\uff1b\u5426\u5219\u76f4\u63a5\u7ec8\u6b62\uff1a<\/p>\n<p>PS C:\\&gt; notepad<\/p>\n<p>PS C:\\&gt; function KillNotepad()<\/p>\n<p>&gt;&gt; {<\/p>\n<p>&gt;&gt; $notepad = Get-Process notepad<\/p>\n<p>&gt;&gt; echo &quot;Trying to closee the process window&#8230;&quot;<\/p>\n<p>&gt;&gt; $messageSend = $notepad.CloseMainWindow()<\/p>\n<p>&gt;&gt; sleep 5<\/p>\n<p>&gt;&gt; if(!$notepad.HasExited)<\/p>\n<p>&gt;&gt; {<\/p>\n<p>&gt;&gt; echo &quot;Forcing process termination.&quot;<\/p>\n<p>&gt;&gt; Stop-Process -Input $notepad<\/p>\n<p>&gt;&gt; }<\/p>\n<p>&gt;&gt; else<\/p>\n<p>&gt;&gt; {<\/p>\n<p>&gt;&gt; echo &quot;Process exited gracefully&quot;<\/p>\n<p>&gt;&gt; }<\/p>\n<p>&gt;&gt; }<\/p>\n<p>&gt;&gt; <\/p>\n<p>PS C:\\&gt; killnotepad<\/p>\n<p>Trying to closee the process window&#8230;<\/p>\n<p>Process exited gracefully<\/p>\n<p>\u5728\u7a0b\u5e8f\u4e2d\uff0cCloseMainWindow\u4ec5\u8fd4\u56de\u4e00\u4e2a\u662f\u5426\u5df2\u7ecf\u5411\u76ee\u6807\u8fdb\u7a0b\u53d1\u9001\u5173\u95ed\u7a97\u53e3\u4fe1\u53f7\u7684\u6807\u5fd7\u3002\u4e3a\u4e86\u5224\u522b\u8fdb\u7a0b\u662f\u5426\u6210\u529f\u9000\u51fa\uff0c\u5176\u4e2d\u4f7f\u7528\u4e86HasExited\u5c5e\u6027\u3002<\/p>\n<p><strong>3 \u8fdb\u7a0b\u53ca\u5176\u7a97\u53e3<\/strong><\/p>\n<p>\u7528\u6237\u4e0d\u80fd\u76f4\u63a5\u4e0eWindows\u4ea4\u4e92\u5e76\u4f20\u9012\u6d88\u606f\uff0c\u4f46\u662f\u5bf9\u4e8e\u6765\u6e90\u4e8e.NET\u547d\u540d\u7a7a\u95f4System.Windows.Forms\u7684\u811a\u672c\u5bf9\u8c61\u6765\u8bf4\u5219\u53ef\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fdb\u7a0b\u7c7b\u5bf9\u5916\u5f00\u653e\u7684MainWindowTitle\u5c5e\u6027\u6765\u533a\u5206\u76f8\u540c\u7a0b\u5e8f\u7684\u4e0d\u540c\u5b9e\u4f8b\u3002\u5982\u679c\u8981\u83b7\u53d6\u5230\u6240\u6709Google\u641c\u7d22\u7684\u6d4f\u89c8\u5668\u7a97\u53e3\uff0c\u5219\u53ef\u901a\u8fc7\u83b7\u53d6\u7a97\u53e3\u6807\u9898\u6765\u5b9e\u73b0\uff1a<\/p>\n<p>PS C:\\&gt; Get-Process |where {$_.MainWindowTitle -Like &quot;*google*&quot;}<\/p>\n<p>Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName<\/p>\n<p>&#8212;&#8212;- &#8212;&#8212; &#8212;&#8211; &#8212;&#8211; &#8212;&#8211; &#8212;&#8212; &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p>584 19 16680 26420 122 3.38 2140 iexplore<\/p>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7a97\u53e3\u6807\u9898\u5305\u542b\u6587\u6863\u540d\u3001\u6587\u4ef6\u540d\u6216\u8005\u5176\u4ed6\u91cd\u8981\u6570\u636e\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u7528MainWindowTitle\u5c5e\u6027\u4f5c\u4e3a\u7a97\u4f53\u7684\u6807\u8bc6\u7b26\u3002<\/p>\n<p>\u53e6\u5916\u4e00\u4e2a\u4e0e\u7528\u6237\u754c\u9762\u76f8\u5173\u7684\u8fdb\u7a0b\u5c5e\u6027\u662fResponding\uff0c\u5982\u679c\u7a0b\u5e8f\u54cd\u5e94\u7528\u6237\u8f93\u5165\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u5c5e\u6027\u83b7\u53d6\u6240\u6709\u6302\u8d77\u7684\u8fdb\u7a0b\u5e76\u6740\u6b7b\u3002\u5982\u679c\u5e76\u4e0d\u5e0c\u671b\u6740\u6b7b\u6240\u6709\u6302\u8d77\u7684\u65e0\u54cd\u5e94\u8fdb\u7a0b\uff0c\u5219\u6bd4\u8f83\u597d\u7684\u9009\u62e9\u662f\u83b7\u53d6\u6302\u8d77\u7684\u8fdb\u7a0b\u5e76\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u3002\u5982\u679c\u4ecd\u7136\u6ca1\u6709\u54cd\u5e94\uff0c\u5219\u5c06\u5176\u6740\u6b7b\uff0c\u5982\uff1a<\/p>\n<p>PS C:\\&gt; function waitforkill()<\/p>\n<p>&gt;&gt; {<\/p>\n<p>&gt;&gt; $before = (Get-Process | where {$_.Responding -eq $false})<\/p>\n<p>&gt;&gt; sleep 10<\/p>\n<p>&gt;&gt; $after = (Get-Process | where {$_.Responding -eq $false})<\/p>\n<p>&gt;&gt; if(($before -ne $null) -and ($after -ne $null))<\/p>\n<p>&gt;&gt; {<\/p>\n<p>&gt;&gt; diff $before $after -IncludeEqual |<\/p>\n<p>&gt;&gt; where {$_.SildIndicator -eq &quot;==&quot;} |<\/p>\n<p>&gt;&gt; foreach {$_.InputObject | Stop-Process}<\/p>\n<p>&gt;&gt; }<\/p>\n<p>&gt;&gt; }<\/p>\n<p>&gt;&gt; <\/p>\n<p>PS C:\\&gt; waitforkill<\/p>\n<p>\u4e0a\u4f8b\u9996\u5148\u83b7\u53d6\u6302\u8d77\u7684\u8fdb\u7a0b\uff0c\u7b49\u5f8510\u79d2\u3002\u518d\u6b21\u83b7\u53d6\uff0c\u4e24\u6b21\u7ed3\u679c\u7684\u4ea4\u96c6\u96c6\u5408\u5373\u9700\u8981\u6e05\u9664\u7684\u50f5\u6b7b\u8fdb\u7a0b\u3002\u9700\u8981\u5f3a\u8c03\u7684\u662f-includeEqual\u9009\u9879\u7528\u4e8e\u6bd4\u8f83\u96c6\u5408\u4e4b\u95f4\u7684\u5dee\u5f02\uff0c\u5e76\u4e14\u6821\u9a8cSideIndicator\u503c\u4e3a\u201c==\u201d\u3002\u6574\u4e2a\u8bed\u53e5\u7684\u542b\u4e49\u4e3a\u5bf9\u8c61\u5728\u4e24\u8fb9\u7684\u96c6\u5408\u4e2d\u5747\u5b58\u5728\uff0c\u800c\u4e14\u65e0\u6cd5\u572810\u79d2\u949f\u5185\u6062\u590d\u7684\u8fdb\u7a0b\u5219\u8ba4\u4e3a\u662f\u50f5\u6b7b\u7684\u8fdb\u7a0b\u3002<\/p>\n<p><strong>4 \u83b7\u53d6\u8fdb\u7a0b\u4f9d\u8d56\u7684\u5e93<\/strong><\/p>\n<p>\u8fdb\u7a0b\u6a21\u5757\u6307\u6240\u6709\u88ab\u8f7d\u5165\u8fdb\u7a0b\u5185\u5b58\u7a7a\u95f4\u4e2d\u7684DLL\u6216\u8005exe\u6587\u4ef6\uff0cPowerShell\u4e2d\u7684Process\u7c7b\u6709\u4e24\u4e2a\u5c5e\u6027\u7528\u4e8e\u64cd\u4f5c\u6a21\u5757\uff0c\u5373MainModule\u548cModules\u3002\u4e3b\u6a21\u5757\u901a\u5e38\u662f\u542f\u52a8\u8fdb\u7a0b\u7684exe\u6587\u4ef6\uff0c\u6a21\u5757\u96c6\u5408\u5305\u542b\u6240\u6709\u88ab\u8f7d\u5165\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7MainModule\u5c5e\u6027\u83b7\u53d6\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u5982\u4e0b\u4f8b\u83b7\u53d6PowerShell\u7684\u5b58\u653e\u4f4d\u7f6e\uff1a<\/p>\n<p>PS C:\\&gt; (Get-process powershell).MainModule.FileName<\/p>\n<p>C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\PowerShell.exe<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528Modules\u96c6\u5408\u67e5\u627e\u4e00\u4e2a\u8fdb\u7a0b\u4f9d\u8d56\u7684\u5e93\uff0c\u4e0b\u4f8b\u83b7\u53d6\u8ba1\u7b97\u5668\u4f9d\u8d56\u7684\u5e93\u6e05\u5355\uff1a<\/p>\n<p>PS C:\\&gt; (Get-Process calc).Modules<\/p>\n<p>Size(K) ModuleName FileName<\/p>\n<p>&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8211;<\/p>\n<p>124 calc.exe C:\\WINDOWS\\sys&#8230;<\/p>\n<p>588 ntdll.dll C:\\WINDOWS\\sys&#8230;<\/p>\n<p>1144 kernel32.dll C:\\WINDOWS\\sys&#8230;<\/p>\n<p>\u2026\u2026<\/p>\n<p>\u7528\u6237\u901a\u8fc7\u7279\u5b9a\u7684\u5e93\u53ef\u4ee5\u4e86\u89e3\u7a0b\u5e8f\u5982\u4f55\u5de5\u4f5c\uff0cPowerShell\u751a\u81f3\u5141\u8bb8\u7528\u6237\u751f\u6210\u591a\u79cd\u7279\u5b9a\u62a5\u544a\u4ee5\u53d1\u73b0\u7c7b\u4f3c\u7684\u7a0b\u5e8f\u3002\u5982\u6240\u6709\u4f7f\u7528mscoree.dll\u7684\u7a0b\u5e8f\u662f.NET\u8fdb\u7a0b\uff0c\u4e0b\u4f8b\u83b7\u53d6\u4f7f\u7528\u52a8\u6001\u5e93\u7684\u8fdb\u7a0b\u6e05\u5355\uff1a<\/p>\n<p>PS C:\\&gt; Get-Process | foreach { $proc = $_;$proc.Modules|<\/p>\n<p>&gt;&gt; where { $_.ModuleName -eq &quot;mscoree.dll&quot;} |<\/p>\n<p>&gt;&gt; foreach {echo $proc}<\/p>\n<p>&gt;&gt; }<\/p>\n<p>&gt;&gt; <\/p>\n<p>Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName<\/p>\n<p>&#8212;&#8212;- &#8212;&#8212; &#8212;&#8211; &#8212;&#8211; &#8212;&#8211; &#8212;&#8212; &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p>778 18 21576 27624 146 599.81 424 explorer<\/p>\n<p>813 27 27144 37196 151 3,525.66 1236 explorer<\/p>\n<p>916 34 72660 60356 439 189.63 6912 FetionFx<\/p>\n<p>1555 29 80752 66632 276 838.36 2140 iexplore<\/p>\n<p>793 6 28448 19324 146 10.09 4060 powershell<\/p>\n<p>\u4e0a\u4f8b\u4e2d\u7684\u7b2c1\u4e2aforeach\u904d\u5386\u8c03\u7528\u6240\u6709\u7684\u8fdb\u7a0b\u5e76\u83b7\u53d6\u6240\u6709\u6a21\u5757\uff0c\u7136\u540e\u5c06\u6240\u6709\u7684\u8fdb\u7a0b\u5bf9\u8c61\u4fdd\u5b58\u5728$proc\u7f13\u5b58\u53d8\u91cf\u4e2d\uff0c\u6700\u540e\u7528where cmdlet\u4ece\u8fdb\u7a0b\u6e05\u5355\u4e2d\u83b7\u53d6\u5305\u542bmscoree.dll\u6a21\u5757\uff1b\u7b2c2\u4e2aforeach\u8f93\u51fa\u6240\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u8fdb\u7a0b\u3002<\/p>\n<p><strong>5 \u83b7\u53d6\u7a0b\u5e8f\u53d1\u5e03\u7684\u76f8\u5173\u4fe1\u606f<\/strong><\/p>\n<p>\u8bfb\u8005\u53ef\u80fd\u6709\u8fc7\u53d1\u73b0\u53ef\u7591\u540d\u79f0\u7684\u8fdb\u7a0b\uff0c\u6700\u540e\u88ab\u786e\u8ba4\u4e3a\u95f4\u8c0d\u7a0b\u5e8f\u6216\u662f\u75c5\u6bd2\u7684\u7ecf\u5386\u3002\u5982\u679c\u80fd\u6b63\u5e38\u5730\u4f7f\u7528\u6740\u6bd2\u8f6f\u4ef6\u5e76\u7ecf\u5e38\u5347\u7ea7\uff0c\u4e5f\u8bb8\u80fd\u907f\u514d\u8fd9\u4e9b\u60c5\u51b5\u7684\u53d1\u751f\u3002\u9664\u6b64\u4ee5\u5916\uff0c\u53ef\u4ee5\u68c0\u67e5\u8fdb\u7a0b\u5c5e\u6027\u5305\u542b\u516c\u53f8\u3001\u4ea7\u54c1\u548c\u4ea7\u54c1\u7248\u672c\u7684\u8fd4\u56de\u503c\u3002\u5c3d\u7ba1\u8fd9\u4e9b\u5185\u5bb9\u4e5f\u6709\u53ef\u80fd\u88ab\u6076\u610f\u7528\u6237\u5047\u9020\uff0c\u4f46\u8fd8\u662f\u53ef\u4ee5\u5728\u4e00\u5b9a\u8303\u56f4\u5185\u6821\u9a8c\u7a0b\u5e8f\u7684\u6765\u6e90\u3002\u5982\u679c\u8981\u786e\u4fdd\u7a0b\u5e8f\u7684\u5408\u6cd5\u6027\u548c\u5b8c\u6574\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u7a0b\u5e8f\u7684\u6570\u5b57\u7b7e\u540d\u6765\u4fdd\u8bc1\u3002<\/p>\n<p>\u4e0b\u4f8b\u83b7\u53d6\u5f53\u524d\u8ba1\u7b97\u673a\u4e2d\u90e8\u5206\u8fd0\u884c\u7a0b\u5e8f\u7684\u53d1\u5e03\u4fe1\u606f\u6e05\u5355\uff1a<\/p>\n<p>PS C:\\PowerShell&gt; Get-Process |select Company,Product,ProductVersion |format-tab<\/p>\n<p>le<\/p>\n<p>Company Product ProductVersion<\/p>\n<p>&#8212;&#8212;- &#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>Adobe Systems Incorporated Adobe Reader 7.0.5.2005092300<\/p>\n<p>Microsoft Corporation Microsoft\u00ae Windows\u00ae Ope&#8230; 5.1.2600.5512<\/p>\n<p>ASUSTeK Computer Inc. AsAcpiSvr.exe 5, 1, 1, 3012<\/p>\n<p>ASUSTeK Computer Inc. AsEPCMon 5, 1, 1, 1002<\/p>\n<p>ASUSTeK Computer Inc. AsTray 5, 1, 1, 3015<\/p>\n<p>Broadcom Corporation. Bluetooth Software 5.5.0.3200<\/p>\n<p>Microsoft Corporation Microsoft(R) Windows(R)&#8230; 5.1.2600.0<\/p>\n<p>Microsoft Corporation Microsoft\u00ae Windows\u00ae Ope&#8230; 5.1.2600.5512<\/p>\n<p><strong>6 \u8bbe\u7f6e\u8fdb\u7a0b\u4f18\u5148\u7ea7<\/strong><\/p>\n<p>\u63d0\u9ad8\u6216\u964d\u4f4e\u7a0b\u5e8f\u8fd0\u884c\u7684\u4f18\u5148\u7ea7\u662f\u5f88\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u5f53\u5b89\u88c5\u5927\u578b\u7a0b\u5e8f\u65f6\uff0c\u53ef\u80fd\u65f6\u95f4\u4f1a\u6bd4\u8f83\u957f\u3002\u5f88\u591a\u7528\u6237\u53ef\u80fd\u4f1a\u5728\u5b89\u88c5\u6587\u4ef6\u7684\u540c\u65f6\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u628a\u5b89\u88c5\u7684\u4f18\u5148\u7ea7\u964d\u4f4e\uff0c\u4f7f\u5176\u4ed6\u7a0b\u5e8f\u6b63\u5e38\u8fd0\u884c\u3002\u5982\u679c\u6b64\u65f6\u4e0d\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\uff0c\u5219\u53ef\u4ee5\u628a\u5b89\u88c5\u7a0b\u5e8f\u7684\u4f18\u5148\u7ea7\u63d0\u9ad8\uff0c\u4f7f\u5b89\u88c5\u5c3d\u5feb\u5b8c\u6210\u3002<\/p>\n<p>\u5728PowerShell\u4e2d\u901a\u8fc7\u8bbe\u7f6ePriorityClass\u679a\u4e3e\u5c5e\u6027\u6765\u6539\u53d8\u8fdb\u7a0b\u4f18\u5148\u7ea7\uff0c\u53ef\u901a\u8fc7\u4f20\u9012\u7c7b\u4f3c \u201cBelowNormal\u201d\u53ca\u201cNormal\u201d\u7b49\u5b57\u7b26\u4e32\u6765\u5b9e\u73b0\u3002\u4e0b\u4f8b\u964d\u4f4e\u5b89\u88c5\u7a0b\u5e8fmsiexec.exe\u7684\u4f18\u5148\u7ea7\uff1a<\/p>\n<p>PS C:\\PowerShell&gt; function LowerPriority()<\/p>\n<p>&gt;&gt; {<\/p>\n<p>&gt;&gt; echo &quot;Lowering installer process priorities&quot;<\/p>\n<p>&gt;&gt; Get-Process msiexec -ErrorAction Stop |<\/p>\n<p>&gt;&gt; foreach {$_.PriorityClass = &quot;BelowNormal&quot;}<\/p>\n<p>&gt;&gt; Read-Host -Prompt &quot;Press Enter to restore install priorities&quot;<\/p>\n<p>&gt;&gt; Get-Process msiexec -ErrorAction SilentlyContinue |<\/p>\n<p>&gt;&gt; foreach { $_.PriorityClass = &quot;Normal&quot;}<\/p>\n<p>&gt;&gt; }<\/p>\n<p>&gt;&gt; <\/p>\n<p>PS C:\\PowerShell&gt; Lowerpriority<\/p>\n<p>\u6267\u884c\u4e0a\u8ff0\u811a\u672c\u540e\u4f1a\u91cd\u65b0\u5bfc\u5165\u7a0b\u5e8f\u4f18\u5148\u7ea7\u5230Normal\u7ea7\u522b\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd0\u884c\u7684msiexec.exe\u8fdb\u7a0b\uff0c\u5219\u5e0c\u671b\u811a\u672c\u6267\u884c\u5931\u8d25\u3002\u800c\u5f53\u7b49\u5f85\u5b89\u88c5\u5b8c\u6210\u540e\u5ffd\u7565\u6240\u6709\u9519\u8bef\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4f7f\u7528ErrorAction\u53c2\u6570\u3002\u9700\u8981\u5f3a\u8c03\u7684\u662f\u5b89\u88c5\u7a0b\u5e8f\u9700\u8981\u7ba1\u7406\u5458\u6743\u9650\uff0c\u56e0\u6b64\u5fc5\u987b\u5728\u7ba1\u7406\u5458\u8d26\u6237\u4e0b\u6267\u884c\u4e0a\u8ff0\u811a\u672c\u3002<\/p>\n<p><strong>7 \u603b \u7ed3<\/strong><\/p>\n<p>\u8fdb\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7528\u4e8e\u5904\u7406\u6570\u636e\u548c\u8fdb\u7a0b\u95f4\u7684\u4ea4\u6362\uff0cPowerShell\u7684\u8fdb\u7a0b\u548c\u670d\u52a1\u7ba1\u7406\u673a\u5236\u80fd\u5206\u6790\u8fdb\u7a0b\u4fe1\u606f\uff0c\u5e76\u4e14\u76f4\u63a5\u64cd\u4f5c\u8fdb\u7a0b\u5b9e\u4f8b\u6307\u5411\u7684\u5bf9\u8c61\u3002\u672c\u6587\u8bb2\u8ff0\u4e86\u5982\u4f55\u4f7f\u7528PowerShell\u7edf\u4e00\u8bbf\u95ee\u8fdb\u7a0b\u7684\u65b9\u6cd5\u5e76\u521b\u5efa\u5728PowerShell\u4e2d\u64cd\u4f5c\u8fdb\u7a0b\u7684\u73af\u5883\uff0c\u8fd9\u662f\u7cfb\u7edf\u7ba1\u7406\u81ea\u52a8\u5316\u7684\u91cd\u8981\u6b65\u9aa4\u3002<\/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.shell.tor.hu\/\">http:\/\/txj.shell.tor.hu\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fdb\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7528\u4e8e\u5904\u7406\u6570\u636e\u548c\u8fdb\u7a0b\u95f4\u7684\u4ea4\u6362\uff0cPowerShell\u7684\u8fdb\u7a0b\u548c\u670d\u52a1\u7ba1\u7406\u673a\u5236\u80fd\u5206\u6790\u8fdb\u7a0b\u4fe1\u606f\uff0c\u5e76\u4e14\u76f4\u63a5\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],"tags":[],"class_list":["post-33140","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33140"}],"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=33140"}],"version-history":[{"count":1,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33140\/revisions"}],"predecessor-version":[{"id":33779,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33140\/revisions\/33779"}],"wp:attachment":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}