Skip to content

Commit 7bafef9

Browse files
see changelog for v2.4.0
1 parent cede9f6 commit 7bafef9

File tree

6 files changed

+327
-88
lines changed

6 files changed

+327
-88
lines changed

PSScriptTools.psd1

0 Bytes
Binary file not shown.

README.md

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Starting in v2.2.0, the module was restructured to better support Desktop and Co
2323
```powershell
2424
Uninstall-Module PSScriptTools -allversions
2525
```
26+
2627
Any command that uses WPF will not run on PowerShell Core and is not exported.
2728

2829
Please post any questions, problems or feedback in [Issues](https://github.com/jdhitsolutions/PSScriptTools/issues). Any input is greatly appreciated.
@@ -232,26 +233,6 @@ get-service | out-more
232233

233234
This also works in PowerShell Core.
234235

235-
## [Invoke-InputBox](docs/Invoke-InputBox.md)
236-
237-
This function is a graphical replacement for `Read-Host`. It creates a simple WPF form that you can use to get user input. The value of the text box will be written to the pipeline.
238-
239-
```powershell
240-
$name = Invoke-InputBox -Prompt "Enter a user name" -Title "New User Setup"
241-
```
242-
243-
![](./images/ibx-1.png)
244-
245-
You can also capture a secure string.
246-
247-
```powershell
248-
Invoke-Inputbox -Prompt "Enter a password for $Name" -AsSecureString -BackgroundColor red
249-
```
250-
251-
![](./images/ibx-2.png)
252-
253-
This example also demonstrates that you can change form's background color. This function will **not** work in PowerShell Core.
254-
255236
## ToDo
256237

257238
Because this module is intended to make scripting easier for you, it adds options to insert ToDo statements into PowerShell files. If you are using the PowerShell ISE or VS Code and import this module, it will add the capability to insert a line like this:
@@ -359,9 +340,59 @@ which generates this markdown:
359340

360341
Because the function writes markdown to the pipeline you will need to pipe it to a command `Out-File` to create a file.
361342

362-
## [ConvertTo-WPFGrid](docs/ConvertTo-WPFGrid.md)
343+
## Graphical Tools
344+
345+
## [Invoke-InputBox](docs/Invoke-InputBox.md)
346+
347+
This function is a graphical replacement for `Read-Host`. It creates a simple WPF form that you can use to get user input. The value of the text box will be written to the pipeline.
348+
349+
```powershell
350+
$name = Invoke-InputBox -Prompt "Enter a user name" -Title "New User Setup"
351+
```
352+
353+
![](./images/ibx-1.png)
354+
355+
You can also capture a secure string.
356+
357+
```powershell
358+
Invoke-Inputbox -Prompt "Enter a password for $Name" -AsSecureString -BackgroundColor red
359+
```
360+
361+
![](./images/ibx-2.png)
362+
363+
This example also demonstrates that you can change form's background color. This function will **not** work in PowerShell Core.
364+
365+
### [New-WPFMessageBox](docs/New-WPFMessageBox.md)
366+
367+
This function creates a Windows Presentation Foundation (WPF) based message box. This is intended to replace the legacy MsgBox function from VBScript and the Windows Forms library. The command uses a set of predefined button sets, each of which will close the form and write a value to the pipeline.
368+
369+
OK = 1
370+
371+
Cancel = 0
372+
373+
Yes = $True
374+
375+
No = $False
363376

364-
This command is an alternative to `Out-Gridview`. It works much the same way. Run a PowerShell command and pipe it to this command. The output will be displayed in an autosized data grid. You can click on column headings to sort. You can resize columns and you can re-order columns.
377+
You can also create an ordered hashtable of your own buttons and values. It is assumed you will typically use this function in a script where you can capture the output and take some action based on the value.
378+
379+
```powershell
380+
PS C:\> New-WPFMessageBox -Message "Are you sure you want to do this?" -Title Confirm -Icon Question -ButtonSet YesNo
381+
```
382+
383+
![A YesNo WPF Message box](/images/wpfbox-1.png)
384+
385+
You can also create your own custom button set as well as modify the background color.
386+
387+
```powershell
388+
PS C:\> New-WPFMessageBox -Message "Select a system option from these choices:" -Title "You Decide" -Background cornsilk -Icon Warning -CustomButtonSet ([ordered]@{"Reboot"=1;"Shutdown"=2;"Cancel"=3})
389+
```
390+
391+
![A customized WPF Message box](/images/wpfbox-2.png)
392+
393+
### [ConvertTo-WPFGrid](docs/ConvertTo-WPFGrid.md)
394+
395+
This command is an alternative to `Out-Gridview`. It works much the same way. Run a PowerShell command and pipe it to this command. The output will be displayed in an auto-sized data grid. You can click on column headings to sort. You can resize columns and you can re-order columns.
365396

366397
```powershell
367398
get-eventlog -list -ComputerName DOM1,SRV1,SRV2 |
@@ -381,7 +412,11 @@ Convertto-WPFGrid -Refresh -timeout 20 -Title "Top Processes"
381412

382413
![Displaying Top Processes](images/wpfgrid2.png)
383414

384-
## [Convert-CommandtoHashtable](docs/Convert-CommandtoHashtable.md)
415+
Note that in v2.4.0 the form layout was modified and may not be reflected in these screen shots.
416+
417+
## Hashtable Tools
418+
419+
### [Convert-CommandtoHashtable](docs/Convert-CommandtoHashtable.md)
385420

386421
This command is intended to convert a long PowerShell expression with named parameters into a splatting
387422
alternative.
@@ -398,7 +433,7 @@ $paramHash = @{
398433
Get-EventLog @paramHash
399434
```
400435

401-
## [Convert-HashtableString](docs/Convert-HashtableString.md)
436+
### [Convert-HashtableString](docs/Convert-HashtableString.md)
402437

403438
This function is similar to `Import-PowerShellDataFile`. But where that command can only process a file, this command
404439
will take any hashtable-formatted string and convert it into an actual hashtable.
@@ -420,7 +455,7 @@ CreatedOn BOVINE320
420455

421456
The test.psd1 file is protected as a CMS Message. In this example, the contents are decoded as a string which is then in turn converted into an actual hashtable.
422457

423-
## [Convert-HashTableToCode](docs/Convert-HashTableToCode.md)
458+
### [Convert-HashTableToCode](docs/Convert-HashTableToCode.md)
424459

425460
Use this command to convert a hashtable into its text or string equivalent.
426461

@@ -436,7 +471,7 @@ PS C:\> convert-hashtabletocode $h
436471

437472
Convert a hashtable object to a string equivalent that you can copy into your script.
438473

439-
## [ConvertTo-HashTable](docs/ConvertTo-HashTable.md)
474+
### [ConvertTo-HashTable](docs/ConvertTo-HashTable.md)
440475

441476
This command will take an object and create a hashtable based on its properties. You can have the hashtable exclude some properties as well as properties that have no value.
442477

@@ -451,7 +486,7 @@ Id 3456
451486
Handles 958
452487
```
453488

454-
## [Join-Hashtable](docs/Join-Hashtable.md)
489+
### [Join-Hashtable](docs/Join-Hashtable.md)
455490

456491
This command will combine two hashtables into a single hashtable.Join-Hashtable will test for duplicate keys. If any of the keys from the first, or primary hashtable are found in the secondary hashtable, you will be prompted for which to keep. Or you can use -Force which will always keep the conflicting key from the first hashtable.
457492

@@ -538,34 +573,6 @@ By default, the output will only show directory or equivalent structures. But yo
538573

539574
![show file system tree](images/show-tree1.png)
540575

541-
## [New-WPFMessageBox](docs/New-WPFMessageBox.md)
542-
543-
This function creates a Windows Presentation Foundation (WPF) based message box. This is intended to replace the legacy MsgBox function from VBScript and the Windows Forms library. The command uses a set of predefined button sets, each of which will close the form and write a value to the pipeline.
544-
545-
OK = 1
546-
547-
Cancel = 0
548-
549-
Yes = $True
550-
551-
No = $False
552-
553-
You can also create an ordered hashtable of your own buttons and values. It is assumed you will typically use this function in a script where you can capture the output and take some action based on the value.
554-
555-
```powershell
556-
PS C:\> New-WPFMessageBox -Message "Are you sure you want to do this?" -Title Confirm -Icon Question -ButtonSet YesNo
557-
```
558-
559-
![A YesNo WPF Message box](/images/wpfbox-1.png)
560-
561-
You can also create your own custom button set as well as modify the background color.
562-
563-
```powershell
564-
PS C:\> New-WPFMessageBox -Message "Select a system option from these choices:" -Title "You Decide" -Background cornsilk -Icon Warning -CustomButtonSet ([ordered]@{"Reboot"=1;"Shutdown"=2;"Cancel"=3})
565-
```
566-
567-
![A customized WPF Message box](/images/wpfbox-2.png)
568-
569576
## [Compare-Module](docs/Compare-Module.md)
570577

571578
Use this command to compare module versions between what is installed against an online repository like the PSGallery
@@ -749,4 +756,4 @@ This is a handy command when traveling and your laptop is using a locally derive
749756

750757
Where possible these commands have been tested with PowerShell Core, but not every platform. If you encounter problems, have suggestions or other feedback, please post an issue.
751758

752-
*last updated 4 March 2019*
759+
*last updated 6 March, 2019*

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log for PSScriptTools
22

3+
## v2.4.0
4+
5+
+ Made datagrid in `ConvertTo-WPFGrid` read-only (Issue #38)
6+
+ Modified datagrid in `ConvertTo-WPFGrid` to better handle resizing (Issue #36)
7+
+ Modified statusbar in `ConvertTo-WPFGrid` to better handle resizing (Issue #37)
8+
+ Modified form in `ConvertTo-WPFGrid` to better fit in the screen and not exceed the screen area (Issue #39)
9+
+ Added parameter to allow usage of local variables in `ConvertTo-WPFGrid` (Issue #35)
10+
+ Help updates
11+
+ Reorganized `README.md`
12+
313
## v2.3.0
414

515
+ Fixed bug in `ConvertTo-WPFGrid` that wasn't updating last update time. (Issue #30)

docs/ConvertTo-WPFGrid.md

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,34 @@ Send command output to an interactive WPF-based grid.
1313

1414
## SYNTAX
1515

16+
### input (Default)
17+
18+
```yaml
19+
ConvertTo-WPFGrid [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh] [-UseLocalVariable <String[]>]
20+
[-UseProfile] [<CommonParameters>]
21+
```
22+
23+
### Input
24+
25+
```yaml
26+
ConvertTo-WPFGrid [[-InputObject] <PSObject>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh]
27+
[-UseLocalVariable <String[]>] [-UseProfile] [<CommonParameters>]
28+
```
29+
30+
### scriptblock
31+
1632
```yaml
17-
ConvertTo-WPFGrid [[-InputObject] <PSObject>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh] [-UseProfile]
18-
[<CommonParameters>]
33+
ConvertTo-WPFGrid [-Scriptblock <ScriptBlock>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh]
34+
[-UseLocalVariable <String[]>] [-UseProfile] [<CommonParameters>]
1935
```
2036

2137
## DESCRIPTION
2238

23-
This command is an alternative to Out-Gridview. It works much the same way. Run a PowerShell command and pipe it to this command. The output will be displayed in an autosized data grid. You can click on column headings to sort. You can resize columns and you can re-order columns. You will want to be selective about which properties you pipe through to this command. See examples.
39+
This command is an alternative to Out-Gridview. It works much the same way. Run a PowerShell command and pipe it to this command. The output will be displayed in an auto-sized data grid. You can click on column headings to sort. You can resize columns and you can re-order columns. You will want to be selective about which properties you pipe through to this command. See examples.
2440

25-
You can specify a timeout value which will automatically close the form. If you specify a timeout and the Refresh parameter, then the contents of the datagrid will automatically refreshed using the timeout value as an integer. This will only work when you pipe a PowerShell expression to ConvertTo-WPFGrid as one command. This will fail if you break the command in the PowerShell ISE or use a nested prompt.
41+
You can specify a timeout value which will automatically close the form. If you specify a timeout and the Refresh parameter, then the contents of the datagrid will automatically refreshed using the timeout value as an integer. This will only work when you pipe a PowerShell expression to ConvertTo-WPFGrid as one command. This will fail if you break the command in the PowerShell ISE or use a nested prompt. Beginning with v2.4.0 the form now has a Refresh button which will automatically refresh the datagrid.
2642

27-
Because the grid is running in a new background runspace, it does not automatically inherit anything from your current session. When refreshing data, you need to make sure that the command up to ConvertTo-WPFGrid can run in a standalone session. For example, avoid using variables that won't exist in the background runspace. However, you can use the -UserProfile parameter which will load your user profile scripts into the runspace.
43+
Because the grid is running in a new background runspace, it does not automatically inherit anything from your current session. However, you can use the -UserProfile parameter which will load your user profile scripts into the runspace. You can also specify a list of locally defined variables to be used in the form.
2844

2945
This command runs the WPF grid in a new runspace so your PowerShell prompt will not be blocked. However, after closing the form you may be left with the runspace. You can use Remove-Runspace to clean up or wait until you restart PowerShell.
3046

@@ -45,10 +61,10 @@ PS C:\> $vmhost = "CHI-HVR2"
4561
PS C:\> Get-VM -computername $VMHost | Select Name,State,Uptime,
4662
@{Name="AssignedMB";Expression={$_.MemoryAssigned/1mb -as [int]}},
4763
@{Name="DemandMB";Expression={$_.MemoryDemand/1mb -as [int]}} |
48-
ConvertTo-WPFGrid -title "VM Report $VMHost" -timeout 20
64+
ConvertTo-WPFGrid -title "VM Report $VMHost" -timeout 30 -refresh -uselocalvariable VMHost
4965
```
5066

51-
Get Hyper-V virtual machine information and display for 20 seconds before automatically closing. Note that this would be written as one long pipelined expression. It is formatted here for the sake of the help documentation.
67+
Get Hyper-V virtual machine information and refresh every 30 seconds. Because the command is using a locally defined variable it is also being used in the form. Note that this would be written as one long pipelined expression. It is formatted here for the sake of the help documentation.
5268

5369
### EXAMPLE 3
5470

@@ -66,7 +82,7 @@ Typically the results of a PowerShell command or expression. You should select t
6682

6783
```yaml
6884
Type: PSObject
69-
Parameter Sets: (All)
85+
Parameter Sets: Input
7086
Aliases:
7187

7288
Required: False
@@ -131,6 +147,22 @@ Load your PowerShell profiles into the background runspace.
131147
```yaml
132148
Type: SwitchParameter
133149
Parameter Sets: (All)
150+
Aliases: profile
151+
152+
Required: False
153+
Position: Named
154+
Default value: None
155+
Accept pipeline input: False
156+
Accept wildcard characters: False
157+
```
158+
159+
### -Scriptblock
160+
161+
Enter a scriptblock that will generate data to be populated in the form
162+
163+
```yaml
164+
Type: ScriptBlock
165+
Parameter Sets: scriptblock
134166
Aliases:
135167

136168
Required: False
@@ -140,6 +172,22 @@ Accept pipeline input: False
140172
Accept wildcard characters: False
141173
```
142174
175+
### -UseLocalVariable
176+
177+
Load locally defined variables into the background runspace
178+
179+
```yaml
180+
Type: String[]
181+
Parameter Sets: (All)
182+
Aliases: var
183+
184+
Required: False
185+
Position: Named
186+
Default value: None
187+
Accept pipeline input: False
188+
Accept wildcard characters: False
189+
```
190+
143191
### CommonParameters
144192
145193
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).

0 commit comments

Comments
 (0)