As a Linux Administrator for the last 10 or so years, I have become pretty accustomed to my the way that my command prompt is set up. Basically, it contains the hostname of the machine and the current director I am in:
(jefferson:~) %
Over the last week or so I have been playing around with VMware’s PowerCLI as a way to simplify my host deployment. While not having the hostname in it does not bother me, the one thing that has been really driving my crazy is the length of the command prompt:
The prompt takes up nearly all of the screen.
To fix it, I needed to modify Initialize-PowerCLIEnvironment.ps1 in C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts directory. I searched for the word prompt and found the global:prompt function. I commented out (Get-location).path and added a snippet that I found on Jason Williams’ Blog. I did have to make a slight modification to it, adding a \ to the split commands.
# Modify the prompt function to change the console prompt.
# Save the previous function, to allow restoring it back.
$originalPromptFunction = $function:prompt
function global:prompt{
# change prompt text
Write-Host "$productShortName " -NoNewLine -foregroundcolor Green
#Write-Host ((Get-location).Path + ">") -NoNewLine
Write-Host ((get-location).Path.Split("\")[(get-location).Path.Split
("\").Length -1] + ">") -NoNewLine
return " "
}
Now when I launch my PowerCLI command, I know had something much more manageable and familiar:
UPDATE: @jakerobinson let me know I could do the same thing with:
Write-Host ((Get-location).Path.Split('\')[-1] + ">") -NoNewLine

