Last active
October 22, 2016 12:19
-
-
Save Sarafian/bededa13bf53c3859d0ffdc7ebdf6416 to your computer and use it in GitHub Desktop.
Set/Reset a prefix on the PowerShell's Console Window title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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