Windows Tip Sheet

Taking Title

Update info in a command window's title bar with this handy trick.

Here's another tip on moving from CMD to PowerShell. Back in the day you could use the Title command to change the title bar of the command prompt window. This was very handy if you were executing a long-running batch file. You could periodically update the title bar, minimize the window and still keep track of the script's progress. Today, my long-running script could very well be in PowerShell. Unfortunately, it doesn't support the old Title command.

Instead, I created my own title function and alias, which I store in my PowerShell profile:

function Set-Title {
Param ([string]$NewTitle)

Set-Alias title Set-Title

The Set-Title function, which has the alias of "title," takes as a parameter the text I want for the window's title bar. Any text with spaces I need to enclose in double quotes. Functionally (no pun intended), my title function works the same as the old title command. However, PowerShell let's me take it a step further.

In CMD there was no way to save or restore the original title text. In PowerShell, I can query the WindowTitle property and save it to a variable. I've added this function as well to my profile:

function Save-Title {

If I know I'm going to be changing title, I'll call Save-Title first to store the current title text. When I'm finished with my code, I can call Set-Title $SavedTitle, and my PowerShell session title is restored.

Assuming you have the above functions in your profile or at the beginning of this script, here's an example of how they can be used:


"REPORT CREATED "+(get-date).ToString() | Out-File $report

foreach ($server in @(Get-Content s:\servers.txt)) {
#skip blank lines
  if (($server).length -gt 0)
  $newtitle="Checking " + $server.ToUpper()
    title $newtitle
    $server.ToUpper() | Out-File $report -append
    "PageFile" | Out-File $report -append
    Get-WmiObject win32_pagefile -computer $server.Trim() '
    | Out-File $report -append
    "OS" | Out-File $report -append
    Get-WmiObject win32_operatingsystem -computer '
    $server.Trim() | Out-File $report -append
    "ComputerSystem" | Out-File $report -append
    Get-WmiObject win32_computersystem -computer '
    $server.Trim() | Out-File $report -append
      #pause for a few seconds just to show title in action
      #not really required.
      sleep 5

#revert back to old title
Title $savedtitle
#view report
Notepad $report

Tech Help—Just An
E-Mail Away



I don't have space to get into the details of this script (these tips are supposed to be quick, remember?). But it reads through the list of servers in s:\servers.txt. It sets the title to indicate what server the script is checking, gets some information from WMI and saves the data to a text file. When finished it opens the report in Notepad.

The script itself isn't anything special; it's merely a vehicle to demonstrate how you can take title of PowerShell.

About the Author


comments powered by Disqus

SharePoint Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.