Skip to content

Commit 3a86d71

Browse files
v2.11.0
1 parent 5cd4043 commit 3a86d71

File tree

6 files changed

+374
-222
lines changed

6 files changed

+374
-222
lines changed

PSScriptTools.psd1

0 Bytes
Binary file not shown.

changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log for PSScriptTools
22

3-
## 2.10.0
3+
## v2.11.0
4+
5+
+ Added a grouping feature to `New-PSFormatXML` (Issue #54)
6+
+ Modified `New-PSFormatXML` to open the XML file if the command is run in VS Code as part of `-Passthru`
7+
+ Help updates
8+
9+
## v2.10.0
410

511
+ Added `Test-WithCulture`
612
+ Fixed typo in `Copy-Command` help

docs-yaml/New-PSFormatXML.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
Computername = $env:computername
1616
17-
OS = (get-ciminstance win32_operatingsystem -Property Caption).caption
17+
OS = (Get-Ciminstance win32_operatingsystem -Property Caption).caption
1818
1919
}
2020
@@ -26,7 +26,7 @@
2626
2727
Name : Jeff
2828
29-
Date : 2/10/2019 8:49:10 PM
29+
Date : 2/10/2019 8:49:10 AM
3030
3131
Computername : BOVINE320
3232
@@ -56,7 +56,7 @@
5656
5757
---- ---- ------------ ----------------
5858
59-
Jeff 2/10/2019 8:49:10 PM BOVINE320 Microsoft Windows 10 Pro
59+
Jeff 2/10/2019 8:49:10 AM BOVINE320 Microsoft Windows 10 Pro
6060
6161
6262
@@ -88,6 +88,29 @@
8888
8989
Runtime : 40.21:12:01
9090
postCode: After the format.ps1xml file is applied, the object can be formatted as designed.
91+
- name: Example 4
92+
preCode: ''
93+
code: >-
94+
PS C:\> $obj | New-PSFormatXML -viewname computer -GroupBy Computername -path "c:\work\$tname.format.ps1xml" -append
95+
96+
PS C:\> Update-FormatData -appendpath "C:\work\$tname.format.ps1xml"
97+
98+
PS C:\> $obj | format-table -View computer
99+
100+
101+
102+
103+
104+
Computername: BOVINE320
105+
106+
107+
108+
Name Date OS Runtime
109+
110+
---- ---- -- -------
111+
112+
Jeff 2/10/2019 8:49:10 AM Microsoft Windows 10 Pro 40.20:56:24.5411481
113+
postCode: This adds another view called Computer that groups objects on the Computername property.
91114
inputs:
92115
- type: System.Object
93116
description: ''
@@ -131,7 +154,7 @@ optionalParameters:
131154
- name: Passthru
132155
aliases: []
133156
defaultValue: None
134-
description: Write the ps1xml file object to the pipeline.
157+
description: Write the ps1xml file object to the pipeline. If you run this command inside VS Code and use this parameter, the file will be opened in the editor.
135158
parameterValueGroup: []
136159
pipelineInput: False
137160
position: Named
@@ -169,6 +192,14 @@ optionalParameters:
169192
pipelineInput: False
170193
position: Named
171194
type: String
195+
- name: GroupBy
196+
aliases: []
197+
defaultValue: None
198+
description: Specify a property name to group on. You can edit the file if you need to change how it is displayed and/or calculated.
199+
parameterValueGroup: []
200+
pipelineInput: False
201+
position: Named
202+
type: String
172203
outputs:
173204
- type: None
174205
description: ''
@@ -194,7 +225,7 @@ requiredParameters:
194225
remarks: >-
195226
When defining custom objects with a new typename, PowerShell by default will display all properties. However, you may wish to have a specific default view, be it a table or list. Or you may want to have different views display the object differently. Format directives are stored in format.ps1xml files which can be tedious to create. This command simplifies that process.
196227
197-
Pipe an instance of your custom object to this function and it will generate a format.ps1xml file based on either all the properties or a subset that you provide. You can repeat the process to add additional views. When finished, edit the format.ps1xml file and fine tune it. The file will have notes on how to substitute script blocks.
228+
Pipe an instance of your custom object to this function and it will generate a format.ps1xml file based on either all the properties or a subset that you provide. You can repeat the process to add additional views. When finished, edit the format.ps1xml file and fine tune it. The file will have notes on how to substitute script blocks. If you run this command inside VS Code and use -Passthru, the new file will automatically be opened in your editor.
198229
199230
Note that table views are set to Autosize. But the table definition will include best guesses for column widths. If you prefer a more granular approach you can delete the Autosize tag and experiment with varying widths. Don't forget to run Update-FormatData to load your new file. You may need to start a new PowerShell session to test changes.
200231
summary: Create or modify a format.ps1xml file
@@ -210,3 +241,4 @@ syntaxes:
210241
- Passthru
211242
- WhatIf
212243
- Typename
244+
- GroupBy

docs/New-PSFormatXML.md

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ Create or modify a format.ps1xml file
1515

1616
```yaml
1717
New-PSFormatXML [-InputObject] <Object> [[-Properties] <String[]>] [-Typename <String>]
18-
[[-FormatType] <String>] [[-ViewName] <String>] [-Path] <String> [-Append] [-Passthru] [-WhatIf] [-Confirm]
19-
[<CommonParameters>]
18+
[[-FormatType] <String>] [[-ViewName] <String>] [-Path] <String> [-GroupBy <String>] [-Append] [-Passthru]
19+
[-WhatIf] [-Confirm] [<CommonParameters>]
2020
```
2121

2222
## DESCRIPTION
2323

2424
When defining custom objects with a new typename, PowerShell by default will display all properties. However, you may wish to have a specific default view, be it a table or list. Or you may want to have different views display the object differently. Format directives are stored in format.ps1xml files which can be tedious to create. This command simplifies that process.
2525

26-
Pipe an instance of your custom object to this function and it will generate a format.ps1xml file based on either all the properties or a subset that you provide. You can repeat the process to add additional views. When finished, edit the format.ps1xml file and fine tune it. The file will have notes on how to substitute script blocks.
26+
Pipe an instance of your custom object to this function and it will generate a format.ps1xml file based on either all the properties or a subset that you provide. You can repeat the process to add additional views. When finished, edit the format.ps1xml file and fine tune it. The file will have notes on how to substitute script blocks. If you run this command inside VS Code and use -Passthru, the new file will automatically be opened in your editor.
2727

2828
Note that table views are set to Autosize. But the table definition will include best guesses for column widths. If you prefer a more granular approach you can delete the Autosize tag and experiment with varying widths. Don't forget to run Update-FormatData to load your new file. You may need to start a new PowerShell session to test changes.
2929

@@ -38,13 +38,13 @@ PS C:\> $obj = [PSCustomObject]@{
3838
Name = "Jeff"
3939
Date = (Get-Date)
4040
Computername = $env:computername
41-
OS = (get-ciminstance win32_operatingsystem -Property Caption).caption
41+
OS = (Get-Ciminstance win32_operatingsystem -Property Caption).caption
4242
}
4343
PS C:\> Update-TypeData -TypeName $tname -MemberType "ScriptProperty" -MemberName "Runtime" -value {(Get-Date) - [datetime]"1/1/2019"} -force
4444
PS C:\> $obj
4545
4646
Name : Jeff
47-
Date : 2/10/2019 8:49:10 PM
47+
Date : 2/10/2019 8:49:10 AM
4848
Computername : BOVINE320
4949
OS : Microsoft Windows 10 Pro
5050
Runtime : 40.20:49:43.9205882
@@ -70,7 +70,7 @@ PS C:\> $obj
7070
7171
Name Date Computername Operating System
7272
---- ---- ------------ ----------------
73-
Jeff 2/10/2019 8:49:10 PM BOVINE320 Microsoft Windows 10 Pro
73+
Jeff 2/10/2019 8:49:10 AM BOVINE320 Microsoft Windows 10 Pro
7474
7575
PS C:\> $obj | format-table -View runtime
7676
@@ -90,6 +90,23 @@ Runtime : 40.21:12:01
9090

9191
After the format.ps1xml file is applied, the object can be formatted as designed.
9292

93+
### Example 4
94+
95+
```powershell
96+
PS C:\> $obj | New-PSFormatXML -viewname computer -GroupBy Computername -path "c:\work\$tname.format.ps1xml" -append
97+
PS C:\> Update-FormatData -appendpath "C:\work\$tname.format.ps1xml"
98+
PS C:\> $obj | format-table -View computer
99+
100+
101+
Computername: BOVINE320
102+
103+
Name Date OS Runtime
104+
---- ---- -- -------
105+
Jeff 2/10/2019 8:49:10 AM Microsoft Windows 10 Pro 40.20:56:24.5411481
106+
```
107+
108+
This adds another view called Computer that groups objects on the Computername property.
109+
93110
## PARAMETERS
94111

95112
### -Append
@@ -159,7 +176,7 @@ Accept wildcard characters: False
159176
160177
### -Passthru
161178
162-
Write the ps1xml file object to the pipeline.
179+
Write the ps1xml file object to the pipeline. If you run this command inside VS Code and use this parameter, the file will be opened in the editor.
163180
164181
```yaml
165182
Type: SwitchParameter
@@ -253,9 +270,25 @@ Accept pipeline input: False
253270
Accept wildcard characters: False
254271
```
255272
273+
### -GroupBy
274+
275+
Specify a property name to group on. You can edit the file if you need to change how it is displayed and/or calculated.
276+
277+
```yaml
278+
Type: String
279+
Parameter Sets: (All)
280+
Aliases:
281+
282+
Required: False
283+
Position: Named
284+
Default value: None
285+
Accept pipeline input: False
286+
Accept wildcard characters: False
287+
```
288+
256289
### CommonParameters
257290
258-
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).
291+
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).
259292
260293
## INPUTS
261294

0 commit comments

Comments
 (0)