Location>code7788 >text

Windows PowerShell terminal configuration

Popularity:248 ℃/2025-01-22 11:40:48

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 viewCurrentUserAllHostsWhat 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 functionPromptTo 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