Setting PowerShell Terminal Options

16 May 2022, 12:32 p.m.
01:09 minutes

During a pentest engagement, you often come across the need for a screenshot for the report. Using the `$host.UI` parameter inside our PowerShell terminal we can do things like set the window title, change the foreground and background colours along with adjusting the size and position. This article looks at how setting values within the `$host.UI` variable can customise our PowerShell terminal.

    Set PowerShell Terminal Options

    We can set values within the terminal to customise how the terminal output is displayed, the title of the terminal window shown or how much buffer size to use. Using these values can be helpful for several things, such as distinguishing windows, staging the title for a report screenshot or improved recognition of terminal output.

    Terminal Displaying Styling

    Screen Buffer

    Get the current screen buffer.

    $host.UI.RawUI.BufferSize
    

    Enlarge the terminal screen buffer to capture more output

    $host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(120,999)
    

    Console Style (for quick identification).

    Set Console Title

    $host.ui.RawUI.WindowTitle = "Staged Window Title For Screenshot"
    

    Set Console Colours

    $Host.UI.RawUI.BackgroundColor = 'Black'
    $Host.UI.RawUI.ForegroundColor = 'Green'
    

    Set Window Position

    Find out what the current window position is

    $host.UI.RawUI.WindowPosition
    

    Set window position

    $host.UI.RawUI.WindowPosition = New-Object System.Management.Automation.Host.Coordinates(0,160)
    

    Captcha: What's the standard TCP port of the following service?

    captcha

    0 comments