How to modify the Windows PowerShell prompt
Windows PowerShell supports configuration files. You can create configuration files and modify them through configuration files.
Configuration file path
Open a Windows Powershell and execute the following command to view the file path
$PROFILE | Select-Object *
According to the result output, you can viewCurrentUserAllHosts
What is the configuration path? This variable is all the hosts of the current user. Just create or modify this file.
refer to:/zh-cn/powershell/module//about/about_profiles?view=powershell-7.4
Configuration prompt
The Windows Powershell prompt is composed of the functionPrompt
To determine, so you can redefine this function in the configuration file and modify the return value.
For example, because the file path may be relatively long, I enter the command on a new line and add the current time. The demo is as follows:
# Modify powershell prompt
function prompt
{
$curtime = Get-Date -Format "HH:mm:ss";
Write-Host "PS: $pwd";
Write-Host -ForegroundColor Green "$curtime" -NoNewLine;
return " > ";
}
refer to:/zh-cn/powershell/module//about/about_prompts?view=powershell-7.4,
/zh/howto/powershell/change-colors-in-powershell/
Other options
A more complete solution can also be used, such as/p/444165353