Skip to content

Instantly share code, notes, and snippets.

@Sarafian
Last active October 22, 2016 12:19
Show Gist options
  • Save Sarafian/bededa13bf53c3859d0ffdc7ebdf6416 to your computer and use it in GitHub Desktop.
Save Sarafian/bededa13bf53c3859d0ffdc7ebdf6416 to your computer and use it in GitHub Desktop.
Set/Reset a prefix on the PowerShell's Console Window title
<#
.Synopsis
Reset the window title of the console
.DESCRIPTION
Reset the window title of the console
.EXAMPLE
Reset-PrefixedTitle
#>
function Reset-PrefixedTitle
{
$originalTitle=Get-Variable -Name "__OriginalWindowTitle__" -Scope Global -ValueOnly -ErrorAction SilentlyContinue
if($originalTitle)
{
Remove-Variable -Name "__OriginalWindowTitle__" -Scope Global
}
$host.ui.RawUI.WindowTitle=$originalTitle
}
<#
.Synopsis
Sets a prefix on the window title of the console
.DESCRIPTION
Sets a prefix on the window title of the console. e.g [prefix] original title
.PARAMETER Prefix
The prefix to set on the title
.EXAMPLE
Set-PrefixedTitle -Prefix "MyPrefix"
#>
function Set-PrefixedTitle
{
param (
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Prefix
)
$originalTitle=Get-Variable -Name "__OriginalWindowTitle__" -Scope Global -ValueOnly -ErrorAction SilentlyContinue
if(-not $originalTitle)
{
$originalTitle=$host.ui.RawUI.WindowTitle
Set-Variable -Name "__OriginalWindowTitle__" -Value $originalTitle -Scope Global
}
$host.ui.RawUI.WindowTitle="[$Prefix] $originalTitle"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment