PowerShell CheatSheet – Console Customization

Want to make the PS Console your own?

  1. Colors
    Turns the console’s background

    [console]::BackgroundColor="DarkRed"
    

    Turns the characters color

    [console]::ForegroundColor="White"
    

    Gets back the default colors parameters

    [console]::ResetColor() ; cls
    
  2. Layout
    Increases the buffer’s height

    [console]::BufferHeight=3000
    

    Increases the buffer’s width

    [console]::BufferWidth=120
    

    Gets back the default Buffer parameters

    [console]::BufferHeight=300
    [console]::BufferWidth=80
    

    Increases the console’s windows height

    [console]::WindowsHeight=100
    

    Increases the console’s windows width

    [console]::WindowsWidth=120
    

    Gets back the default console’s windows parameters

    [console]::WindowsHeight=25
    [console]::WindowsWidth=80
    
  3. Fonts
    Use ‘Consolas’ font in your console

    $key = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont"
      
    ## Find out if Consolas is installed on the system
    if(!(test-path (join-path $env:windir "Fonts\CONSOLA.TTF")))
    {
            write-host "The Consolas font is not installed on the system."
            write-host "Install Microsoft Office 2007 Beta to obtain the font."
            break
    }
      
    ## Determine if Consolas is already installed as a command window font
    $installed = get-itemproperty $key |
                 get-member |
                 where-object { $_.Name -match "^0+$" } |
                 where-object { $_.Definition -match "Consolas" }
    if($installed -ne $null)
    {
            write-host "The Consolas font is already installed as a command window font."
            break
    }
      
    ## Find out what the largest string of zeros is
    $zeros = (get-itemproperty $key |
             get-member |
             where-object { $_.Name -match "^0+$" } |
             measure-object).Count
      
    ## Install the font
    new-itemproperty $key -Name ("0" * ($zeros + 1)) -Type string -Value "Consolas"
    write-host "Consolas font installed successfully as a command window font."
    

    Needs at least a logoff/logon to be effective.

  4. Misc.
    Modifies the console’s title

    [console]::Title="My custom PowerShell console"
    

    Modifies the cursor’s size

    [console]::CursorSize=100
    

    Hides the cursor

    [console]::CursorVisible=$false
    

    Makes her shout!

    [console]::Beep()
    

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top