Skip to content

Commit

Permalink
see changelog for v2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Mar 6, 2019
1 parent cede9f6 commit 7bafef9
Show file tree
Hide file tree
Showing 6 changed files with 327 additions and 88 deletions.
Binary file modified PSScriptTools.psd1
Binary file not shown.
119 changes: 63 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Starting in v2.2.0, the module was restructured to better support Desktop and Co
```powershell
Uninstall-Module PSScriptTools -allversions
```

Any command that uses WPF will not run on PowerShell Core and is not exported.

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

This also works in PowerShell Core.

## [Invoke-InputBox](docs/Invoke-InputBox.md)

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.

```powershell
$name = Invoke-InputBox -Prompt "Enter a user name" -Title "New User Setup"
```

![](./images/ibx-1.png)

You can also capture a secure string.

```powershell
Invoke-Inputbox -Prompt "Enter a password for $Name" -AsSecureString -BackgroundColor red
```

![](./images/ibx-2.png)

This example also demonstrates that you can change form's background color. This function will **not** work in PowerShell Core.

## ToDo

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:
Expand Down Expand Up @@ -359,9 +340,59 @@ which generates this markdown:

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

## [ConvertTo-WPFGrid](docs/ConvertTo-WPFGrid.md)
## Graphical Tools

## [Invoke-InputBox](docs/Invoke-InputBox.md)

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.

```powershell
$name = Invoke-InputBox -Prompt "Enter a user name" -Title "New User Setup"
```

![](./images/ibx-1.png)

You can also capture a secure string.

```powershell
Invoke-Inputbox -Prompt "Enter a password for $Name" -AsSecureString -BackgroundColor red
```

![](./images/ibx-2.png)

This example also demonstrates that you can change form's background color. This function will **not** work in PowerShell Core.

### [New-WPFMessageBox](docs/New-WPFMessageBox.md)

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.

OK = 1

Cancel = 0

Yes = $True

No = $False

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 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.

```powershell
PS C:\> New-WPFMessageBox -Message "Are you sure you want to do this?" -Title Confirm -Icon Question -ButtonSet YesNo
```

![A YesNo WPF Message box](/images/wpfbox-1.png)

You can also create your own custom button set as well as modify the background color.

```powershell
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})
```

![A customized WPF Message box](/images/wpfbox-2.png)

### [ConvertTo-WPFGrid](docs/ConvertTo-WPFGrid.md)

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.

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

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

## [Convert-CommandtoHashtable](docs/Convert-CommandtoHashtable.md)
Note that in v2.4.0 the form layout was modified and may not be reflected in these screen shots.

## Hashtable Tools

### [Convert-CommandtoHashtable](docs/Convert-CommandtoHashtable.md)

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

## [Convert-HashtableString](docs/Convert-HashtableString.md)
### [Convert-HashtableString](docs/Convert-HashtableString.md)

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

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.

## [Convert-HashTableToCode](docs/Convert-HashTableToCode.md)
### [Convert-HashTableToCode](docs/Convert-HashTableToCode.md)

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

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

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

## [ConvertTo-HashTable](docs/ConvertTo-HashTable.md)
### [ConvertTo-HashTable](docs/ConvertTo-HashTable.md)

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.

Expand All @@ -451,7 +486,7 @@ Id 3456
Handles 958
```

## [Join-Hashtable](docs/Join-Hashtable.md)
### [Join-Hashtable](docs/Join-Hashtable.md)

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.

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

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

## [New-WPFMessageBox](docs/New-WPFMessageBox.md)

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.

OK = 1

Cancel = 0

Yes = $True

No = $False

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.

```powershell
PS C:\> New-WPFMessageBox -Message "Are you sure you want to do this?" -Title Confirm -Icon Question -ButtonSet YesNo
```

![A YesNo WPF Message box](/images/wpfbox-1.png)

You can also create your own custom button set as well as modify the background color.

```powershell
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})
```

![A customized WPF Message box](/images/wpfbox-2.png)

## [Compare-Module](docs/Compare-Module.md)

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

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.

*last updated 4 March 2019*
*last updated 6 March, 2019*
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log for PSScriptTools

## v2.4.0

+ Made datagrid in `ConvertTo-WPFGrid` read-only (Issue #38)
+ Modified datagrid in `ConvertTo-WPFGrid` to better handle resizing (Issue #36)
+ Modified statusbar in `ConvertTo-WPFGrid` to better handle resizing (Issue #37)
+ Modified form in `ConvertTo-WPFGrid` to better fit in the screen and not exceed the screen area (Issue #39)
+ Added parameter to allow usage of local variables in `ConvertTo-WPFGrid` (Issue #35)
+ Help updates
+ Reorganized `README.md`

## v2.3.0

+ Fixed bug in `ConvertTo-WPFGrid` that wasn't updating last update time. (Issue #30)
Expand Down
64 changes: 56 additions & 8 deletions docs/ConvertTo-WPFGrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,34 @@ Send command output to an interactive WPF-based grid.

## SYNTAX

### input (Default)

```yaml
ConvertTo-WPFGrid [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh] [-UseLocalVariable <String[]>]
[-UseProfile] [<CommonParameters>]
```

### Input

```yaml
ConvertTo-WPFGrid [[-InputObject] <PSObject>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh]
[-UseLocalVariable <String[]>] [-UseProfile] [<CommonParameters>]
```

### scriptblock

```yaml
ConvertTo-WPFGrid [[-InputObject] <PSObject>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh] [-UseProfile]
[<CommonParameters>]
ConvertTo-WPFGrid [-Scriptblock <ScriptBlock>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh]
[-UseLocalVariable <String[]>] [-UseProfile] [<CommonParameters>]
```

## DESCRIPTION

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.
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.

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.
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.

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.
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.

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.

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

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.
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.

### EXAMPLE 3

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

```yaml
Type: PSObject
Parameter Sets: (All)
Parameter Sets: Input
Aliases:

Required: False
Expand Down Expand Up @@ -131,6 +147,22 @@ Load your PowerShell profiles into the background runspace.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: profile

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Scriptblock
Enter a scriptblock that will generate data to be populated in the form
```yaml
Type: ScriptBlock
Parameter Sets: scriptblock
Aliases:

Required: False
Expand All @@ -140,6 +172,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -UseLocalVariable
Load locally defined variables into the background runspace
```yaml
Type: String[]
Parameter Sets: (All)
Aliases: var

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
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).
Expand Down
Loading

0 comments on commit 7bafef9

Please sign in to comment.