Set-PromptisAdmin.ps1
19 Sep 2025Description
Purpose
Sets the console window title to display the current user’s username, privileges, and current path.
Detailed Description
This function sets the console window title to display the current user’s username, followed by their privileges (either “Admin Privileges” or “User Privileges”), and the current path.
Usage
Example 1
Set-TitleisAdmin
Notes
No additional notes.
Script
function Set-TitleisAdmin {
<#
.SYNOPSIS
Sets the console window title to display the current user's username, privileges, and current path.
.DESCRIPTION
This function sets the console window title to display the current user's username, followed by their privileges (either "Admin Privileges" or "User Privileges"), and the current path.
.PARAMETER None
This function does not accept any parameters.
.EXAMPLE
Set-TitleisAdmin
#>
$Username = whoami.exe /upn
$CurrentPath = $PWD.Path
if (Test-IsAdmin) {
$host.UI.RawUI.WindowTitle = "$($Username) - Admin Privileges - Path: $($CurrentPath)"
}
else {
$host.UI.RawUI.WindowTitle = "$($Username) - User Privileges - Path: $($CurrentPath)"
}
}
function Set-PromptisAdmin {
<#
.SYNOPSIS
Sets the PowerShell prompt to display whether the current session is running as an administrator or not.
.DESCRIPTION
This function sets the PowerShell prompt to display "(Admin)" if the current session is running as an administrator, or "(User)" if it is not.
.PARAMETER None
This function has no parameters.
.EXAMPLE
Set-PromptisAdmin
This example sets the PowerShell prompt to display whether the current session is running as an administrator or not.
.NOTES
This function requires the Test-IsAdmin and Set-TitleisAdmin functions to be defined.
#>
if (Test-IsAdmin) {
function global:prompt {
Set-TitleisAdmin
"(Admin) $PWD> "
}
}
else {
function global:prompt {
Set-TitleisAdmin
"(User) $PWD> "
}
}
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.