DEV Community

Cover image for PowerShell Core | Out-GridView 😎Welcome Back😎
Ewerton Jordão
Ewerton Jordão

Posted on

2 1

PowerShell Core | Out-GridView 😎Welcome Back😎

Out-GridView no PowerShell Core

E ae, pessoal, beleza ? Vamos falar sobre uma feature muito bacana para quem utiliza o PowerShell 5.1. Esse cmdlet está disponível por padrão, porém, se você utiliza o PowerShell Core 6.X provavelmente notou que ele não estava disponível, mas isso acabou 🥳🥳🥳.

O grid é bem útil na visualização do output de objetos, pois conseguimos aplicar filtros,e é uma ótima opção para usuários com pouca intimidade com scripts.

Vamos então aos passos necessários para utilizar o Out-GridView.

  1. Ter o PowerShell Core 6.2+ no seu SO. (disponível para Linux, Windows, macOS, everywhere)
  2. E o módulo Microsoft.PowerShell.GraphicalTools.
Invoke-Expression -Command "& {$(Invoke-RestMethod https://gist.githubusercontent.com/EwertonJordao/8ba7faaef23036e1d22c93dbcd68dc30/raw/a65c35b0ba3901a5fbc277de40350d3b45258344/out-gridview_teste.ps1)}"
if($IsLinux){
pwsh -c "& {install-module Microsoft.PowerShell.GraphicalTools;
get-process | out-gridview }"
}
If($IsMacOS){
pwsh -c "& {install-module Microsoft.PowerShell.GraphicalTools;
get-process | out-gridview }"
}
if($IsWindows){
pwsh -c "& {install-module Microsoft.PowerShell.GraphicalTools -ac;
get-service | out-gridview }"
}

Obs: No script presumo que você já tenha o PowerShell Core no seu SO, e que a PSGallery esteja como provider trusted, ao instalar um módulo ele vai buscar em um repositório que neste caso é a PSGallery.

Get-PSRepository
Enter fullscreen mode Exit fullscreen mode

Output esperado após executar o cmdlet acima.

InstallationPolicy SourceLocation Name
Trusted https://www.powershellgallery.com/api/v2 PSGallery

Caso o Output do cmdlet seja conforme tabela abaixo:

InstallationPolicy SourceLocation Name
Untrusted https://www.powershellgallery.com/api/v2 PSGallery

Definimos o valor para Trusted desta maneira:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted  
Enter fullscreen mode Exit fullscreen mode

Exemplo Windows 10:
Out-GridView em funcionamento no Windows 10

Exemplo centOS:
Out-GridView em funcionamento no centOS

Fico devendo o output no macOS :/, desculpe.

É isso pessoal, não se esqueça, PS é vida.

Curtiu? Quer saber mais?

GitHub logo PowerShell / GraphicalTools

Modules that mix PowerShell and GUIs/CUIs! - built on Avalonia and gui.cs

GraphicalTools - Out-ConsoleGridView

The GraphicalTools 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
Enter fullscreen mode Exit fullscreen mode

Features

Cross-platform! Use the cmdlet Out-ConsoleGridview to view and filter objects graphically.

screenshot of Out-ConsoleGridView

Examples

Example 1: Output processes to a grid view

PS C:\> Get-Process | Out-ConsoleGridView
Enter fullscreen mode Exit fullscreen mode

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

PS C:\> $P = Get-Process
PS C:\> $P | Out-ConsoleGridView -OutputMode Single
Enter fullscreen mode Exit fullscreen mode

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


Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay