{"componentChunkName":"component---src-templates-post-template-js","path":"/powershell-custom-prompt-en","result":{"data":{"markdownRemark":{"id":"e5e0a84a-6c4e-5c78-babf-80d0d147757a","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/powershell-custom-prompt\">original page</a>.</p>\n</blockquote>\n<h2 id=\"customize-the-powershell-prompt-display\" style=\"position:relative;\"><a href=\"#customize-the-powershell-prompt-display\" aria-label=\"customize the powershell prompt display permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Customize the PowerShell prompt display</h2>\n<p>Let’s jump right in and start learning PowerShell.</p>\n<p>First, let’s simplify the prompt display.<br>\nBy default, it is probably shown as <code class=\"language-text\">PS [current directory]</code>, like this.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PS C:\\Users\\yuki> </code></pre></div>\n<p>Here, you can remove the current-directory display by entering the following command.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PS C:\\Users\\yuki> function Prompt { \"PS > \" }\nPS ></code></pre></div>\n<p>To restore the original state, enter the following.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PS > function prompt { \"PS \" + $(Get-Location) + \"> \" }</code></pre></div>\n<p>This returns the prompt to its original form.</p>\n<p>Next, let’s customize the display using another command.</p>\n<p>If you enter the following command, the output of <code class=\"language-text\">$(echo \"test\")</code> will be shown in the prompt.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PS C:\\Users\\yuki> function prompt { \"PS \" + $(echo \"test\") + \"> \" }\nPS test></code></pre></div>\n<p>Using this approach, you can freely change how the PowerShell prompt is displayed.</p>\n<p><strong>By the way, <code class=\"language-text\">Get-Location</code>, which we used to display the current directory, has two other aliases for the same command.</strong></p>\n<p>They are <strong>gl</strong> and <strong>pwd</strong>.</p>\n<p>So even if you enter the following, the current directory will still be displayed in the prompt just as when using <code class=\"language-text\">Get-Location</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PS C:\\Users\\yuki> function prompt {\n>> \"PS \" + $(pwd) + \"> \" }\n\nPS C:\\Users\\yuki> function prompt {\n>> \"PS \" + $(gl) + \"> \" }\n\nPS C:\\Users\\yuki></code></pre></div>\n<p>When it comes to these aliases, a natural question is whether you really need to know all of them.<br>\nIf you are the only one using them, honestly, knowing just one is probably enough.</p>\n<p>However, <strong>if you are going to use PowerShell in the security field, it seems you need to know all of the aliases</strong>.</p>\n<p>The idea is that <strong>even if you do not use a particular alias yourself, an attacker might use it, so understanding them is important if you want to recognize an attacker’s intent</strong>.</p>\n<p>For more details, I referred to the following article.</p>\n<p><a href=\"https://akaki.io/2019/learning_powershell.html\" target=\"_blank\" rel=\"noopener noreferrer\">Learning the basics of PowerShell at the Yamato Security Study Group · Akaki I/O</a></p>\n<h2 id=\"summary\" style=\"position:relative;\"><a href=\"#summary\" aria-label=\"summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h2>\n<p>This time, I covered how to change the prompt display and touched on aliases.</p>\n<p>PowerShell has become open source, and because it is a powerful shell and scripting environment that works not only on Windows but also on Linux and macOS, I want to keep learning more and more about it in the future.</p>","fields":{"slug":"/powershell-custom-prompt-en","tagSlugs":["/tag/power-shell-en/","/tag/windows-en/","/tag/english/"]},"frontmatter":{"date":"2020-06-30","description":"This article summarizes how to customize the PowerShell prompt display.","tags":["PowerShell (en)","Windows (en)","English"],"title":"How to freely customize the PowerShell prompt display","socialImage":{"publicURL":"/static/dc4d8b7f8795f3c3d3489d9957d155f2/no-image.png"}}}},"pageContext":{"slug":"/powershell-custom-prompt-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}