{"id":146831,"date":"2021-01-04T16:00:24","date_gmt":"2021-01-04T13:00:24","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/using-psreadline-in-powershell-cloudsavvy-it\/"},"modified":"2021-01-04T16:00:24","modified_gmt":"2021-01-04T13:00:24","slug":"using-psreadline-in-powershell-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/using-psreadline-in-powershell-cloudsavvy-it\/","title":{"rendered":"#Using PSReadLine in PowerShell \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a25843d7f498\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a25843d7f498\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/using-psreadline-in-powershell-cloudsavvy-it\/#Updating_and_Loading_PSReadLine\" >Updating and Loading PSReadLine<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/using-psreadline-in-powershell-cloudsavvy-it\/#Features_of_PSReadLine\" >Features of PSReadLine<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/using-psreadline-in-powershell-cloudsavvy-it\/#PSReadLine_History_File\" >PSReadLine History File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/using-psreadline-in-powershell-cloudsavvy-it\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#Using PSReadLine in PowerShell \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4374\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/8fec593cd19e3b20a0773cafaaaaf848\/p\/uploads\/2020\/03\/23e4a5a4.png\" alt=\"Powershell logo\" width=\"1400\" height=\"578\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/redirect.viglink.com?u=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fpsreadline%2F%3Fview%3Dpowershell-7.1&amp;key=204a528a336ede4177fff0d84a044482\">PSReadLine<\/a> is one of those modules that may not im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely show its utility until regular use. If you use the command-line of PowerShell often, PSReadLine can make your life much easier. Included in PowerShell versions as far back as Windows PowerShell 5, PSReadLine continues to add new features and utility. Building on the venerable legacy of GNU Readline in the Unix world, PSReadLine adds additional features to the PowerShell command-line experience such as multi-line editing, syntax coloring, predictive IntelliSense, richer history support, and alternative edit modes.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Updating_and_Loading_PSReadLine\"><\/span>Updating and Loading PSReadLine<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Most relatively recent versions of PowerShell have a bundled version of PSReadLine. Included as far back as Windows PowerShell 5.0, each subsequent version has added a newer version with PowerShell 7.1 included PSReadLine 2.1. Of course, you may want to take advantage of newer features in older PowerShell versions. In case PSReadLine is not already imported, use <code>Import-Module PSReadLine<\/code> to start using the features right away. To make sure you are using the latest version, read on!<\/p>\n<blockquote><p><em>Beginning with PowerShell 7.0, PowerShell skips auto-loading PSReadLine on Windows if a screen reader program is detected. Currently, PSReadLine doesn\u2019t work well with screen readers. The default rendering and formatting of PowerShell 7.0 on Windows works properly. You can manually load the module if necessary.<\/em><\/p>\n<\/blockquote>\n<p><strong>Windows PowerShell 5.x<\/strong><\/p>\n<p>There are <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>ly two steps to updating PSReadLine with Windows PowerShell 5.0 or 5.1. First, you need to make sure you are running version <code>1.6.0<\/code> or higher of PowerShellGet. To do this, you need to run the following command in an elevated Windows PowerShell session.<\/p>\n<pre><code class=\"language-powershell\">Install-Module -Name PowerShellGet -Force&#13;\n<\/code><\/pre>\n<p>Next, make sure that all PowerShell sessions are closed and in an elevated <code>cmd.exe<\/code> prompt run the following code. The reason that this is run from <code>cmd.exe<\/code> is that, by default, PSReadLine is loaded and can\u2019t be updated if in memory.<\/p>\n<pre><code class=\"language-powershell\">powershell -noprofile -command \"Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease\"&#13;\n<\/code><\/pre>\n<p><strong>PowerShell 6.x Core and PowerShell 7<\/strong><\/p>\n<p>To update PSReadLine in the newer versions of PowerShell, you can do a similar operation by closing all open PowerShell sessions, <code>pwsh.exe<\/code>, and run an elevated <code>cmd.exe<\/code> session with the following code.<\/p>\n<pre><code class=\"language-powershell\">pwsh.exe -noprofile -command \"Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease\"&#13;\n<\/code><\/pre>\n<p><strong>Updating PowerShell Gallery Installed PSReadLine<\/strong><\/p>\n<p>You may have installed PSReadLine from the PowerShell Gallery, and if you have done this, you can run either of the following commands to update depending on whether you are on Windows PowerShell or PowerShell Core\/7.<\/p>\n<pre><code class=\"language-powershell\"># Windows PowerShell&#13;\npowershell -noprofile -command \"Update-Module PSReadLine -AllowPrerelease\"&#13;\n&#13;\n# PowerShell Core\/7&#13;\npwsh.exe -noprofile -command \"Update-Module PSReadLine -AllowPrerelease\"&#13;\n<\/code><\/pre>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Features_of_PSReadLine\"><\/span>Features of PSReadLine<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>What can we do with PSReadLine? There are a number of very cool features that can help you with your command-line experience. Below you will see how several features work in practice.<\/p>\n<p><strong>Syntax Coloring<\/strong><\/p>\n<p>An example of how syntax coloring makes the readability of the command-line much easier, see this example where you can see that the output is colored, for the variable names, function names, and comparison operators.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8723\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/8b2ccd9f1da1b9155fec13370ca08382\/p\/uploads\/2020\/12\/dd806c59.png\" alt=\"\" width=\"1023\" height=\"115\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Although this command line isn\u2019t terribly long, there are cases where splitting this across multiple lines would be much easier to deal with. Read on, to see how we can split this over multiple lines, just like a traditional code editor.<\/p>\n<p><strong>Multi-Line Editing<\/strong><\/p>\n<p>Taking the same command <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/watch-movies-tv-seriess\/\" data-internallinksmanager029f6b8e52c=\"8\" title=\"Watch Movies &amp; TV Series\" target=\"_blank\" rel=\"noopener\">series<\/a> above, how do we split this across multiple lines? Using the default key combination of Shift-Enter (on Windows), we can split across lines as denoted by <code>&gt;&gt;<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8724\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/4eded82507e9dc73831a8d135eef83e0\/p\/uploads\/2020\/12\/63987953.png\" alt=\"\" width=\"902\" height=\"150\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can use arrow keys to navigate around the text and only when you are ready to run the command, you can hit the Enter key to execute. What about when you aren\u2019t sure command to use? Predictive Intellisense to the rescue!<\/p>\n<p><strong>Predictive Intellisense<\/strong><\/p>\n<p>First, we need to enable Predictive IntelliSense. You can tell it to use different source types, but the most common is simply your history. Keep in mind that until you have a history file with content built up this may not be the most useful, but after a while it becomes handy.<\/p>\n<pre><code class=\"language-powershell\"># This will enable the prediction source for IntelliSense&#13;\nSet-PSReadLineOption -PredictionSource 'History'&#13;\n# (Optional) Change the darker grey to a lighter grey to account for dark backgrounds&#13;\nSet-PSReadLineOption -Colors @{ InlinePrediction = '#9CA3AF'}&#13;\n<\/code><\/pre>\n<p>Now we can test this out using the same command that we just ran. You can see that after just typing <code>Get<\/code> we already see the command offered for completion. You can use the right arrow (default) to accept the selection.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8725\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/32ef29065980679420e6e362fe50231d\/p\/uploads\/2020\/12\/e2eba771.png\" alt=\"\" width=\"985\" height=\"164\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"PSReadLine_History_File\"><\/span>PSReadLine History File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Since we have talked about the history file, it can be useful to know where this file is actually stored. What\u2019s contained within is each command on a new line, with no additional data in a simple format.<\/p>\n<ul>\n<li><strong>Windows<\/strong> \u2013 <code>$env:<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">APP<\/a>DATA\\Microsoft\\Windows\\PowerShell\\PSReadLine<\/code><\/li>\n<li><strong>Linux<\/strong> \u2013 <code>$env:XDG_DATA_HOME\/powershell\/PSReadLine<\/code> or <code>$env:HOME\/.local\/share\/powershell\/PSReadLine<\/code><\/li>\n<\/ul>\n<blockquote><p><em>Be aware! When using cmdlets like <code>ConvertTo-SecureString<\/code> passwords may be stored in the history file.<\/em><\/p>\n<\/blockquote>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>PSReadLine is a very useful module to enhance your command-line experience. With multi-line editing, syntax highlighting, and the recent addition of Predictive IntelliSense, it is an indispensable addition to any system administrators toolkit!\n<\/p><\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong>\n<\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/8722\/using-psreadline-in-powershell\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#Using PSReadLine in PowerShell \u2013 CloudSavvy IT&#8221; PSReadLine is one of those modules that may not immediately show its utility until regular use. If you use the command-line of PowerShell often, PSReadLine can make your life much easier. Included in PowerShell versions as far back as Windows PowerShell 5, PSReadLine continues to add new features&#8230;<\/p>\n","protected":false},"author":1,"featured_media":146832,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/03\/23e4a5a4.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-146831","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/146831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=146831"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/146831\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/146832"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=146831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=146831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=146831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}