Last active
August 29, 2015 14:16
-
-
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.
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
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