美化你的PowerShell

先上效果图:

打开(或创建)C:\Users\【你的用户名】\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1,加入以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
function prompt {
Write-Host -NoNewline "# " -ForegroundColor Blue
Write-Host -NoNewline "$env:UserName" -ForegroundColor Cyan
Write-Host -NoNewline " @ "
Write-Host -NoNewline "$env:ComputerName" -ForegroundColor Green
Write-Host -NoNewline " in "
$path = "$pwd" -replace "C:\\Users\\【你的用户名】", "~"
Write-Host -NoNewline "$path" -ForegroundColor Yellow
$now = Get-Date -Format "tt hh:mm:ss"
Write-Host " [$now]"
return "$ "
}