• Stars
    star
    772
  • Rank 58,858 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created over 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Modules that mix PowerShell and GUIs/CUIs!

ConsoleGuiTools - Out-ConsoleGridView and Show-ObjectTree

This repo contains the Out-ConsoleGridView PowerShell Cmdlet providing console-based GUI experiences based on Terminal.Gui (gui.cs).

Note: A module named Microsoft.PowerShell.GraphicalTools used to be built and published out of this repo, but per #101 it is deprecated and unmaintained until such time that it can be rewritten on top of .NET MAUI.

Installation

Install-Module Microsoft.PowerShell.ConsoleGuiTools

Features

  • Out-ConsoleGridview - Send objects to a grid view window for interactive filtering and sorting.

  • Show-ObjectTree - Send objects to a tree view window for interactive filtering and sorting.

  • Cross-platform - Works on any platform that supports PowerShell 7.2+.

  • Interactive - Use the mouse and keyboard to interact with the grid or tree view.

  • Filtering - Filter the data using the built-in filter box.

  • Sorting - Sort the data by clicking on the column headers.

  • Multiple Selection - Select multiple items and send them down the pipeline.

  • Customizable - Customize the grid view window with the built-in parameters.

Demo GIF

Examples

Example 1: Output processes to a grid view

Get-Process | Out-ConsoleGridView

This command gets the processes running on the local computer and sends them to a grid view window.

Example 2: Use a variable to output processes to a grid view

$P = Get-Process
$P | Out-ConsoleGridView -OutputMode Single

This command also gets the processes running on the local computer and sends them to a grid view window.

The first command uses the Get-Process cmdlet to get the processes on the computer and then saves the process objects in the $P variable.

The second command uses a pipeline operator to send the $P variable to Out-ConsoleGridView.

By specifying -OutputMode Single the grid view window will be restricted to a single selection, ensuring no more than a single object is returned.

Example 3: Display a formatted table in a grid view

Get-Process | Select-Object -Property Name, WorkingSet, PeakWorkingSet | Sort-Object -Property WorkingSet -Descending | Out-ConsoleGridView

This command displays a formatted table in a grid view window.

It uses the Get-Process cmdlet to get the processes on the computer.

Then, it uses a pipeline operator (|) to send the process objects to the Select-Object cmdlet. The command uses the Property parameter of Select-Object to select the Name, WorkingSet, and PeakWorkingSet properties to be displayed in the table.

Another pipeline operator sends the filtered objects to the Sort-Object cmdlet, which sorts them in descending order by the value of the WorkingSet property.

The final part of the command uses a pipeline operator (|) to send the formatted table to Out-ConsoleGridView.

You can now use the features of the grid view to search, sort, and filter the data.

Example 4: Save output to a variable, and then output a grid view

($A = Get-ChildItem -Path $pshome -Recurse) | Out-ConsoleGridView

This command saves its output in a variable and sends it to Out-ConsoleGridView.

The command uses the Get-ChildItem cmdlet to get the files in the Windows PowerShell installation directory and its subdirectories. The path to the installation directory is saved in the $pshome automatic variable.

The command uses the assignment operator (=) to save the output in the $A variable and the pipeline operator (|) to send the output to Out-ConsoleGridView.

The parentheses in the command establish the order of operations. As a result, the output from the Get-ChildItem command is saved in the $A variable before it is sent to Out-ConsoleGridView.

Example 5: Output processes for a specified computer to a grid view

Get-Process -ComputerName "Server01" | ocgv -Title "Processes - Server01"

This command displays the processes that are running on the Server01 computer in a grid view window.

The command uses ocgv, which is the built-in alias for the Out-ConsoleGridView cmdlet, it uses the Title parameter to specify the window title.

Example 6: Define a function to kill processes using a graphical chooser

function killp { Get-Process | Out-ConsoleGridView -OutputMode Single -Filter $args[0] | Stop-Process -Id {$_.Id} }
killp note

This example shows defining a function named killp that shows a grid view of all running processes and allows the user to select one to kill it.

The example uses the -Filter paramter to filter for all proceses with a name that includes note (thus highlighting Notepad if it were running. Selecting an item in the grid view and pressing ENTER will kill that process.

Example 7: Pass multiple items through Out-ConsoleGridView

Get-Process | Out-ConsoleGridView -PassThru | Export-Csv -Path .\ProcessLog.csv

This command lets you select multiple processes from the Out-ConsoleGridView window. The processes that you select are passed to the Export-Csv command and written to the ProcessLog.csv file.

The command uses the PassThru parameter of Out-ConsoleGridView, which lets you send multiple items down the pipeline. The PassThru parameter is equivalent to using the Multiple value of the OutputMode parameter.

Example 8: Use F7 as "Show Command History"

Add gui-cs/F7History to your Powershell profile.

Press F7 to see the history for the current PowerShell instance

Press Shift-F7 to see the history for all PowerShell instances.

Whatever you select within Out-ConsoleGridView will be inserted on your command line.

Whatever was typed on the command line prior to hitting F7 or Shift-F7 will be used as a filter.

Example 9: Output processes to a tree view

PS C:\> Get-Process | Show-ObjectTree

This command gets the processes running on the local computer and sends them to a tree view window.

Use right arrow when a row has a + symbol to expand the tree. Left arrow will collapse the tree.

Development

1. Install PowerShell 7.2+

Install PowerShell 7.2+ with these instructions.

2. Clone the GitHub repository

git clone https://github.com/PowerShell/GraphicalTools.git

3. Install Invoke-Build

Install-Module InvokeBuild -Scope CurrentUser

Now you're ready to build the code. You can do so in one of two ways:

4. Building the code from PowerShell

pushd ./GraphicalTools
Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools
popd

From there you can import the module that you just built for example (start a fresh pwsh instance first so you can unload the module with an exit; otherwise building again may fail because the .dll will be held open):

pwsh
Import-Module ./module/Microsoft.PowerShell.ConsoleGuiTools

And then run the cmdlet you want to test, for example:

Get-Process | Out-ConsoleGridView
exit

NOTE: If you change the code and rebuild the project, you'll need to launch a new PowerShell process since the DLL is already loaded and can't be unloaded.

5. Debugging in Visual Studio Code

code ./GraphicalTools

Build by hitting Ctrl-Shift-B in VS Code.

Set a breakpoint and hit F5 to start the debugger.

Click on the VS Code "TERMINAL" tab and type your command that starts Out-ConsoleGridView, e.g.

ls | ocgv

Your breakpoint should be hit.

Contributions Welcome

We would love to incorporate community contributions into this project. If you would like to contribute code, documentation, tests, or bug reports, please read the development section above to learn more.

Microsoft.PowerShell.ConsoleGuiTools Architecture

ConsoleGuiTools consists of 2 .NET Projects:

  • ConsoleGuiTools - Cmdlet implementation for Out-ConsoleGridView
  • OutGridView.Models - Contains data contracts between the GUI & Cmdlet

Note: Previously, this repo included Microsoft.PowerShell.GraphicalTools which included the Avalonia-based Out-GridView (implemented in .\Microsoft.PowerShell.GraphicalTools and .\OutGridView.Gui). These components have been deprecated (see note above).

Maintainers

Originally authored by Tyler Leonhardt.

License

This project is licensed under the MIT License.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

More Repositories

1

PowerShell

PowerShell for every system!
C#
45,459
star
2

Win32-OpenSSH

Win32 port of OpenSSH
7,290
star
3

PSReadLine

A bash inspired readline implementation for PowerShell
C#
3,700
star
4

PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
C#
1,842
star
5

vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
TypeScript
1,687
star
6

DscResources

Central repository for PowerShell Desired State Configuration (DSC) resources.
772
star
7

platyPS

Write PowerShell External Help in Markdown
C#
765
star
8

PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
C#
623
star
9

Polaris

A cross-platform, minimalist web framework for PowerShell
PowerShell
507
star
10

PSResourceGet

PSResourceGet is the package manager for PowerShell
C#
483
star
11

PowerShellGetv2

PowerShellGet is the Package Manager for PowerShell
PowerShell
430
star
12

PowerShell-RFC

RFC (Request for Comments) documents for community feedback on design changes and improvements to PowerShell ecosystem
PowerShell
430
star
13

PowerShell-Docker

Repository for building PowerShell Docker images
Dockerfile
400
star
14

Crescendo

a module for wrapping native applications in a PowerShell function and module
PowerShell
397
star
15

SecretManagement

PowerShell module to consistent usage of secrets through different extension vaults
C#
321
star
16

JEA

Just Enough Administration
PowerShell
254
star
17

PowerShellGallery

PowerShell
228
star
18

Operation-Validation-Framework

PowerShell
223
star
19

DSC

This repo is for the DSC v3 project
Rust
192
star
20

SHiPS

Simple Hierarchy in PowerShell - developing PowerShell provider got so much easier
C#
188
star
21

PSSwagger

The cmdlet generator from OpenAPI (f.k.a Swagger) specification
PowerShell
164
star
22

PowerShellStandard

C#
157
star
23

SecretStore

C#
155
star
24

PSPrivateGallery

DSC Resources and Configurations to deploy and manage Private PowerShell Gallery
PowerShell
148
star
25

CompletionPredictor

C#
145
star
26

GPRegistryPolicyParser

PowerShell
140
star
27

WindowsCompatibility

Module that allows Windows PowerShell Modules to be used from PSCore6
PowerShell
137
star
28

PowerShell-Tests

Pester based tests for testing PowerShell
PowerShell
130
star
29

PowerShell-IoT

Interact with I2C, SPI & GPIO devices using PowerShell Core!
C#
130
star
30

PSDscResources

PowerShell
129
star
31

EditorSyntax

PowerShell syntax highlighting for editors (VS Code, Atom, SublimeText, TextMate, etc.) and GitHub!
PowerShell
127
star
32

Modules

C#
111
star
33

Phosphor

A library and PowerShell module for generating user interfaces from PowerShell modules
TypeScript
109
star
34

GPRegistryPolicy

PowerShell
102
star
35

Community-Blog

Submissions for posts to the PowerShell Community Blog -https://devblogs.microsoft.com/powershell-community
102
star
36

psl-omi-provider

PSRP Linux support library
C
100
star
37

Microsoft.PowerShell.Archive

Archive PowerShell module contains cmdlets for working with ZIP archives
C#
93
star
38

PSArm

PSArm is a PowerShell module that provides a PowerShell-embedded domain-specific language (DSL) for Azure Resource Manager (ARM) templates
C#
77
star
39

Remotely

Enable remote execution of scripts. Works with Pester.
PowerShell
74
star
40

TextUtility

Microsoft.PowerShell.TextUtility module
C#
64
star
41

PSDesiredStateConfiguration

Source for https://www.powershellgallery.com/packages/PSDesiredStateConfiguration module
PowerShell
59
star
42

ProjectMercury

An interactive shell to work with AI-powered assistance providers
C#
56
star
43

Demo_CI

PowerShell
55
star
44

PowerShellGet

This module provide functions used with PowerShellGet v3 to provide compatibility with scripts expecting PowerShellGet v2
PowerShell
55
star
45

DscResource.Tests

Common meta tests for PowerShell DSC resources repositories.
PowerShell
51
star
46

PowerShell-Native

C++
48
star
47

Whitepapers

Staging area for new documents and whitepapers
46
star
48

AzurePSDrive

Navigate Azure Resources Just like A FileSystem
PowerShell
41
star
49

ContainerProvider

ContainerImageProvider
PowerShell
38
star
50

PrivateCloud.DiagnosticInfo

PowerShell
38
star
51

PackageManagementProviderResource

Modules with DSC resources for the PackageManagement(aka OneGet) providers.
PowerShell
37
star
52

Pager

Project for console pager, which is published as a NuGet package Microsoft.PowerShell.Pager
C#
34
star
53

MarkdownRender

C#
32
star
54

DSC-Samples

Samples and tutorials for DSC v3
Go
29
star
55

PlasterBuild

Provides common build tasks for PowerShell module projects
PowerShell
29
star
56

PowerShell-Snap

PowerShell
28
star
57

SelfSignedCertificate

A module for generating self-signed certificates in PowerShell Core
PowerShell
27
star
58

CimPSDrive

SHiPS based provider to navigate CIM classes and namespaces
PowerShell
27
star
59

DscConfigurations

PowerShell
27
star
60

tree-sitter-PowerShell

JavaScript
25
star
61

GitHub-Actions

PowerShell
25
star
62

MMI

C#
24
star
63

Microsoft.PowerShell.Kubectl

PowerShell module to manage Kubernetes
PowerShell
23
star
64

LibreSSL

C
22
star
65

ODataUtils

PowerShell Module to generate cmdlets from an OData endpoint
PowerShell
22
star
66

ThreadJob

PowerShell
22
star
67

WmiNamespaceSecurityDsc

This module contains DSC resources to manage WMI Namespace Security.
PowerShell
21
star
68

FileUtility

C#
21
star
69

UnixCompleters

C#
20
star
70

Homebrew-Tap

Ruby
19
star
71

underhanded-powershell

Underhanded PowerShell Contest Repository
PowerShell
18
star
72

Hardware-Management-Module

PowerShell
17
star
73

generator-powershell

Create PowerShell modules and scripts using Yeoman!
JavaScript
16
star
74

Announcements

PowerShell Team Announcements
15
star
75

JsonAdapter

C#
14
star
76

PowerShellModuleCoverage

Track issues related to using Windows PowerShell modules with PowerShell
13
star
77

whatsnew

PowerShell
13
star
78

PSRelease

PowerShell
11
star
79

AwsDscToolkit

AWS DSC Toolkit
PowerShell
10
star
80

DscResource.Template

PowerShell
10
star
81

command-not-found

C#
10
star
82

TemplateConfig

Provides template for organizing DSC configuration scripts and supporting modules
PowerShell
10
star
83

SystemLocaleDsc

DSC Resource for configuring Windows System Locale
PowerShell
9
star
84

SmartPackageProvider

A PackageManagement provider to find and install packages using search engines
C#
9
star
85

xDisk

PowerShell
8
star
86

psl-pester

Fork of Pester for compatibility with PowerShell on Linux.
PowerShell
8
star
87

PowerShell-Blog-Samples

Samples for the PowerShell blog
PowerShell
8
star
88

ZLib

C
7
star
89

AWSBootStrapper

PowerShell
6
star
90

WSAProvider

A PackageManagement provider to find and install packages for Appx based packaging format
PowerShell
6
star
91

PowerShellGetDsc

DSCResources for the PowerShellGet module
PowerShell
5
star
92

DscConfiguration.Tests

Test automation scripts for evaluating the quality of DSC Configurations using Azure virtual machines and Azure Automation DSC.
PowerShell
5
star
93

SILDeploymentHelper

PowerShell
4
star
94

vscode-powershellise-keybindings

A Visual Studio Code extension that configures PowerShell ISE keybindings.
TypeScript
4
star
95

PSPackageProject

PowerShell
4
star
96

Compliance

3
star
97

.github

3
star
98

ISEAddOnExamples

3
star
99

pscore-docs-dotnet

PowerShell
2
star
100

JsonAdapterFeedbackPredictor

1
star