PowerShell Out-ConsoleGridView and F7History

I saw these two console tools for PowerShell in my newsfeed, and I like them 🙂 This blog post will show you what they are and how they work.

What is F7History?

In older PowerShell versions, pressing F7 gave you a list of previous commands you could select and run again. This option is no longer available in newer versions of PowerShell when using the PSReadline module, and that’s where F7History comes in. When using this module, it’s possible to show previous commands again using F7 instead of scrolling back with the Up-arrow and searching using Ctrl-R.

What is Out-ConsoleGridView?

In PowerShell, you have the option to output information to Out-GridView. This depends on PowerShell ISE (So, for everyone who removes that from Windows… Don’t 🙂 ). The Out-ConsoleGridView cmdlet does the same thing, but instead of popping a separate Window… It displays it inside your PowerShell terminal and has the excellent Filter option at the top.

Dependencies

The Out-ConsoleGridView cmdlet is dependent on the Microsoft.PowerShell.ConsoleGuiTools module. The F7History has a dependency on the Out-ConsoleGridView, PSReadline, and Microsoft.PowerShell.ConsoleGuiTools modules.

Note: Both are only available starting from PowerShell v7.2 because of the dependency on Microsoft.PowerShell.ConsoleGuiTools

F7History

Installation

You can add F7History to your system by installing the module by running the following:

Install-Module F7History

To have it available in all your sessions, you can add this to your profile like this:

- Notepad $profile
- Add Import-Module -Name "F7History" to the file
- Quit/Save and start a new PowerShell session

Usage

After running import-module F7History, pressing F7 will show you this:

You can use the Up or Down arrow key to select a command from the list and press Enter to run that command again. If you use the Tab key, it will jump into the Filter line so that you can search for a specific command if the list of previous commands is too extensive.

But if you want to see all your history, you can press Shift-F7. This will look almost the same, but it will also tell you when you ran a specific command:

Documentation

If you want to read more about F7History, follow these links:

GitHub

PowerShellGallery

Out-ConsoleGridView

Installation

You can add Out-ConsoleGridView to your system by installing the ConsoleGuiTools. You can do that by running the following:

Install-Module microsoft.powershell.consoleguitools

Usage

When installed, you can use Out-ConsoleGridView to display your output inside your Terminal and use it to select or filter items. For example:

Get-Service | Out-ConsoleGridView

will show you this:

You can select one item by using Space and use CTRL-A to select them all, for example:

This is useful if you start Out-ConsoleGridview and want to use that to select several items which should be stored in a variable. For example:

$services=Get-Service | Out-ConsoleGridView

This is display all services (Just like the list in the previous screenshots), and I selected the first four items. After pressing Enter to Accept, the Out-ConsoleGridView closes, and my $services variable contains the four selected items:

C:\Users\HarmVeenstra> $services

Status   Name               DisplayName
------   ----               -----------
Stopped  AarSvc_6667e2      Agent Activation Runtime_6667e2
Running  AdobeARMservice    Adobe Acrobat Update Service
Running  agent_ovpnconnect  OpenVPN Agent agent_ovpnconnect
Stopped  AJRouter           AllJoyn Router Service

You can also filter text in the Filter line by typing one or more characters. For example:

Typing “hy” started filtering the services overview into all lines matching that.

Documentation

If you want to read more about Out-ConsoleGridView, follow these links:

GitHub

PowerShellGallery

7 thoughts on “PowerShell Out-ConsoleGridView and F7History

  1. Upon entering:
    PS C:\WINDOWS\system32> install-module f7history

    I received this:
    NuGet provider is required to continue
    PowerShellGet requires NuGet provider version ‘2.8.5.201’ or newer to interact with NuGet-based repositories. The NuGet
    provider must be available in ‘C:\Program Files\PackageManagement\ProviderAssemblies’ or
    ‘C:\Users\bromberg.DESKTOP-V44B91G\AppData\Local\PackageManagement\ProviderAssemblies’. You can also install the NuGet
    provider by running ‘Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force’. Do you want PowerShellGet
    to install and import the NuGet provider now?
    [Y] Yes [N] No [S] Suspend [?] Help (default is “Y”):

    Do I want NuGet on my system?
    Thanks in advance to all who reply,
    Dan

    • It is needed for downloading the modules, if you haven’t installed any other modules on your system in the past… Then this question pops up. You could download the files for the modules manually and copy them to your modules folder, but NuGet is easier as package manager

      • I already use Chocolatey and Winget as package managers. I see where Nuget
        is used for .NET so I’m wondering what benefit (other than your marvelous F7History, of course) Nuget would be for me. I hate bloating my system unnecessarity.
        Thanks for your newsletter and reply.
        Dan

      • Ah, I understand… NuGet is needed for all modules that you want to download from the PSGallery. You could do without it, but it’s more work to download from GitHub and import

      • So I installed NuGet but now am stopped by this install error upon issuing the
        ‘Install-Module F7History’ command:

        Untrusted repository
        You are installing the modules from an untrusted repository. If you trust this repository, change its
        InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
        ‘PSGallery’?
        [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “N”): y
        WARNING: The externally managed, dependent module ‘System.Collections.Hashtable’ is not installed on this computer. To
        use the current module ‘F7History’, ensure that its dependent module ‘System.Collections.Hashtable’ is installed.

        Where do I get ‘System.Collections.Hashtable’? and what other modules might I have to install?

        Dan

      • The biggest dependency is they Microsoft.PowerShell.ConsoleGuiTools module, did you install that?

        C:\Users\HarmVeenstra> Get-Dependency -modulename f7history
        WARNING: Caching locally available modules. To skip this step, use parameter ‘availableModules’

        Type : Module
        Name : Microsoft.PowerShell.ConsoleGuiTools
        Version : 0.7.4
        Source : F7History
        Command :

  2. Pingback: Intune Newsletter - 28th July 2023 - Andrew Taylor

Leave a Reply

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