Custom prompt and Start-Transcript

This topic contains 11 replies, has 3 voices, and was last updated by  Joel Sallow 1 month ago.

  • Author
    Posts
  • #99333

    Jason Robinson
    Participant

    I created a custom prompt using the following:

    function prompt {"$(get-date) + >"}

    Then I run Start-Transcript to start logging. When I review the transcript the cmdlet I ran does not align with the custom prompt, but rather a new prompt on the line below it. Here is an example:

    Transcript started, output file is C:\Users\xxxx\Documents\PowerShell_transcript.DESKTOP-U995LEF.qwCyiDP8.20180420113112.txt
    04/20/2018 11:31:12>
    PS>get-process powershell

    Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
    ——- —— —– —– —— — — ———–
    692 31 61116 76268 1.36 11236 1 powershell

    Without the custom prompt the executed cmdlet is on the same line as the prompt, example:

    Transcript started, output file is C:\Users\Jason\Documents\PowerShell_transcript.DESKTOP-U995LEF.yDgSPx+e.20180420120046.txt
    PS C:\Temp> get-process powershell

    Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
    ——- —— —– —– —— — — ———–
    747 31 74236 86172 2.03 11236 1 powershell

    Is there anyway to use a custom prompt and have start-transcript align the typed commands with the custom prompt?

  • #99343

    Bill Kindle
    Participant

    What you are seeing I believe is expected. PS> means you ran a PowerShell cmdlet or set of commands at the prompt you created.

    If you start a new transcript, try switching to command prompt by issuing 'cmd' and pressing enter. This will change your shell. to go back to powershell you type 'exit' and press enter or open a new shell again by typing 'powershell' and pressing enter.

    Each of these shells will show up in the transcript, followed by whatever command / output goes with that shell.

    Now, if you are wanting your prompt to always be displayed, you may want to look at adding that function to your profile.

    • #99346

      Jason Robinson
      Participant

      Thanks for the reply. What I would like is my custom prompt and command to be on the same line in the transcript, example:

      04/20/2018 11:31:12>get-process powershell

      When running powershell with the default prompt this occurs, why would this change with a custom prompt?

    • #99349

      Bill Kindle
      Participant

      This makes a little more sense now. Try adding your custom prompt function to your PowerShell profile (should be in Documents\WindowsPowerShell) 'profile.ps1'. Once you've added it, start a new console and you should see your custom prompt immediately. Then use

      Start-Transcript -Path .\transcript.txt

      to begin your transcript, followed by whatever cmdlets you want to run. Then

      Stop-Transcript

      . Then to view the transcript, simply run

      notepad .\transcript

      and you should see your customized prompt lined up how you want it.

      Here's an example from a test I ran:

      Configuration Name:
      Machine: FTW-12278 (Microsoft Windows NT 10.0.16299.0)
      Host Application: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile
      Process ID: 16964
      PSVersion: 5.1.16299.194
      PSEdition: Desktop
      PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.16299.194
      BuildVersion: 10.0.16299.194
      CLRVersion: 4.0.30319.42000
      WSManStackVersion: 3.0
      PSRemotingProtocolVersion: 2.3
      SerializationVersion: 1.1.0.1
      **********************
      Transcript started, output file is .\psorg4.txt
      PS C:\Users\wkindle\PScripts> Get-Process

      Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
      ——- —— —– —– —— — — ———–
      319 50 20220 6020 972.34 4664 0 AgentService
      133 11 2264 1244 24.33 14392 2 ApMsgFwd
      142 11 2204 2016 134.50 5072 2 ApntEx

    • #99352

      Jason Robinson
      Participant

      It make no difference. They are still not on the same line.

      Profile

      function prompt {"$(Get-Date)>"}

      Transcript:
      Transcript started, output file is C:\Users\Jason\Documents\PowerShell_transcript.DESKTOP-U995LEF.R6iiKpvk.20180420135511.txt
      04/20/2018 13:55:11>
      PS>get-date

      Friday, April 20, 2018 1:55:14 PM

    • #99357

      Bill Kindle
      Participant

      Please paste the full contents of your PowerShell profile here.

    • #99366

      Jason Robinson
      Participant

      There is nothing else in my profile. Only the one prompt function.

  • #99361

    Joel Sallow
    Participant

    I suppose it's possible that the transcript commands override the custom prompt somewhat if it doesn't contain certain characters, though I'd find that odd. Just to see, try prefixing 'PS' to the custom prompt and see if it behaves:

    function prompt {
    "PS $(Get-Date)>"
    } 
    • #99363

      Jason Robinson
      Participant

      Adding PS to the prompt did not seem to make a difference.

      function prompt {"PS$(Get-Date)>"}

      Transcript started, output file is C:\Users\Jason\Documents\PowerShell_transcript.DESKTOP-U995LEF.GHTqJZkg.20180420150327.txt
      PS04/20/2018 15:03:27>
      PS>get-date

      Friday, April 20, 2018 3:03:29 PM

  • #99372

    Joel Sallow
    Participant

    Try passing the prompt value with Write-Host instead of letting it fall to output, maybe? This is weird...

    function prompt {Write-Host "$(Get-Date)>"}
    • #99382

      Jason Robinson
      Participant

      No dice, same result in the transcript.

      Transcript started, output file is C:\Users\Jason\Documents\PowerShell_transcript.DESKTOP-U995LEF.LdPi_BxD.20180420162331.txt
      04/20/2018 16:23:31>
      PS>get-date

      Friday, April 20, 2018 4:23:34 PM

      Is it possible to test to see if you have the same results? I've tested on two machines and I am getting the same on both, but want to make sure it is not just me.

      Version : 5.1.16299.251

  • #99390

    Joel Sallow
    Participant

    Same result for me:

    PS C:\Users\xxxx> function prompt { "PS $(Get-Date) $(Split-Path -Leaf $pwd)>" }
    PS 04/20/2018 18:35:47 xxxx>
    PS C:\Users\xxxx> cd ..
    PS 04/20/2018 18:35:51 xxxx>
    PS C:\Users\xxxx> get-ChildItem

    Weird. I'm gonna step on over to the Github and see if there's any open issues for this.

You must be logged in to reply to this topic.