Skip to content

Instantly share code, notes, and snippets.

@vScripter
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vScripter/84faa2dd6a7c0a9ae105 to your computer and use it in GitHub Desktop.
Save vScripter/84faa2dd6a7c0a9ae105 to your computer and use it in GitHub Desktop.
Set-ConsoleWindowTitle - Set the PowerShell console window title to a custom message or a custom 'default' message.
function Set-ConsoleWindowTitle {
[cmdletbinding()]
param (
[parameter(Mandatory = $true,
Position = 0,
ParameterSetName = 'Default')]
[validateset("Default", "Custom")]
[string]$MessageType,
[parameter(Mandatory = $false,
Position = 1,
ParameterSetName = 'Default')]
[string]$Message
) # param
BEGIN {
$defaultTitle = $host.ui.RawUI.WindowTitle = "$env:COMPUTERNAME - $env:USERNAME"
} # BEGIN
PROCESS {
switch ($MessageType) {
'Default' {
if ($host.Name -eq 'ConsoleHost') {
$host.ui.RawUI.WindowTitle = $defaultTitle
} # end if
} # Default
'Custom' {
if ($host.Name -eq 'ConsoleHost') {
$host.ui.RawUI.WindowTitle = $Message
} # end if
} # Custom
} # switch
} # PROCESS
} # function Set-ConsoleWindowTitle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment