title: Customizing PowerShell Prompt - Equivalent to CMD's $M$P$_$+$G?
body: <p>I've started to "play around" with PowerShell and am trying to get it to "behave".</p>
  
  <p>One of the things I'd like to do is to customize the PROMPT to be "similar" to what "$M$P$_$+$G" do on MS-Dos:</p>
  
  <p>A quick rundown of what these do:</p>
  
  <p><b>Character</b><b>| Description</b><br>
  <b>$m  </b> The remote name associated with the current drive letter or the empty string if current drive is not a network drive. <br>
  <b>$p  </b> Current drive and path <br>
  <b>$_  </b> ENTER-LINEFEED  <br>
  <b>$+  </b> Zero or more plus sign (+) characters depending upon the depth of the <b>pushd</b> directory stack, one character for each level pushed <br>
  <b>$g  </b> > (greater-than sign) <br></p>
  
  <p>So the final output is something like:</p>
  
  <pre><code>    \\spma1fp1\JARAVJ$ H:\temp
      ++&gt;
  </code></pre>
  
  <p>I've been able to add the <code>$M</code> and <code>$_</code> functionality (and a nifty History feature) to my prompt as follows:</p>
  
  <pre><code>function prompt
  {
     ## Get the history. Since the history may be either empty,
     ## a single item or an array, the @() syntax ensures
     ## that PowerShell treats it as an array
     $history = @(get-history)
  
  
     ## If there are any items in the history, find out the
     ## Id of the final one.
     ## PowerShell defaults the $lastId variable to '0' if this
     ## code doesn't execute.
     if($history.Count -gt 0)
     {
        $lastItem = $history[$history.Count - 1]
        $lastId = $lastItem.Id
     }
  
     ## The command that we're currently entering on the prompt
     ## will be next in the history. Because of that, we'll
     ## take the last history Id and add one to it.
     $nextCommand = $lastId + 1
  
     ## Get the current location
     $currentDirectory = get-location
  
     ## Set the Windows Title to  the current location
     $host.ui.RawUI.WindowTitle = "PS: " + $currentDirectory
  
     ## And create a prompt that shows the command number,
     ## and current location
     "PS:$nextCommand $currentDirectory
  &gt;"
  }
  </code></pre>
  
  <p>But the rest is not yet something I've managed to duplicate....</p>
  
  <p>Thanks a lot for the tips that will surely come!</p>