{"id":33116,"date":"2010-11-26T03:48:00","date_gmt":"2010-11-26T02:48:00","guid":{"rendered":"https:\/\/www.fuhaijun.com\/?p=33116"},"modified":"2024-11-06T11:21:43","modified_gmt":"2024-11-06T03:21:43","slug":"windows-powershell-2-0-%e5%bc%80%e5%8f%91%e4%b9%8b%e5%91%bd%e4%bb%a4%e5%88%ab%e5%90%8d","status":"publish","type":"post","link":"https:\/\/www.fuhaijun.com\/?p=33116","title":{"rendered":"Windows PowerShell 2.0 \u5f00\u53d1\u4e4b\u547d\u4ee4\u522b\u540d"},"content":{"rendered":"<p>UNIX shell\u7684\u7528\u6237\u5df2\u7ecf\u80fd\u591f\u4e3a\u547d\u4ee4\u6dfb\u52a0\u66f4\u7b80\u77ed\u548c\u53cb\u597d\u7684\u522b\u540d\uff0c\u4f46\u9057\u61be\u7684\u662fDOS\u57fa\u4e8e\u7684shell\uff0ccommand.com\u548ccmd.exe\u7f3a\u5c11\u8fd9\u4e2a\u7279\u6027\u3002\u800c\u5176\u4ed6\u7b2c\u4e09\u65b9\u5de5\u5177\uff0c\u5982doskey.exe\u5141\u8bb8\u7528\u6237\u4e3a\u547d\u4ee4\u5b9a\u4e49\u522b\u540d\uff0c\u4f46\u4e0d\u662f\u57fa\u4e8eshell\u7684\uff0c\u800c\u4e14\u7528\u6237\u9700\u8981\u8bb0\u5fc6\u96be\u8bb0\u7684\u8bed\u6cd5\u3002PowerShell\u6700\u7ec8\u586b\u8865\u4e86Windows shell\u7684\u8fd9\u4e2a\u7a7a\u767d\uff0c\u800c\u4e14\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684\u5bf9\u547d\u4ee4\u522b\u540d\u7684\u652f\u6301\u3002<\/p>\n<p>PowerShell\u63d0\u4f9b\u7684\u5927\u90e8\u5206\u547d\u4ee4\u5728\u521d\u59cb\u5316\u5b89\u88c5\u65f6\u521b\u5efa\uff0cVersion 2.0 CTP3\u63d0\u4f9b\u4e86\u767e\u4f59\u4e2a\u5185\u7f6e\u7684cmdlet\u3002\u4e0b\u4f8b\u68c0\u7d22\u5728\u7cfb\u7edf\u4e2d\u6ce8\u518c\u7684cmdlet\u7684\u6570\u76ee\uff1a<\/p>\n<pre>PS C:\\&gt;(Get-Command \u2013type Cmdlet).Length\n235<\/pre>\n<p>\u5728\u8fd9\u4e9b\u5185\u7f6e\u7684cmdlet\u4e2dPowerShell\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u7f16\u7a0b\u89c4\u5219\u548c\u5efa\u8bae\uff0c\u6240\u6709\u7684\u540d\u79f0\u548c\u53c2\u6570\u90fd\u662f\u4ee5\u4fbf\u4e8e\u7528\u6237\u5b66\u4e60\u548c\u4f7f\u7528\u7684\u65b9\u5f0f\u547d\u540d\u7684\u3002<\/p>\n<p>\u9664\u4e86\u90e8\u5206\u522b\u540d\u662f\u4e13\u4e3a\u5b9e\u73b0\u4e0e\u5176\u4ed6\u754c\u9762\u7684\u540d\u79f0\u517c\u5bb9\u6027\u800c\u8bbe\u8ba1\u7684\u4ee5\u5916\uff0c\u5176\u4ed6PowerShell\u4e2d\u7684\u5185\u7f6e\u522b\u540d\u901a\u5e38\u662f\u4e3a\u4e86\u7b80\u77ed\u6613\u7528\u800c\u8bbe\u8ba1\u7684\u3002\u8fd9\u4e9b\u7b80\u77ed\u7684\u540d\u79f0\u4fbf\u4e8e\u5feb\u901f\u952e\u5165\uff0c\u4f46\u662f\u5982\u679c\u4e0d\u4e86\u89e3\u5176\u542b\u4e49\uff0c\u5219\u65e0\u6cd5\u89e3\u8bfb\u3002<\/p>\n<p>\u901a\u8fc7\u63d0\u4f9b\u4e00\u7ec4\u57fa\u4e8e\u5e38\u7528\u52a8\u8bcd\u548c\u540d\u8bcd\u7684\u901f\u8bb0\u540d\u79f0\u7684\u6807\u51c6\u522b\u540d\uff0cPowerShell\u8bd5\u56fe\u5728\u6e05\u6670\u6027\u4e0e\u7b80\u77ed\u6027\u4e4b\u95f4\u53d6\u5f97\u5e73\u8861\u3002\u8fd9\u6837\u5728\u4e00\u7ec4\u5e38\u7528cmdlet \u7684\u6838\u5fc3\u522b\u540d\u4e2d\uff0c\u53ea\u9700\u4e86\u89e3\u901f\u8bb0\u540d\u79f0\u5373\u53ef\u89e3\u8bfb\u8fd9\u4e9b\u547d\u4ee4\u3002\u4f8b\u5982\uff0c\u5728\u6807\u51c6\u522b\u540d\u4e2d\u52a8\u8bcdGet\u7f29\u5199\u4e3ag\uff0c\u52a8\u8bcdSet\u7f29\u5199\u4e3as\uff0c\u540d\u8bcdItem\u7f29\u5199\u4e3ai\uff0c\u540d\u8bcdLocation \u7f29\u5199\u4e3al\uff0c\u800c\u540d\u8bcdCommand\u7f29\u5199\u4e3acm\u3002\u4ee5\u4e0b\u7b80\u77ed\u793a\u4f8b\u8bf4\u660e\u4e86\u8fd9\u4e00\u5de5\u4f5c\u673a\u5236\uff0cGet-Item \u7684\u6807\u51c6\u522b\u540d\u901a\u8fc7\u5c06\u8868\u793aGet\u7684g\u4e0e\u8868\u793aItem\u7684i\u7ec4\u5408\u800c\u83b7\u5f97\uff0c\u5373gi\uff1bSet-Item\u7684\u6807\u51c6\u522b\u540d\u901a\u8fc7\u5c06\u8868\u793aSet\u7684s\u4e0e\u8868\u793aItem\u7684i\u7ec4\u5408\u800c\u83b7\u5f97\uff0c\u5373si\uff1bGet-Location\u7684\u6807\u51c6\u522b\u540d\u901a\u8fc7\u5c06\u8868\u793aGet\u7684g\u4e0e\u8868\u793aLocation\u7684l\u7ec4\u5408\u800c\u83b7\u5f97\uff0c\u5373gl\uff1bSet-Location\u7684\u6807\u51c6\u522b\u540d\u901a\u8fc7\u5c06\u8868\u793aSet\u7684s\u4e0e\u8868\u793aLocation\u7684l\u7ec4\u5408\u800c\u83b7\u5f97\uff0c\u5373sl\uff1bGet-Command\u7684\u6807\u51c6\u522b\u540d\u662f\u901a\u8fc7\u5c06\u8868\u793aGet\u7684g\u4e0e\u8868\u793aCommand\u7684cm\u7ec4\u5408\u800c\u83b7\u5f97\uff0c\u5373gcm\u3002<\/p>\n<p><b>\u521b\u5efa\u522b\u540d<\/b><\/p>\n<p>\u522b\u540d\u7528\u6765\u5173\u8054\u67d0\u4e2a\u540d\u5b57\u548c\u67d0\u547d\u4ee4\uff0c\u5982\u679c\u8981\u7528\u6307\u5411Write-Host\u7684log\u522b\u540d\u6765\u5b9e\u73b0\u8f93\u51fa\uff0c\u9700\u8981\u8c03\u7528New-Alias\u8fd9\u4e2acmdlet\u6765\u5b9e\u73b0\uff1a<\/p>\n<pre>PS C:\\&gt;New-Alias log  Write-Host\nPS C:\\&gt;<\/pre>\n<p>\u63a5\u4e0b\u6765\u5373\u53ef\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u8fd9\u4e2a\u522b\u540d\uff1a<\/p>\n<pre>PS C:\\&gt; log \u201cOuput With log alias Operation Completed Successfully\u201d\nPS C:\\&gt; Ouput With log alias Operation Completed Successfully<\/pre>\n<p>\u5982\u679c\u522b\u540d\u5df2\u7ecf\u5b58\u5728\uff0cNew-Alias\u4f1a\u629b\u51fa\u9519\u8bef;<\/p>\n<pre>PS C:\\&gt; New-Alias log Get-ChildItem\nNew-Alias : Alias not allowed because an alias with the name \u2018log\u2019 already exists.\nAt line:1 char:10\n+ New-Alias  &lt;&lt;&lt;&lt; log Get-ChildItem<\/pre>\n<p>\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5\u522b\u540d\u6e05\u5355\u6765\u786e\u8ba4\u8981\u4f7f\u7528\u7684\u522b\u540d\u662f\u5426\u53ef\u7528\uff0c\u4f7f\u7528\u7684\u65b9\u6cd5\u4e3aGet-Alias\u3001Get-Command\u6216Alias\u63d0\u4f9b\u8005\u3002<\/p>\n<p>\uff081\uff09Get-Alias<\/p>\n<p>\u8fd9\u4e2acmdlet\u8fd4\u56de\u7cfb\u7edf\u4e2d\u6240\u6709\u7684\u522b\u540d\u6216\u6839\u636e\u4f20\u9012\u7ed9\u8fc7\u6ee4\u5668\u7684\u53c2\u6570\u53ea\u8fd4\u56de\u76f8\u5e94\u7684\u522b\u540d\uff0c\u4e0b\u4f8b\u8fd4\u56de\u6240\u6709\u4ee5l\u5f00\u5934\u7684\u522b\u540d\uff1a<\/p>\n<pre>PS C:\\&gt; Get-Alias l*\n\nCommandType     Name     Definition\n-----------------     ------      ---------\nAlias                lp         Out-Printer\nAlias                ls         Get-ChildItem\nAlias                lp         Out-Printer<\/pre>\n<p>\u53ef\u4ee5\u4f7f\u7528if\u8bed\u53e5\u5224\u65ad\u7279\u5b9a\u522b\u540d\u662f\u5426\u5b58\u5728\uff1a<\/p>\n<pre>PS C:\\&gt; if(Get-Alias log)\n&gt;&gt; {\n&gt;&gt;log \u201cAlias exists\u201d\n&gt;&gt; }\nAlias exists<\/pre>\n<p>\u4e0a\u4f8b\u5047\u8bbe\u4e4b\u524d\u5b9a\u4e49\u7684\u522b\u540d\u5b58\u5728\uff0c\u5219\u8f93\u51fa\u4fe1\u606f\uff1b\u5982\u679c\u672a\u8f93\u51fa\uff0c\u5219\u8bf4\u660e\u522b\u540d\u4e0d\u5b58\u5728\u6216\u8005log\u8fd9\u4e2a\u522b\u540d\u6307\u5411\u7684\u547d\u4ee4\u5e76\u4e0d\u662fWrite-Host\uff0c\u8fd9\u91cc\u4f7f\u7528\u8fd9\u4e2a\u6280\u5de7\u662f\u56e0\u4e3a\u4e4b\u524d\u5b9a\u4e49\u7684\u522b\u540dlog\u6307\u5411Write-Host\u3002<\/p>\n<p>\uff082\uff09Get-Command<\/p>\n<p>\u522b\u540d\u76f8\u5f53\u4e8e\u547d\u4ee4\u7684\u5feb\u6377\u65b9\u5f0f\uff0c\u4f7f\u7528Get-Command\u4e5f\u53ef\u627e\u51fa\uff0c\u4e3a\u6b64\u9700\u8981\u5c06CommandType\u53c2\u6570\u8bbe\u7f6e\u4e3aAlias\u3002\u5982\u679c\u9700\u8981\u7f29\u5c0f\u67e5\u627e\u8303\u56f4\uff0c\u5219\u53ef\u4ee5\u589e\u52a0\u8fc7\u6ee4\u5668\u3002\u4e0b\u4f8b\u83b7\u53d6\u4ee5l\u5f00\u5934\u7684\u522b\u540d\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; Get-Command -CommandType Alias l*\n\nCommandType     Name                            Definition\n-----------     ----                            ----------\nAlias           log                             Write-Host\nAlias           lp                              Out-Printer\nAlias           ls                              Get-ChildItem<\/pre>\n<p>\u9700\u8981\u5f3a\u8c03\u7684\u662f\u4e0a\u4f8b\u4e0e\u901a\u8fc7Get-Alias\u5f97\u5230\u7684\u8f93\u51fa\u7ed3\u679c\u4e00\u81f4\uff0c\u4e24\u4e2acmdlet\u5728\u83b7\u53d6\u522b\u540d\u65b9\u9762\u7684\u6548\u679c\u76f8\u540c\uff0c\u8fd4\u56de\u7684\u90fd\u662f\u522b\u540d\u5bf9\u5e94\u7684\u5bf9\u8c61\u7c7b\u578bAliasInfo\u3002<\/p>\n<p>\uff083\uff09\u522b\u540d\u63d0\u4f9b\u7a0b\u5e8f<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u522b\u540d\u63d0\u4f9b\u7a0b\u5e8f\u6620\u5c04\u5230\u7c7b\u4f3c\u6587\u4ef6\u7cfb\u7edf\u7684alias\uff1a\u9a71\u52a8\u5668\uff0c\u4e0b\u4f8b\u901a\u8fc7\u5176\u83b7\u53d6\u6240\u6709\u4ee5l\u5f00\u5934\u7684\u522b\u540d\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; cd alias:\nPS Alias:\\&gt; dir l*\nCommandType     Name                            Definition\n-----------     ----                            ----------\nAlias           lp                              Out-Printer\nAlias           ls                              Get-ChildItem\nAlias           log                             Write-Host<\/pre>\n<p>\u540c\u6837\uff0c\u5728\u8fd9\u91cc\u83b7\u53d6\u5230\u7684\u8fd8\u662fAliasInfo\u5bf9\u8c61\u7684\u96c6\u5408\uff0c\u56e0\u4e3a\u522b\u540d\u63d0\u4f9b\u7a0b\u5e8f\u8fd4\u56de\u7684\u662f\u8fd9\u4e2a\u7c7b\u578b\u7684\u5bf9\u8c61\u3002Test-Path cmdlet\u53ef\u4ee5\u5224\u65ad\u67d0\u4e2a\u6587\u4ef6\u6216\u76ee\u5f55\u662f\u5426\u5b58\u5728\uff0c\u8fd9\u6837\u5373\u53ef\u4f7f\u7528Test-Path\u91cd\u5199\u524d\u9762\u7684if\u8bed\u53e5\u6765\u5224\u65ad\u7279\u5b9a\u522b\u540d\u662f\u5426\u5b58\u5728\uff0c\u5982\u4e0b\u4f8b\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; if(Test-Path alias:\\log)\n&gt;&gt; {\n&gt;&gt;     log &quot;Alias exists&quot;\n&gt;&gt; }\n&gt;&gt;\nAlias exists<\/pre>\n<p><b>\u4fee\u6539\u522b\u540d<\/b><\/p>\n<p>\u5f88\u591a\u65f6\u5019\u7528\u6237\u9700\u8981\u4fee\u6539\u522b\u540d\uff0c\u6216\u663e\u5f0f\u5730\u7528\u81ea\u5df1\u7684\u522b\u540d\u8986\u76d6\u5df2\u7ecf\u5b58\u5728\u7684\u522b\u540d\u3002\u5982\u679c\u522b\u540d\u5df2\u7ecf\u5b58\u5728\uff0c\u518d\u6b21\u4f7f\u7528New-Alias cmdlet\u521b\u5efa\u76f8\u540c\u7684\u522b\u540d\u5c06\u4f1a\u629b\u9519\uff0c\u5982\u679c\u9700\u8981\u5f3a\u5236\u8986\u76d6\u5df2\u5b58\u5728\u7684\u522b\u540d\uff0c\u5219\u53ef\u4ee5\u4f20\u9012Force\u7684\u5f00\u5173\u53c2\u6570\u3002\u6b64\u65f6New-Alias\u5c06\u4f1a\u628a\u629b\u51fa\u7684\u9519\u8bef\u5728\u540e\u53f0\u9500\u6bc1\uff0c\u5e76\u5220\u9664\u5df2\u6709\u7684\u65e7\u522b\u540d\uff0c\u7136\u540e\u521b\u5efa\u65b0\u7684\u522b\u540d\u3002\u4e0b\u4f8b\u66f4\u65b0log\u8fd9\u4e2a\u522b\u540d\uff0c\u4f7f\u7528Write-Verbose\u66ff\u6362Write-Host\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; Get-Alias log\n\nCommandType     Name                      Definition\n-----------          ----                        ----------\nAlias               log                         Write-Host\n\nPS C:\\PowerShell&gt; New-Alias log Write-Verbose -Force\nPS C:\\PowerShell&gt; Get-Alias log\n\nCommandType     Name                      Definition\n-----------          ----                        ----------\nAlias               log                         Write-Verbose\n\nPS C:\\PowerShell&gt; $VerbosePreference =&quot;Continue&quot;\nPS C:\\PowerShell&gt; log &quot;This is just a test&quot;\nVERBOSE: This is just a test<\/pre>\n<p>\u9700\u8981\u5f3a\u8c03\u7684\u662f\uff0c\u7531\u4e8e\u5728\u4e0a\u4f8b\u4e2d\u4f7f\u7528\u4e86Write-Verbose\u8fd9\u4e2a\u7528\u4e8e\u8c03\u8bd5\u7684cmdlet\uff0c\u53ef\u4ee5\u9700\u8981\u8bbe\u7f6e$VerbosePreference\u5168\u5c40\u53d8\u91cf\u4e3aContinue\uff0c\u8fd9\u6837\u4f1a\u5c06\u9519\u8bef\u62a5\u544a\u7ed9\u7528\u6237\u5e76\u7ee7\u7eed\u6267\u884c\u540e\u9762\u7684\u4ee3\u7801\u3002\u7528\u6237\u53ef\u4ee5\u4ece\u7b2c11\u7ae0\u5b66\u5230\u66f4\u591a\u5173\u4e8e\u811a\u672c\u8c03\u8bd5\u7684\u6280\u672f\uff0c\u5305\u62ec\u8ddf\u8e2a\u3001\u6b65\u8fdb\u8c03\u8bd5\u811a\u672c\u4ee3\u7801\u3002<\/p>\n<p>\u4e3a\u4e86\u907f\u514d\u7531\u4e8e\u5f3a\u5236\u66f4\u65b0\u522b\u540d\uff0c\u8986\u76d6\u5df2\u6709\u7684\u91cd\u8981\u522b\u540d\uff0cPowerShell\u63d0\u4f9b\u4e86\u53e6\u5916\u4e00\u4e2a\u53ef\u9009\u7684\u4fee\u6539\u522b\u540d\u7684cmdlet\uff0c\u5373Set-Alias\u3002\u5176\u5de5\u4f5c\u65b9\u5f0f\u7c7b\u4f3cNew-Alias \u2013Force\uff0c\u4f46\u662f\u66f4\u7b80\u7ec3\u3002\u4e0b\u4f8b\u5c06log\u522b\u540d\u7684\u6307\u5411\u6539\u56deWrite-Host\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; Set-Alias log Write-Host\nPS C:\\PowerShell&gt; Get-Alias log\n\nCommandType     Name                          Definition\n-----------          ----                            ----------\nAlias               log                             Write-Host\n\nPS C:\\PowerShell&gt; log &quot;Write-Host is back&quot;\nWrite-Host is back<\/pre>\n<p>\u7531\u4e8e\u522b\u540d\u5728\u522b\u540d\u63d0\u4f9b\u7a0b\u5e8fAlias\uff1a\u4e2d\u662f\u4ee5\u4e00\u6761\u7c7b\u4f3c\u6587\u4ef6\u7684\u8bb0\u5f55\u7684\u5f62\u5f0f\u5b58\u5728\uff0c\u56e0\u6b64\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Set-Item cmdlet\u8bbe\u7f6e\u76f8\u5e94\u7684\u8bb0\u5f55\u3002\u64cd\u4f5c\u7684\u65b9\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; cd Alias:\nPS Alias:\\&gt; Set-Item log Write-Verbose\nPS Alias:\\&gt; dir log\n\nCommandType     Name                          Definition\n-----------          ----                            ----------\nAlias               log                             Write-Verbose<\/pre>\n<p>\u522b\u540d\u65e2\u7136\u53ef\u4ee5\u4f5c\u4e3a\u7c7b\u4f3c\u6587\u4ef6\u8bb0\u5f55\u7684\u5f62\u5f0f\u64cd\u4f5c\uff0c\u56e0\u6b64\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528Set-Content cmdlet\u4fee\u6539\u522b\u540d\u3002\u4e0b\u4f8b\u901a\u8fc7\u8bbe\u7f6e\u522b\u540d\u8bb0\u5f55\u7684\u5185\u5bb9\u6765\u4f7f\u522b\u540d\u91cd\u65b0\u6307\u5411\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; cd alias:\nPS Alias:\\&gt; Set-Content log Write-Host\nPS Alias:\\&gt; dir log\n\nCommandType     Name                          Definition\n-----------          ----                            ----------\nAlias               log                             Write-Host<\/pre>\n<p>PowerShell\u4e2d\u5e76\u6ca1\u6709\u63d0\u4f9b\u4e13\u95e8\u7684cmdlet\u6765\u5220\u9664\u6216\u6e05\u7406\u65e0\u7528\u7684\u522b\u540d\uff0c\u4e3a\u4e86\u7ef4\u62a4\u522b\u540d\uff0c\u9700\u8981\u4f7f\u7528\u522b\u540d\u63d0\u4f9b\u7a0b\u5e8f\uff0c\u5e76\u8c03\u7528Remove-Item cmdlet\uff08\u522b\u540d\u662f\u201cdel\u201d\uff09\u79fb\u9664\u65e0\u7528\u7684\u522b\u540d\u3002\u4e0b\u4f8b\u6f14\u793a\u79fb\u9664log\u522b\u540d\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; cd alias:\nPS Alias:\\&gt; del log\nPS Alias:\\&gt; Get-Alias log\nGet-Alias : This command cannot find a matching alias because alias with name '\nlog' do not exist.\nAt line:1 char:10\n+ Get-Alias &lt;&lt;&lt;&lt;  log\n    + CategoryInfo          : ObjectNotFound: (log:String) [Get-Alias], ItemNo\n   tFoundException\n    + FullyQualifiedErrorId : ItemNotFoundException,Microsoft.PowerShell.Comma\n   nds.GetAliasCommand<\/pre>\n<p>\u4ece\u4e0a\u4f8b\u80fd\u591f\u770b\u5230\uff0clog\u522b\u540d\u5df2\u7ecf\u88ab\u6e05\u9664\uff0c\u901a\u8fc7Get-Alias\u83b7\u53d6\u8be5\u522b\u540d\u65f6\u629b\u9519\u3002<\/p>\n<p><b>\u5bfc\u5165\/\u5bfc\u51fa\u522b\u540d<\/b><\/p>\n<p>\u53ef\u4ee5\u5bfc\u51fa\u5df2\u7ecf\u5b9a\u4e49\u7684\u522b\u540d\uff0c\u4e5f\u53ef\u4ee5\u5728\u76ee\u6807\u8ba1\u7b97\u673a\u4e0a\u5bfc\u5165\u8fd9\u4e9b\u522b\u540d\u3002<\/p>\n<p>\u5982\u679c\u8981\u5bfc\u51fa\u6240\u6709\u7684\u522b\u540d\uff0c\u5219\u9700\u8981\u8c03\u7528Export-Alias cmdlet\uff0c\u6700\u7b80\u5316\u7684\u60c5\u51b5\u4e0b\u53ea\u9700\u63d0\u4f9b\u4fdd\u5b58\u522b\u540d\u7684\u4f4d\u7f6e\u5373\u53ef\u3002\u5bfc\u51fa\u7684\u522b\u540d\u6587\u4ef6\u4e3a\u6587\u672c\u683c\u5f0f\uff0c\u5177\u4f53\u64cd\u4f5c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>PS C:\\&gt; Export-Alias aliases.txt\nPS C:\\&gt; type .\\aliases.txt\n# Alias File\n# Exported by : Administrator\n# Date\/Time : 2008\u5e7412\u67083\u65e5 14:32:19\n# Machine : NULL\n&quot;ac&quot;,&quot;Add-Content&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;asnp&quot;,&quot;Add-PSSnapIn&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;clc&quot;,&quot;Clear-Content&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;cli&quot;,&quot;Clear-Item&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;clp&quot;,&quot;Clear-ItemProperty&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;clv&quot;,&quot;Clear-Variable&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;compare&quot;,&quot;Compare-Object&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;cpi&quot;,&quot;Copy-Item&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;cpp&quot;,&quot;Copy-ItemProperty&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;cvpa&quot;,&quot;Convert-Path&quot;,&quot;&quot;,&quot;ReadOnly, AllScope&quot;\n&quot;clear&quot;,&quot;Clear-Host&quot;,&quot;&quot;,&quot;AllScope&quot;\n.......<\/pre>\n<p>\u5bfc\u5165\u7684\u8fc7\u7a0b\u9700\u8981\u8c03\u7528Import-Alias cmdlet\u5c06\u5bfc\u51fa\u7684\u522b\u540d\u6587\u4ef6\u5b89\u88c5\u5230\u76ee\u6807\u4e3b\u673a\u7684\u5f53\u524dShell\u8fdb\u7a0b\u4e2d\uff0c\u5982\uff1a<\/p>\n<pre>PS C:\\&gt; Import-Alias .\\aliases.txt\nImport-Alias : Alias not allowed because an alias with the name 'ac' already ex\nists.\nAt line:1 char:13\n+ Import-Alias &lt;&lt;&lt;&lt;  .\\aliases.txt\n    + CategoryInfo          : ResourceExists: (ac:String) [Import-Alias], Sess\n   ionStateException\n    + FullyQualifiedErrorId : AliasAlreadyExists,Microsoft.PowerShell.Commands\n   .ImportAliasCommand\n\nImport-Alias : Alias not allowed because an alias with the name 'asnp' already\nexists.\nAt line:1 char:13\n+ Import-Alias &lt;&lt;&lt;&lt;  .\\aliases.txt\n    + CategoryInfo          : ResourceExists: (asnp:String) [Import-Alias], Se\n   ssionStateException\n    + FullyQualifiedErrorId : AliasAlreadyExists,Microsoft.PowerShell.Commands\n   .ImportAliasCommand\n\nImport-Alias : Alias not allowed because an alias with the name 'clc' already e\nxists.\nAt line:1 char:13\n+ Import-Alias &lt;&lt;&lt;&lt;  .\\aliases.txt\n    + CategoryInfo          : ResourceExists: (clc:String) [Import-Alias], Ses\n   sionStateException\n    + FullyQualifiedErrorId : AliasAlreadyExists,Microsoft.PowerShell.Commands\n   .ImportAliasCommand<\/pre>\n<p>\u5728\u672c\u673a\u6267\u884c\u8be5\u64cd\u4f5c\u65f6\uff0c\u4f1a\u629b\u51fa\u5927\u91cf\u7684\u9519\u8bef\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0bExport-Alias cmdlet\u4f1a\u5bfc\u51fa\u6240\u6709\u7684\u522b\u540d\uff0c\u751a\u81f3\u5305\u62ec\u5185\u7f6e\u7684\u522b\u540d\u3002\u4e3a\u4e86\u4fdd\u8bc1\u5728\u5bfc\u5165\u522b\u540d\u7684\u8fc7\u7a0b\u4e2d\u4e0d\u8986\u76d6\u7528\u6237\u7684\u914d\u7f6e\uff0cImport-Alias\u4f1a\u5bf9\u8986\u76d6\u522b\u540d\u7684\u64cd\u4f5c\u629b\u51fa\u8b66\u544a\u4fe1\u606f\u3002\u8fd9\u4e0d\u662f\u4e00\u4e2a\u95ee\u9898\uff0c\u56e0\u4e3a\u5185\u7f6e\u7684\u522b\u540d\u5b9a\u4e49\u5728\u4efb\u4f55\u673a\u5668\u4e0a\u90fd\u662f\u4e00\u81f4\u7684\uff0c\u53ef\u4ee5\u4e0d\u4f1a\u9020\u6210\u9519\u8bef\u3002<\/p>\n<p>\u6709\u65f6\u9700\u8981\u5f3a\u5236\u8986\u76d6\u5df2\u7ecf\u5b58\u5728\u7684\u522b\u540d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e3aImport-Alias cmdlet\u4f20\u9012-Force\u53c2\u6570\u5b9e\u73b0\uff0c\u64cd\u4f5c\u5982\u4e0b\u4f8b\u6240\u793a\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; Import-Alias .\\aliases.txt -Force\nPS C:\\PowerShell&gt;<\/pre>\n<p>\u5982\u679c\u4e0d\u8986\u76d6\u5185\u7f6e\u7684\u522b\u540d\uff0c\u53ea\u5bfc\u5165\u65b0\u589e\u7684\u522b\u540d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9aErrorAction\u53c2\u6570\u4e3aSilentlyContinue\u6765\u5ffd\u7565\u9519\u8bef\u63d0\u793a\u3002\u8fd9\u6837\u4e0d\u4f1a\u8986\u76d6\u5df2\u6709\u522b\u540d\uff0c\u800c\u53ea\u6dfb\u52a0\u65b0\u589e\u7684\u522b\u540d\uff0c\u64cd\u4f5c\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; Import-Alias .\\aliases.txt -ErrorAction SilentlyContinue\nPS C:\\PowerShell&gt;<\/pre>\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7\u7f16\u8f91\u5df2\u5bfc\u51fa\u7684\u522b\u540d\u6587\u4ef6\uff0c\u6e05\u9664\u5176\u4e2d\u5185\u7f6e\u7684\u522b\u540d\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u53ea\u5bfc\u5165\u65b0\u589e\u522b\u540d\u3002\u7136\u800c\u8fd9\u4e0d\u662f\u597d\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5bfc\u51fa\u7684\u522b\u540d\u6587\u4ef6\u6709\u5f88\u591a\u884c\uff0c\u6e05\u7406\u5e76\u4e0d\u65b9\u4fbf\u3002\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u8fc7\u6ee4\u5668\u7684\u65b9\u5f0f\u53ea\u5bfc\u51fa\u90e8\u5206\u522b\u540d\uff0c\u5982\u4e0b\u4f8b\u53ea\u5bfc\u51fa\u4ee5log\u5f00\u5934\u7684\u522b\u540d\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; Set-Alias log-host Write-Host\nPS C:\\PowerShell&gt; Set-Alias log-verbose Write-Verbose\nPS C:\\PowerShell&gt; Export-Alias log-aliases.txt log*\nPS C:\\PowerShell&gt; type .\\log-aliases.txt\n# Alias File\n# Exported by : Administrator\n# Date\/Time : 2008\u5e7412\u67083\u65e5 14:58:58\n# Machine : NULL\n&quot;log-host&quot;,&quot;Write-Host&quot;,&quot;&quot;,&quot;None&quot;\n&quot;log-verbose&quot;,&quot;Write-Verbose&quot;,&quot;&quot;,&quot;None&quot;<\/pre>\n<p>\u751a\u81f3\u53ef\u4ee5\u5206\u591a\u6b21\u5c06\u522b\u540d\u5bfc\u51fa\uff0c\u5e76\u6dfb\u52a0\u5230\u76f8\u540c\u7684\u6587\u4ef6\u4e2d\u3002\u4e0b\u4f8b\u5c06trace*\u7684\u522b\u540d\u5bfc\u5165\u5230\u4e4b\u524d\u7684\u522b\u540d\u5217\u8868\u4e2d\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; Set-Alias trace-host Write-Host\nPS C:\\PowerShell&gt; Export-Alias .\\log-aliases.txt trace* -append\nPS C:\\PowerShell&gt; type .\\log-aliases.txt\n# Alias File\n# Exported by : Administrator\n# Date\/Time : 2008\u5e7412\u67083\u65e5 14:58:58\n# Machine : NULL\n&quot;log-host&quot;,&quot;Write-Host&quot;,&quot;&quot;,&quot;None&quot;\n&quot;log-verbose&quot;,&quot;Write-Verbose&quot;,&quot;&quot;,&quot;None&quot;\n# Alias File\n# Exported by : Administrator\n# Date\/Time : 2008\u5e7412\u67083\u65e5 15:05:45\n# Machine : NULL\n&quot;trace-host&quot;,&quot;Write-Host&quot;,&quot;&quot;,&quot;None&quot;<\/pre>\n<p>\u80fd\u591f\u770b\u5230\u5176\u4e2d\u7684\u6587\u4ef6\u5934\u88ab\u63d2\u5165\u4e86\u4e24\u6b21\uff0c\u4f46\u662f\u65e0\u5173\u7d27\u8981\uff0c\u5728\u5bfc\u5165\u8fc7\u7a0b\u4e2d\u4f1a\u5ffd\u7565\u6ce8\u91ca\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u5c06\u522b\u540d\u5bfc\u51fa\u4e3a\u811a\u672c\u5f62\u5f0f\uff0c\u4fbf\u4e8e\u540e\u9762\u901a\u8fc7\u6267\u884c\u65b9\u5f0f\u5bfc\u5165\uff0c\u53ea\u9700\u8981\u6dfb\u52a0-as\u53c2\u6570\u5373\u53ef\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; Export-Alias log-aliases.ps1 log* -as Script\nPS C:\\PowerShell&gt; type .\\log-aliases.ps1\n# Alias File\n# Exported by : Administrator\n# Date\/Time : 2008\u5e7412\u67083\u65e5 15:16:51\n# Machine : NULL\nset-alias -Name:&quot;log-host&quot; -Value:&quot;Write-Host&quot; -Description:&quot;&quot; -Option:&quot;None&quot;\nset-alias -Name:&quot;log-verbose&quot; -Value:&quot;Write-Verbose&quot; -Description:&quot;&quot; -Option:&quot;N\none&quot;\nPS C:\\PowerShell&gt;<\/pre>\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u6587\u4ef6\u683c\u5f0f\u4e3acsv\uff0c\u5c06\u522b\u540d\u5bfc\u51fa\u4e3a\u7528\u9017\u53f7\u5206\u9694\u7684\u6587\u4ef6\uff0c\u8fd9\u6837\u5373\u53ef\u901a\u8fc7Microsoft Word\u6253\u5f00\u3002\u5982\uff1a<\/p>\n<pre>PS C:\\PowerShell&gt; Export-Alias .\\log-aliases.csv log* -as csv\nPS C:\\PowerShell&gt; type .\\log-aliases.csv\n# Alias File\n# Exported by : Administrator\n# Date\/Time : 2008\u5e7412\u67083\u65e5 15:25:56\n# Machine : NULL\n&quot;log-host&quot;,&quot;Write-Host&quot;,&quot;&quot;,&quot;None&quot;\n&quot;log-verbose&quot;,&quot;Write-Verbose&quot;,&quot;&quot;,&quot;None&quot;\nPS C:\\PowerShell&gt;<\/pre>\n<p>\u522b\u540d\u4e0e\u53d8\u91cf\u53ca\u51fd\u6570\u76f8\u4f3c\uff0c\u5728\u5f53\u524dShell\u8fdb\u7a0b\u4e2d\u5b9a\u4e49\u7684\u522b\u540d\u4ec5\u5728\u5f53\u524d\u8fdb\u7a0b\u4e2d\u6709\u6548\u3002\u5982\u679c\u9700\u8981\u4f7f\u522b\u540d\u5728\u6240\u6709\u7684\u63a7\u5236\u53f0\u4e0a\u5747\u6709\u6548\uff0c\u5219\u9700\u8981\u4fdd\u5b58\u522b\u540d\u7684\u914d\u7f6e\u3002\u4fdd\u5b58\u7684\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>\uff081\uff09\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0Set-Alias\u547d\u4ee4\u5b9a\u4e49\u81ea\u5df1\u7684\u522b\u540d\u3002\u5982\u679c\u8981\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u5219\u9700\u8981\u5b66\u4e60\u7b2c13\u7ae0\u4e2d\u7684\u6709\u5173\u5185\u5bb9\u3002\u53ea\u9700\u8981\u5c06\u914d\u7f6e\u7684\u547d\u4ee4\u7c98\u8d34\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d\u5373\u53ef\u5b9e\u73b0\u522b\u540d\u7684\u91cd\u590d\u4f7f\u7528\uff0c\u4f46\u8fd9\u79cd\u505a\u6cd5\u4f1a\u5bfc\u81f4\u914d\u7f6e\u6587\u4ef6\u7684\u7ef4\u62a4\u5f88\u4e0d\u65b9\u4fbf\u3002<\/p>\n<p>\uff082\uff09\u5728\u5b9a\u4e49\u522b\u540d\u540e\u5c06\u5176\u5bfc\u51fa\u5230\u7279\u5b9a\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u7f16\u8f91\u6587\u4ef6\u4ee5\u6e05\u9664\u5176\u4e2d\u65e0\u7528\u7684\u522b\u540d\u3002\u5c06\u4fee\u6539\u540e\u7684\u6587\u4ef6\u4fdd\u5b58\u5728\u7279\u5b9a\u7684\u4f4d\u7f6e\uff0c\u901a\u8fc7Import-Alias\u547d\u4ee4\u628a\u8be5\u6587\u4ef6\u5bfc\u5165\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d\u3002\u8fd9\u79cd\u505a\u6cd5\u7684\u597d\u5904\u5728\u4e8e\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u7ef4\u62a4\u522b\u540d\uff0c\u6700\u597d\u5c06\u522b\u540d\u6587\u4ef6\u4fdd\u5b58\u5728\u914d\u7f6e\u6587\u4ef6\u76ee\u5f55\u4e0b\uff0c\u4ee5\u907f\u514d\u65e0\u610f\u4e2d\u5220\u9664\u522b\u540d\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p><b>\u603b \u7ed3<\/b><\/p>\n<p>\u672c\u6587\u7740\u91cd\u4ecb\u7ecd\u4e86\u5982\u4f55\u5b9a\u4e49\u548c\u4f7f\u7528\u522b\u540d\u6765\u4f7f\u65e5\u5e38\u7684Shell\u4f7f\u7528\u66f4\u52a0\u4fbf\u6377\u3002\u952e\u5165 cmdlet \u540d\u79f0\u5f88\u9ebb\u70e6\uff0c\u4e3a\u6700\u5927\u9650\u5ea6\u5730\u51cf\u5c11\u952e\u5165\u5185\u5bb9\u5e76\u4f7f\u4e60\u60ef\u5176\u4ed6\u5916\u58f3\u7a0b\u5e8f\u7684\u7528\u6237\u66f4\u5bb9\u6613\u4f7f\u7528\uff0cPowerShell \u652f\u6301\u522b\u540d\uff08\u5373\u547d\u4ee4\u7684\u66ff\u4ee3\u540d\u79f0\uff09\u7684\u6982\u5ff5\u3002\u53ef\u4ee5\u4e3a cmdlet \u540d\u3001\u51fd\u6570\u540d\u6216\u53ef\u6267\u884c\u6587\u4ef6\u540d\u521b\u5efa\u522b\u540d\uff0c\u7136\u540e\u5728\u4efb\u4f55\u547d\u4ee4\u4e2d\u952e\u5165\u522b\u540d\u3002<\/p>\n<p>\u8d5b\u8fea\u7f51\u5730\u5740\uff1a<a href=\"http:\/\/news.ccidnet.com\/art\/32857\/20100617\/2089265_1.html\">http:\/\/news.ccidnet.com\/art\/32857\/20100617\/2089265_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","protected":false},"excerpt":{"rendered":"<p>UNIX shell\u7684\u7528\u6237\u5df2\u7ecf\u80fd\u591f\u4e3a\u547d\u4ee4\u6dfb\u52a0\u66f4\u7b80\u77ed\u548c\u53cb\u597d\u7684\u522b\u540d\uff0c\u4f46\u9057\u61be\u7684\u662fDOS\u57fa\u4e8e\u7684shell\uff0ccomman [&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-33116","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33116"}],"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=33116"}],"version-history":[{"count":1,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33116\/revisions"}],"predecessor-version":[{"id":33800,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33116\/revisions\/33800"}],"wp:attachment":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}