{"id":145,"date":"2007-06-06T21:56:49","date_gmt":"2007-06-07T05:56:49","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/06\/06\/do-you-need-some-prompting\/"},"modified":"2007-06-06T21:56:49","modified_gmt":"2007-06-07T05:56:49","slug":"do-you-need-some-prompting","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/06\/06\/do-you-need-some-prompting\/","title":{"rendered":"Do you need some prompting?"},"content":{"rendered":"<p>During Don&#8217;s TechEd session that was simulcast on the web, I was furiously answering questions for the online crowd. One of the questions was about Don&#8217;s PowerShell prompt.&nbsp; Every time he pressed Enter, a command counter was incremented and displayed like this:<\/p>\n<p>[137] PSH C:\\temp &gt;<\/p>\n<p>I don&#8217;t exactly what Don used, but here&#8217;s a prompt function that I came up with to achieve this effect:<\/p>\n<p><font face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">Function Prompt {<br \/>#[137] PSH C:\\temp &gt;<br \/># You need to define $global:i=0<br \/># in your profile before you run this function<br \/># You can reset $i to 0 at any time if you want<br \/># to &#8220;reset&#8221; the prompt counter<br \/>$global:i++<br \/>&#8221;[&#8220;+$i+&#8221;] PSH &#8221; +&nbsp; $(Get-Location) + &#8221; &gt; &#8220;<br \/>}<\/font> <\/p>\n<p>In your profile, which is where you would add this function, you&#8217;ll also need to define a global counter variable.<\/p>\n<p><font face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">$global:i=0<\/font><\/p>\n<p>The prompt function will increment this counter each time you press Enter. If you want to start again at 0, simply set $i back to 0. Short and simple.<\/p>\n<p>But this got me thinking&#8230;what else can I do with my PowerShell prompt? My prompt includes the current date and location displayed in yellow:<\/p>\n<p>Wed 6\/6\/2007 12:29:28 PM PS C:\\Documents and Settings\\jhicks &gt;<\/p>\n<p>But what about having a prompt that displays CPU utilization and the number of running processes:<\/p>\n<p>[CPU:7% Procs:66] PS C:\\temp &gt;<\/p>\n<p>What about a prompt that displays the current user:<\/p>\n<p>PS [SAPIEN\\JHICKS 3:03 PM] C:\\temp &gt;<\/p>\n<p>One of my favorites that I came up with, at least for a short term, is to have the current location spoken:<\/p>\n<p><font face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">function Prompt {<br \/>#Install SAPIEN Community extensions and use Write-Speech to <br \/>#speak the current directory<br \/>Get-Location | Write-Speech <br \/>$myPrompt=&#8221;PSH &#8221; +&nbsp; $(Get-Location) + &#8221; &gt; &#8220;<br \/>Write-Host ($myPrompt) -nonewline<br \/>return &#8221; &#8220;<br \/>}<\/font> <\/p>\n<p>I&#8217;ve attached a text file with all the prompt functions that I&#8217;ve mentioned here plus a few more.&nbsp; Once you look at the samples you&#8217;ll see how easy it is to mix and match information.<\/p>\n<p>Enjoy.<\/p>\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:a505d6e0-abd5-47dc-820c-a496abfe8fb7\" class=\"wlWriterSmartContent\">Technorati Tags: <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/PowerShell\">PowerShell<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Prompt\">Prompt<\/a><\/div>\n<p> <\/p>\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:981710ea-5e4f-4fe3-8410-ad24f7b6c010\" class=\"wlWriterSmartContent\">del.icio.us Tags: <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/PowerShell\">PowerShell<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/Prompt\">Prompt<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>During Don&#8217;s TechEd session that was simulcast on the web, I was furiously answering questions for the online crowd. One of the questions was about Don&#8217;s PowerShell prompt. I thought I&#8217;d figure out what Don did plus came up with a bunch of new prompts you can use.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-145","post","type-post","status-publish","format-standard","hentry","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=145"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/145\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}