Note: This post is an update from a previous post. I have learned a bit since then and decided it was time for a refresh and to clean it up a little.
Add to your $Profile.CurrentUserAllHosts file so that you have a consistent prompt over all consoles.
Create the profile if it does not exist:
New-Item $Profile.CurrentUserAllHosts -Force -Confirm:$false
Then open the new file.
Invoke-Item $Profile.CurrentUserAllHosts
Copy and paste the below into the file and save.
Hope you find this useful. I have included full comments for your learning.
# SHELL CUSTOMISATION: --------------------------------------------------------
# COMMON MODULES: -------------------------------------------------------------
Import-Module -Name Terminal-Icons
# HELPER FUNCTIONS: -----------------------------------------------------------
function Test-RunAsAdministrator {
$Principal = [Security.Principal.WindowsPrincipal] ([Security.Principal.WindowsIdentity]::GetCurrent())
if ($Principal.IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) {
return $true
} else {
return $false
} # END if ($Principal.IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator"))
} # END function Test-RunAsAdministrator
# SET-LOCATION:----------------------------------------------------------------
# Capture the current security principal context:
# If in Admin Mode set location to user profile for safety.
if (Test-RunAsAdministrator -eq $false) {
Set-Location $env:USERPROFILE
} # if (Test-RunAsAdministrator -eq $true)
# MOTD BANNER: ----------------------------------------------------------------
$Context = $env:USERNAME + '@' + $Env:COMPUTERNAME
$SystemInfo = Get-CimInstance -Class CIM_OperatingSystem
$LastBootUpTime = $SystemInfo.LastBootUpTime
$Time = (Get-Date) - $LastBootUpTime
# Weather:
# Review https://github.com/chubin/wttr.in for docs and options.
# Check if running in the ISE:
if ($psIse) {
# ISE displays incorrectly so use a one-liner format.
$Weather = (Invoke-WebRequest wttr.in/Dunedin?format=3).Content
} else {
$Weather = (Invoke-WebRequest wttr.in/Dunedin?0AQFn).Content
} # END if ($psIse)
$MOTD = @"
_ _ _ ___ __
/\/\ __ _| | _____ (_) |_ / _ \___ / _\ /\ /\
/ \ / _` | |/ / _ \ | | __| / /_)/ _ \\ \ / /_/ /
/ /\/\ \ (_| | < __/ | | |_ / ___/ (_) |\ \/ __ /
\/ \/\__,_|_|\_\___| |_|\__| \/ \___/\__/\/ /_/
$Context | $($SystemInfo.Caption) $($SystemInfo.OSArchitecture)
Uptime: [ $($Time.Days) Days, $($Time.Hours) Hrs, $($Time.Minutes) Mins ]
$Weather
"@
Write-Host $MOTD -ForegroundColor DarkCyan
# CUSTOM PROMPT: --------------------------------------------------------------
function Prompt {
<#
RESULT:
Colourised Prompt based on Admin Context or Location.
TimeStamp | History ID | Location
[ 07:32:34 ] [ 1 ]: C:\windows\System32
≥
#>
# DEFINE VARIABLES: -------------------------------------------------------
$Location = ($ExecutionContext.SessionState.Path.CurrentLocation).Path
$TimeStamp = (Get-Date -UFormat %T).ToString()
$AdminMode = [ConsoleColor]::Yellow
$UserMode = [ConsoleColor]::DarkGray
$LocationWarning = [ConsoleColor]::Red
$CmdPromptChar = (0x2265 -as [char]).ToString()
# BUILD THE PROMPT: -------------------------------------------------------
# Check PowerShell Debugging context:
if ($PSDebugContext) {
# Debug Context. Prefix the prompt with [DBG]:
$Prompt = "[DBG] [ $TimeStamp ] [ $($MyInvocation.HistoryId) ]: $Location "
} else {
# Standard prompt:
$Prompt = "[ $TimeStamp ] [ $($MyInvocation.HistoryId) ]: $Location "
} # END if ($PSDebugContext)
# Use console colour to indicate Admin/User mode and warn on working directory (as appropriate).
# Check if in Windows System 32:
if ($Location -eq "$env:SystemRoot\system32" ) {
# Location Warning: Set the prompt warning colour and write the prompt to host:
Write-Host $Prompt -ForegroundColor $LocationWarning
} elseif (Test-RunAsAdministrator) {
# Admin Mode: Set the prompt warning colour and write the prompt to host:
Write-Host $Prompt -ForegroundColor $AdminMode
} else {
# User Mode: Set the prompt warning colour and write the prompt to host:
Write-Host $Prompt -ForegroundColor $UserMode
} # END if ($Location -eq "$env:SystemRoot\system32" )
# Check if nested prompt.
# Add the command prompt char to the next line for cleaner console and cleaner copy and paste.
Write-Host ($(if ($NestedPromptLevel -ge 1) { ">> " } else { $CmdPromptChar + ' ' }) ) -NoNewline
# PowerShell expects a string. Return empty string otherwise the prompt defaults to 'PS>'.
Return ' '
} # END function Prompt #######################################################
A sample of the result:

Happy Coding!