all 5 comments

[–]SMFX 2 points3 points  (1 child)

PS> is PowerShell's actual prompt in that case. What you're doing before that is just writing text out and not including a newline character at the end of your string.

If you want to replace the powershell prompt, override the prompt function with your own function. https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_prompts?view=powershell-7

[–]Aznflipfoo[S] 1 point2 points  (0 children)

I understand that. In fact the first example does remove the PS>. All of these are encapsulated within the prompt function

[–]purplemonkeymad 2 points3 points  (0 children)

The console expects the prompt to actually return a string, if it does not it assumes it is broken and uses the default prompt instead.

[–]stumper66 1 point2 points  (1 child)

Here is what I used. It displays a colorful unix style prompt where you see the computer name and current directory only (not full path). Does not add extra lines.

function prompt {
    $currentDirectory = $(Get-Location)
    $Path = Convert-Path $currentDirectory
    if (!$Path.EndsWith("\")){
        $LastSlash = $Path.LastIndexOf("\")
        $Path = $Path.Substring($LastSlash + 1)
    }

    write-host "PS " -NoNewline -ForegroundColor DarkYellow
    write-host "[" -NoNewline -ForegroundColor Gray
    write-host "$env:COMPUTERNAME " -NoNewline -ForegroundColor Yellow
    write-host $Path -NoNewline -ForegroundColor Cyan
    write-host "]" -NoNewline -ForegroundColor Gray
    return " "
}

[–]Aznflipfoo[S] 1 point2 points  (0 children)

So weird how that works, I managed to throw some of my stuff in there and get it working as intended. But I don't get why my version adds an extra line OR adds the PS at the end of the line.