Skip to content

Commit cd21e62

Browse files
authored
Add HelpMessage to parameters and update readme (#173)
1 parent becace5 commit cd21e62

File tree

3 files changed

+128
-20
lines changed

3 files changed

+128
-20
lines changed

README.md

Lines changed: 104 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The GraphicalTools repo contains the `Out-ConsoleGridView`
44
PowerShell Cmdlet providing console-based GUI experiences based on
5-
[Terminal.Gui (gui.cs)](https://github.com/migueldeicaza/gui.cs).
5+
[Terminal.Gui (gui.cs)](https://github.com/gui-cs/Terminal.Gui).
66

77
_Note:_ A module named `Microsoft.PowerShell.GraphicalTools` used to be built and published out of this repo, but per [#101](https://github.com/PowerShell/GraphicalTools/issues/101) it is deprecated and unmaintained until such time that it can be rewritten on top of [.NET MAUI](https://devblogs.microsoft.com/dotnet/introducing-net-multi-platform-app-ui/).
88

@@ -20,14 +20,109 @@ to view and filter objects graphically.
2020

2121
![screenshot of Out-ConsoleGridView](docs/Microsoft.PowerShell.ConsoleGuiTools/ocgv.gif)
2222

23-
### Examples
23+
## Examples
2424

25-
Get a process ID:
26-
```powershell
27-
gps | ocgv -OutputMode Single
25+
### Example 1: Output processes to a grid view
26+
27+
```PowerShell
28+
PS C:\> Get-Process | Out-ConsoleGridView
29+
```
30+
31+
This command gets the processes running on the local computer and sends them to a grid view window.
32+
33+
### Example 2: Use a variable to output processes to a grid view
34+
35+
```PowerShell
36+
PS C:\> $P = Get-Process
37+
PS C:\> $P | Out-ConsoleGridView -OutputMode Single
2838
```
2939

30-
See the [F7 History](https://github.com/gui-cs/F7History) script to show the PowerShell command history when F7 is pressed.
40+
This command also gets the processes running on the local computer and sends them to a grid view window.
41+
42+
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.
43+
44+
The second command uses a pipeline operator to send the $P variable to **Out-ConsoleGridView**.
45+
46+
By specifying `-OutputMode Single` the grid view window will be restricted to a single selection, ensuring no more than a single object is returned.
47+
48+
### Example 3: Display a formatted table in a grid view
49+
50+
```PowerShell
51+
PS C:\> Get-Process | Select-Object -Property Name, WorkingSet, PeakWorkingSet | Sort-Object -Property WorkingSet -Descending | Out-ConsoleGridView
52+
```
53+
54+
This command displays a formatted table in a grid view window.
55+
56+
It uses the Get-Process cmdlet to get the processes on the computer.
57+
58+
Then, it uses a pipeline operator (|) to send the process objects to the Select-Object cmdlet.
59+
The command uses the **Property** parameter of **Select-Object** to select the Name, WorkingSet, and PeakWorkingSet properties to be displayed in the table.
60+
61+
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.
62+
63+
The final part of the command uses a pipeline operator (|) to send the formatted table to **Out-ConsoleGridView**.
64+
65+
You can now use the features of the grid view to search, sort, and filter the data.
66+
67+
### Example 4: Save output to a variable, and then output a grid view
68+
69+
```PowerShell
70+
PS C:\> ($A = Get-ChildItem -Path $pshome -Recurse) | Out-ConsoleGridView
71+
```
72+
73+
This command saves its output in a variable and sends it to **Out-ConsoleGridView**.
74+
75+
The command uses the Get-ChildItem cmdlet to get the files in the Windows PowerShell installation directory and its subdirectories.
76+
The path to the installation directory is saved in the $pshome automatic variable.
77+
78+
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**.
79+
80+
The parentheses in the command establish the order of operations.
81+
As a result, the output from the Get-ChildItem command is saved in the $A variable before it is sent to **Out-ConsoleGridView**.
82+
83+
### Example 5: Output processes for a specified computer to a grid view
84+
85+
```PowerShell
86+
PS C:\> Get-Process -ComputerName "Server01" | ocgv -Title "Processes - Server01"
87+
```
88+
89+
This command displays the processes that are running on the Server01 computer in a grid view window.
90+
91+
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.
92+
93+
### Example 6: Define a function to kill processes using a graphical chooser
94+
95+
```PowerShell
96+
PS C:\> function killp { Get-Process | Out-ConsoleGridView -OutputMode Single -Filter $args[0] | Stop-Process -Id {$_.Id} }
97+
PS C:\> killp note
98+
```
99+
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.
100+
101+
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.
102+
103+
### Example 7: Pass multiple items through Out-ConsoleGridView
104+
105+
```PowerShell
106+
PS C:\> Get-Process | Out-ConsoleGridView -PassThru | Export-Csv -Path .\ProcessLog.csv
107+
```
108+
109+
This command lets you select multiple processes from the **Out-ConsoleGridView** window.
110+
The processes that you select are passed to the **Export-Csv** command and written to the ProcessLog.csv file.
111+
112+
The command uses the *PassThru* parameter of **Out-ConsoleGridView**, which lets you send multiple items down the pipeline.
113+
The *PassThru* parameter is equivalent to using the Multiple value of the *OutputMode* parameter.
114+
115+
### Example 8: Use F7 as "Show Command History"
116+
117+
Add [gui-cs/F7History](https://github.com/gui-cs/F7History) to your Powershell profile.
118+
119+
Press `F7` to see the history for the current PowerShell instance
120+
121+
Press `Shift-F7` to see the history for all PowerShell instances.
122+
123+
Whatever you select within `Out-ConsoleGridView` will be inserted on your command line.
124+
125+
Whatever was typed on the command line prior to hitting `F7` or `Shift-F7` will be used as a filter.
31126

32127
## Development
33128

@@ -97,14 +192,14 @@ you would like to contribute code, documentation, tests, or bug reports,
97192
please read the [development section above](https://github.com/PowerShell/GraphicalTools#development)
98193
to learn more.
99194

100-
## (Deprecated) Microsoft.PowerShell.GraphicalTools Architecture
195+
## Microsoft.PowerShell.ConsoleGuiTools Architecture
101196

102-
`GraphicalTools` consists of 2 .NET Projects:
197+
`ConsoleGuiTools` consists of 2 .NET Projects:
103198

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

107-
_Note:_ Previously, GraphicalTools also included the Avalonia-based `Out-GridView` which was implemented in `.\Microsoft.PowerShell.GraphicalTools` and `.\OutGridView.Gui`. These components have been deprecated (see note above).
202+
_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).
108203

109204
## Maintainers
110205

docs/Microsoft.PowerShell.ConsoleGuiTools/Out-ConsoleGridView.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ external help file: ConsoleGuiToolsModule.dll-Help.xml
33
keywords: powershell,cmdlet
44
locale: en-us
55
Module Name: Microsoft.PowerShell.ConsoleGuiTools
6-
ms.date: 08/09/2019
6+
ms.date: 08/24/2022
77
schema: 2.0.0
88
title: Out-ConsoleGridView
99
---
@@ -18,7 +18,7 @@ Sends output to an interactive table in the same console window.
1818

1919
```PowerShell
2020
Out-ConsoleGridView [-InputObject <psobject>] [-Title <string>] [-OutputMode {None | Single |
21-
Multiple}] [-Filter <string>] [<CommonParameters>]
21+
Multiple}] [-Filter <string>] [-MinUi] [<CommonParameters>]
2222
```
2323

2424
## DESCRIPTION
@@ -27,7 +27,7 @@ The **Out-ConsoleGridView** cmdlet sends the output from a command to a grid vie
2727

2828
You can use the following features of the table to examine your data:
2929

30-
- Quick Filter. Use the Filter box at the top of the window to search the text in the table. You can search for text in a particular column, search for literals, and search for multiple words. You can use the `-Filter` command to pre-populate the Filter box.
30+
- Quick Filter. Use the Filter box at the top of the window to search the text in the table. You can search for text in a particular column, search for literals, and search for multiple words. You can use the `-Filter` command to pre-populate the Filter box. The filter uses regular expressions.
3131

3232
For instructions for using these features, type `Get-Help Out-ConsoleGridView -Full` and see How to Use the Grid View Window Features in the Notes section.
3333

@@ -175,7 +175,7 @@ Accept wildcard characters: False
175175
176176
### -OutputMode
177177
Specifies the items that the interactive window sends down the pipeline as input to other commands.
178-
By default, this cmdlet does not generate any output.
178+
By default, this cmdlet generates zero, one, or many items.
179179
180180
To send items from the interactive window down the pipeline, click to select the items (either the the mouse in terminals that support mouse or the `SPACE` key) and then press `ENTER`. `ESC` cancels.
181181

@@ -215,6 +215,21 @@ Accept pipeline input: False
215215
Accept wildcard characters: False
216216
```
217217

218+
### -MinUi
219+
If specified no window frame, filter box, or status bar will be displayed in the **Out-ConsoleGridView** window.
220+
221+
```yaml
222+
Type: SwitchParameter
223+
Parameter Sets: (All)
224+
Aliases:
225+
226+
Required: False
227+
Position: Named
228+
Default value: None
229+
Accept pipeline input: False
230+
Accept wildcard characters: False
231+
```
232+
218233
### CommonParameters
219234
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
220235

@@ -238,8 +253,6 @@ By default `Out-ConsoleGridView` returns objects representing the selected rows
238253

239254
## RELATED LINKS
240255

241-
[Out-GridView](Out-GridView.md)
242-
243256
[Out-File](Out-File.md)
244257

245258
[Out-Printer](Out-Printer.md)

src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,33 @@ public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
2929
/// <summary>
3030
/// This parameter specifies the current pipeline object.
3131
/// </summary>
32-
[Parameter(ValueFromPipeline = true)]
32+
[Parameter(ValueFromPipeline = true, HelpMessage = "Specifies the input pipeline object")]
3333
public PSObject InputObject { get; set; } = AutomationNull.Value;
3434

3535
/// <summary>
3636
/// Gets/sets the title of the Out-GridView window.
3737
/// </summary>
38-
[Parameter]
38+
[Parameter(HelpMessage = "Specifies the text that appears in the title bar of the Out-ConsoleGridView window. y default, the title bar displays the command that invokes Out-ConsoleGridView.")]
3939
[ValidateNotNullOrEmpty]
4040
public string Title { get; set; }
4141

4242
/// <summary>
4343
/// Get or sets a value indicating whether the selected items should be written to the pipeline
4444
/// and if it should be possible to select multiple or single list items.
4545
/// </summary>
46-
[Parameter()]
46+
[Parameter(HelpMessage = "Determines whether a single item (Single), multiple items (Multiple; default), or no items (None) will be written to the pipeline. Also determines selection behavior in the GUI.")]
4747
public OutputModeOption OutputMode { set; get; } = OutputModeOption.Multiple;
4848

4949
/// <summary>
5050
/// gets or sets the initial value for the filter in the GUI
5151
/// </summary>
52-
[Parameter()]
52+
[Parameter(HelpMessage = "Pre-populates the Filter edit box, allowing filtering to be specified on the command line. The filter uses regular expressions." )]
5353
public string Filter { set; get; }
5454

5555
/// <summary>
5656
/// gets or sets the whether "minimum UI" mode will be enabled
5757
/// </summary>
58-
[Parameter()]
58+
[Parameter(HelpMessage = "If specified no window frame, filter box, or status bar will be displayed in the GUI.")]
5959
public SwitchParameter MinUI { set; get; }
6060

6161
#endregion Input Parameters

0 commit comments

Comments
 (0)