{"id":1057,"date":"2022-10-04T13:21:13","date_gmt":"2022-10-04T05:21:13","guid":{"rendered":"https:\/\/benson.ml\/?p=1057"},"modified":"2022-10-04T13:46:14","modified_gmt":"2022-10-04T05:46:14","slug":"win10%e6%b8%85%e9%99%a4powershell%e5%8e%86%e5%8f%b2%e8%ae%b0%e5%bd%95%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/benson80.eu.org\/?p=1057","title":{"rendered":"\u5982\u4f55\u6709\u6548\u6e05\u7a7aPowerShell\u4e2dPSReadline\u7684\u6240\u6709\u5386\u53f2\u7eaa\u5f55"},"content":{"rendered":"\n<p>\u6e05\u9664\u4e00\u4e2a PowerShell \u5de5\u4f5c\u9636\u6bb5 (Session) \u7684\u5386\u53f2\u7eaa\u5f55<\/p>\n\n\n\n<p>\u4f60\u6bcf\u6b21\u5f00\u542f\u4e00\u4e2a PowerShell \u89c6\u7a97\uff0c\u5c31\u4f1a\u5efa\u7acb\u4e00\u4e2a\u5de5\u4f5c\u9636\u6bb5 (Session)\uff0c\u800c\u6bcf\u4e2a\u5de5\u4f5c\u9636\u6bb5\u90fd\u4f1a\u7ef4\u62a4\u4e00\u4efd\u8f93\u5165\u547d\u4ee4\u7684\u5386\u53f2\u7eaa\u5f55\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e Windows 10 \u5f00\u59cb\uff0c\u9884\u8bbe PowerShell \u4f1a\u81ea\u52a8\u8f7d\u5165 PSReadLine \u6a21\u5757\uff0c\u5927\u5927\u5f3a\u5316\u4e86 PowerShell \u547d\u4ee4\u5217\u73af\u5883\u7684\u547d\u4ee4\u8f93\u5165\u80fd\u529b\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u4e2a\u547d\u4ee4\u7ba1\u7406\u8f93\u5165\u547d\u4ee4\u7684\u5386\u53f2\u7eaa\u5f55\uff1a<\/p>\n\n\n\n<p>1. \u53d6\u5f97\u5386\u53f2\u7eaa\u5f55 (Get-History)<\/p>\n\n\n\n<p>Get-History<\/p>\n\n\n\n<p>\u4f60\u4e5f\u53ef\u4ee5\u7528\u5185\u5efa\u7684 h \u522b\u540d (Alias)\uff0c\u76f4\u63a5\u8f93\u5165 h \u5c31\u53ef\u4ee5\u67e5\u8be2\u5386\u53f2\u7eaa\u5f55\uff1a<\/p>\n\n\n\n<p>h<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u663e\u793a\u5728\u753b\u9762\u4e0a\u7684\u8303\u4f8b\uff1a<\/p>\n\n\n\n<p>Id CommandLine<\/p>\n\n\n\n<p>&#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n\n\n\n<p>1 dir<br>2 cls<br>3 Get-Alias<\/p>\n\n\n\n<p>2. \u6267\u884c\u5386\u53f2\u547d\u4ee4 (Invoke-History)<\/p>\n\n\n\n<p>Invoke-History 3<\/p>\n\n\n\n<p>\u4f60\u4e5f\u53ef\u4ee5\u7528\u5185\u5efa\u7684 r \u522b\u540d (Alias)\uff0c\u76f4\u63a5\u8f93\u5165 r &lt;Id&gt; \u5c31\u53ef\u4ee5\u67e5\u8be2\u5386\u53f2\u7eaa\u5f55\uff1a<\/p>\n\n\n\n<p>r 3<\/p>\n\n\n\n<p>3. \u6e05\u9664\u5386\u53f2\u7eaa\u5f55 (Clear-History)<\/p>\n\n\n\n<p>Clear-History<\/p>\n\n\n\n<p>\u53e6\u5916\u6709\u4e2a Alt-F7 \u952e\u76d8\u5feb\u901f\u952e\uff0c\u5f53\u4f60\u6309\u4e0b\u4e4b\u540e\uff0c\u5e76\u4e0d\u4f1a\u6e05\u9664\u6240\u6709\u5386\u53f2\u7eaa\u5f55\uff0c\u800c\u662f\u8ba9\u4f60\u4e0d\u80fd\u7528 \u2b06 \u65b9\u5411\u952e\u8f7d\u5165\u4e4b\u524d\u8f93\u5165\u8fc7\u7684\u547d\u4ee4\uff01<\/p>\n\n\n\n<p>\u6e05\u9664\u6240\u6709 PowerShell \u8f93\u5165\u8fc7\u7684\u547d\u4ee4\u5386\u53f2\u7eaa\u5f55<\/p>\n\n\n\n<p>\u5176\u5b9e\u7ba1\u7406\u4e00\u4e2a\u5de5\u4f5c\u9636\u6bb5\u7684\u5386\u53f2\u7eaa\u5f55\u4e0d\u600e\u4e48\u5b9e\u7528\uff0c\u56e0\u4e3a PSReadLine \u9884\u8bbe\u4f1a\u8bb0\u5fc6\u4f60\u6709\u53f2\u4ee5\u6765\u6240\u6709\u8f93\u5165\u8fc7\u7684\u547d\u4ee4\uff0c\u6240\u4ee5\u4f60\u4e0b\u6b21\u91cd\u5f00 PowerShell \u53c8\u53ef\u4ee5\u641c\u5bfb\u5230\u6240\u6709\u7684\u5386\u53f2\u7eaa\u5f55\uff01\u4e8b\u5b9e\u4e0a\uff0c\u4f60\u5728 PowerShell \u89c6\u7a97\u8f93\u5165\u7684\u6240\u6709\u547d\u4ee4\uff0c\u5168\u90e8\u90fd\u8bb0\u5f55\u5230\u4e00\u4e2a\u6587\u5b57\u6863\u4e2d\uff0c\u4f60\u53ef\u4ee5\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u51fa\u8be5\u6863\u6848\u7684\u8def\u5f84\uff1a<\/p>\n\n\n\n<p>(Get-PSReadlineOption).HistorySavePath<\/p>\n\n\n\n<p>\u9884\u8bbe\u5e94\u8be5\u662f\u8fd9\u4e2a\u8def\u5f84\uff1a<\/p>\n\n\n\n<p>$env:APPDATA\\Microsoft\\Windows\\PowerShell\\PSReadLine\\ConsoleHost_history.txt<\/p>\n\n\n\n<p>\u6211\u7684\u8fd9\u4e2a\u6863\u6848\u6709 13,370 \u884c\uff0c\u53ef\u4ee5\u60f3\u8c61\u91cc\u9762\u5305\u542b\u4e86\u591a\u5c11\u4e1c\u897f\uff0c\u4f46\u8fd9\u4e2a\u673a\u5236\u975e\u5e38\u5355\u7eaf\uff0c\u8fd9\u53cd\u800c\u53ef\u4ee5\u8ba9\u6211\u60f3\u51fa\u66f4\u591a\u79cd\u5e94\u7528\uff1a<\/p>\n\n\n\n<p>1. \u4f60\u53ef\u4ee5\u624b\u52a8\u6e05\u9664\u6240\u6709\u4e0d\u60f3\u4fdd\u7559\u5728\u5386\u53f2\u7eaa\u5f55\u4e2d\u7684\u547d\u4ee4<\/p>\n\n\n\n<p>    \u4f8b\u5982\u4f60\u66fe\u7ecf\u8f93\u5165\u8fc7\u7684\u91d1\u94a5\u6216\u5bc6\u7801\uff0c\u90fd\u5e94\u8be5\u627e\u51fa\u6765\u6e05\u7a7a\u3002<\/p>\n\n\n\n<p>2. \u4f60\u53ef\u4ee5\u52a0\u5165\u6240\u6709\u4f60\u5e0c\u671b\u672a\u6765\u53ef\u4ee5\u968f\u65f6\u67e5\u8be2\u5230\u7684\u547d\u4ee4<\/p>\n\n\n\n<p>    \u6709\u5f88\u591a\u5e38\u89c1\u7684\u547d\u4ee4\uff0c\u53ef\u4ee5\u6574\u7406\u4e00\u904d\uff0c\u8fd9\u6837\u4e4b\u540e\u8981\u8f93\u5165\u547d\u4ee4\u5c31\u4f1a\u53d8\u7684\u975e\u5e38\u5b9e\u7528\uff01<\/p>\n\n\n\n<p>\u4e0d\u8fc7 PSReadLine \u6709\u4e2a MaximumHistoryCount \u9009\u9879\u8bbe\u5b9a\uff0c\u5b9a\u4e49\u80fd\u8f7d\u5165\u7684\u6700\u5927\u5386\u53f2\u547d\u4ee4\u7684\u6570\u91cf\uff1a<\/p>\n\n\n\n<p>(Get-PSReadLineOption).MaximumHistoryCount<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u8bbe\u5b9a\u7684\u9884\u8bbe\u503c\u4e3a 4,096 \u7b14\uff0c\u56e0\u6b64\u5f53\u4f60\u5f00\u542f PowerShell \u4e4b\u540e\uff0c\u5e76\u4e0d\u4f1a\u771f\u7684\u8f7d\u5165 13,370 \u884c\u547d\u4ee4\uff0c\u800c\u662f\u53ea\u4f1a\u8f7d\u5165\u547d\u4ee4\u6700\u540e\u9762\u7684 4,096 \u884c\u800c\u5df2\u3002\u82e5\u4f60\u8981\u52a0\u5165\u4e00\u4e9b\u81ea\u5df1\u5e0c\u671b\u5728\u672a\u6765\u53ef\u4ee5\u67e5\u5230\u7684\u547d\u4ee4\uff0c\u5efa\u8bae\u76f4\u63a5\u52a0\u5230\u8be5\u6863\u6848\u7684\u6700\u540e\u9762\uff01<\/p>\n\n\n\n<p>\u5982\u4f55\u6e05\u9664PowerShell\u5386\u53f2\u8bb0\u5f55\uff1f<\/p>\n\n\n\n<p>\u6253\u5f00PowerShell\uff0c\u8fd0\u884c\u547d\u4ee4\uff1a Remove-Item (Get-PSReadlineOption).HistorySavePath \u9700\u8981\u5173\u95ed\u7a97\u53e3\uff0c\u518d\u6253\u5f00\u7a97\u53e3\u7528\u952e\u76d8\u4e0a\u4e0b\u952e\u5c31\u4e0d\u4f1a\u51fa\u73b0\u4e86\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6e05\u9664\u4e00\u4e2a PowerShell \u5de5\u4f5c\u9636\u6bb5 (Ses &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1057","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1057"}],"version-history":[{"count":7,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1057\/revisions"}],"predecessor-version":[{"id":1064,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1057\/revisions\/1064"}],"wp:attachment":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}