{"id":9956,"date":"2023-10-18T01:22:54","date_gmt":"2023-10-17T17:22:54","guid":{"rendered":"https:\/\/as32.net\/blog\/?p=9956"},"modified":"2023-10-18T01:22:54","modified_gmt":"2023-10-17T17:22:54","slug":"powershell%e7%9b%b8%e5%85%b3","status":"publish","type":"post","link":"https:\/\/www.bohu.net\/blog\/9956\/","title":{"rendered":"powershell\u76f8\u5173"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u67e5\u770b\u522b\u540d<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528Get-Command\u67e5\u770b<strong>Alias<\/strong>\u7684\u547d\u4ee4\uff1a\u00a0<code>Get-Command -CommandType Alias<\/code><\/li>\n\n\n\n<li>\u67e5\u770b\u6b64Session\u4e2d\u5df2\u7ecf\u8bbe\u5b9a\u7684\u6240\u6709\u522b\u540d\uff1a<code>Get-Alias<\/code>\u6216<code>gal<\/code><\/li>\n\n\n\n<li>\u67e5\u770b\u67d0\u522b\u540d\u7684\u539f\u547d\u4ee4\uff0c\u5982<code>ls<\/code>\u7684\u539f\u547d\u4ee4\uff1a<code>Get-Alias ls<\/code><\/li>\n\n\n\n<li>\u67e5\u770b\u67d0\u539f\u547d\u4ee4\u7684\u522b\u540d\uff0c\u5982<code>Get-ChildItem<\/code>\u7684\u522b\u540d\uff1a<code>Get-Alias -Definition Get-ChildItem<\/code><\/li>\n\n\n\n<li>\u6309\u5c5e\u6027\u83b7\u53d6\u522b\u540d\uff1a<code>Get-Alias | Where-Object {$_.Options -Match \"ReadOnly\"}<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"compatibility-aliases-in-windows\">Windows \u4e2d\u7684\u517c\u5bb9\u6027\u522b\u540d<\/h2>\n\n\n\n<p>PowerShell \u5177\u6709\u591a\u4e2a\u522b\u540d\uff0c\u4f7f UNIX \u548c cmd.exe \u7528\u6237\u53ef\u4ee5\u5728 Windows \u4e2d\u4f7f\u7528\u719f\u6089\u7684\u547d\u4ee4\u3002 \u4e0b\u8868\u663e\u793a\u4e86\u5e38\u7528\u547d\u4ee4\u3001\u76f8\u5173\u7684 PowerShell cmdlet \u548c PowerShell \u522b\u540d\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>cmd.exe\u547d\u4ee4<\/th><th>UNIX \u547d\u4ee4<\/th><th>PowerShell Cmdlet<\/th><th>PowerShell \u522b\u540d<\/th><\/tr><\/thead><tbody><tr><td><strong>cd<\/strong>\u3001<strong>chdir<\/strong><\/td><td><strong>cd<\/strong><\/td><td><code>Set-Location<\/code><\/td><td><code>sl<\/code>\u3001<code>cd<\/code>\u3001<code>chdir<\/code><\/td><\/tr><tr><td><strong>cls<\/strong><\/td><td><strong>clear<\/strong><\/td><td><code>Clear-Host<\/code><\/td><td><code>cls<\/code>&nbsp;<code>clear<\/code><\/td><\/tr><tr><td><strong>copy<\/strong><\/td><td><strong>cp<\/strong><\/td><td><code>Copy-Item<\/code><\/td><td><code>cpi<\/code>\u3001<code>cp<\/code>\u3001<code>copy<\/code><\/td><\/tr><tr><td><strong>del<\/strong>\u3001<strong>erase<\/strong>\u3001<strong>rd<\/strong>\u3001<strong>rmdir<\/strong><\/td><td><strong>rm<\/strong><\/td><td><code>Remove-Item<\/code><\/td><td><code>ri<\/code>\u3001<code>del<\/code>\u3001<code>erase<\/code>\u3001<code>rd<\/code>\u3001<code>rm<\/code>\u3001<code>rmdir<\/code><\/td><\/tr><tr><td><strong>dir<\/strong><\/td><td><strong>ls<\/strong><\/td><td><code>Get-ChildItem<\/code><\/td><td><code>gci<\/code>\u3001<code>dir<\/code>\u3001<code>ls<\/code><\/td><\/tr><tr><td>echo<\/td><td>echo<\/td><td><code>Write-Output<\/code><\/td><td><code>write<\/code>&nbsp;<code>echo<\/code><\/td><\/tr><tr><td><strong>md<\/strong><\/td><td><strong>mkdir<\/strong><\/td><td><code>New-Item<\/code><\/td><td><code>ni<\/code><\/td><\/tr><tr><td><strong>move<\/strong><\/td><td><strong>mv<\/strong><\/td><td><code>Move-Item<\/code><\/td><td><code>mi<\/code>\u3001<code>move<\/code>\u3001<code>mi<\/code><\/td><\/tr><tr><td><strong>popd<\/strong><\/td><td><strong>popd<\/strong><\/td><td><code>Pop-Location<\/code><\/td><td><code>popd<\/code><\/td><\/tr><tr><td><\/td><td><strong>pwd<\/strong><\/td><td><code>Get-Location<\/code><\/td><td><code>gl<\/code>\u3001<code>pwd<\/code><\/td><\/tr><tr><td><strong>pushd<\/strong><\/td><td><strong>pushd<\/strong><\/td><td><code>Push-Location<\/code><\/td><td><code>pushd<\/code><\/td><\/tr><tr><td><strong>ren<\/strong><\/td><td><strong>mv<\/strong><\/td><td><code>Rename-Item<\/code><\/td><td><code>rni<\/code>\u3001<code>ren<\/code><\/td><\/tr><tr><td>type<\/td><td><strong>cat<\/strong><\/td><td><code>Get-Content<\/code><\/td><td><code>gc<\/code>\u3001<code>cat<\/code>\u3001<code>type<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>&nbsp;\u5907\u6ce8<\/p>\n\n\n\n<p>\u6b64\u8868\u4e2d\u7684\u522b\u540d\u7279\u5b9a\u4e8e Windows\u3002 \u67d0\u4e9b\u522b\u540d\u5728\u5176\u4ed6\u5e73\u53f0\u4e0a\u4e0d\u53ef\u7528\u3002 \u8fd9\u662f\u4e3a\u4e86\u4f7f\u672c\u673a\u547d\u4ee4\u80fd\u591f\u5728 PowerShell \u4f1a\u8bdd\u4e2d\u5de5\u4f5c\u3002 \u4f8b\u5982\uff0c\u672a\u5728 macOS \u6216 Linux \u4e0a\u5c06&nbsp;<code>ls<\/code>&nbsp;\u5b9a\u4e49\u4e3a PowerShell \u522b\u540d\uff0c\u4ee5\u4fbf\u8fd0\u884c\u672c\u673a\u547d\u4ee4\u800c\u4e0d\u662f&nbsp;<code>Get-ChildItem<\/code>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"to-start-the-windows-powershell-ise\">Windows \u4e0bGUI\u7f16\u8f91\u5de5\u5177 PowerShell ISE<\/h3>\n\n\n\n<p>\u5355\u51fb\u201c<strong>\u5f00\u59cb\u201d<\/strong>\uff0c\u9009\u62e9\u201cWindows PowerShell\u201d\uff0c\u7136\u540e\u5355\u51fb\u201c<strong>Windows PowerShell ISE<\/strong>\u201d\u3002\u00a0\u6216\u8005\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u547d\u4ee4\u5916\u58f3\u6216\u201c\u8fd0\u884c\u201d\u6846\u4e2d\u952e\u5165\u5185\u5bb9\u3002<code>powershell_ise.exe<\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Linux\u4e0b\u5b89\u88c5 powershell<\/h3>\n\n\n\n<p>\u5982\u679c\u4f60\u5df2\u5b89\u88c5\u00a0<a href=\"https:\/\/learn.microsoft.com\/zh-cn\/dotnet\/core\/sdk\">.NET Core SDK<\/a>\uff0c\u5219\u53ef\u4ee5\u8f7b\u677e\u5730\u5b89\u88c5 PowerShell \u4f5c\u4e3a\u00a0<a href=\"https:\/\/learn.microsoft.com\/zh-cn\/dotnet\/core\/tools\/global-tools\">.NET \u5168\u5c40\u5de5\u5177<\/a>\u3002<\/p>\n\n\n\n<p>sh\u590d\u5236<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet tool install --global PowerShell\n<\/code><\/pre>\n\n\n\n<p>dotnet \u5de5\u5177\u5b89\u88c5\u7a0b\u5e8f\u5c06&nbsp;<code>~\/.dotnet\/tools<\/code>&nbsp;\u6dfb\u52a0\u5230&nbsp;<code>PATH<\/code>&nbsp;\u73af\u5883\u53d8\u91cf\u4e2d\u3002 \u4f46\u662f\uff0c\u5f53\u524d\u8fd0\u884c\u7684 shell \u6ca1\u6709\u66f4\u65b0\u7684&nbsp;<code>PATH<\/code>\u3002 \u5e94\u8be5\u53ef\u4ee5\u901a\u8fc7\u952e\u5165&nbsp;<code>pwsh<\/code>&nbsp;\u4ece\u65b0 shell \u542f\u52a8 PowerShell\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u67e5\u770b\u522b\u540d Windows \u4e2d\u7684\u517c\u5bb9\u6027\u522b\u540d PowerShell \u5177\u6709\u591a\u4e2a\u522b\u540d\uff0c\u4f7f UNIX \u548c cmd.exe &hellip; <a href=\"https:\/\/www.bohu.net\/blog\/9956\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cpowershell\u76f8\u5173\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29],"tags":[719,721,300,720,722],"class_list":["post-9956","post","type-post","status-publish","format-standard","hentry","category-windows","category-29","tag-get-alias","tag-linux-powershell","tag-powershell","tag-powershell-ise","tag-pwsh"],"_links":{"self":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/9956","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/comments?post=9956"}],"version-history":[{"count":1,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/9956\/revisions"}],"predecessor-version":[{"id":9957,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/9956\/revisions\/9957"}],"wp:attachment":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/media?parent=9956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/categories?post=9956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/tags?post=9956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}