Skip to content

Commit 6c4d0ff

Browse files
.ps1xml formatting file doc corrections (#12614)
* Fix 5.1 about_Format.ps1xml examples This fixes the wrong path used in both `Update-FormatData` examples. The paths used to initially create the custom formatting files are .\MyDotNetTypes.Format.ps1xml and .\MyFileSystem.Format.ps1xml. Before this change, Update-FormatData -PrependPath incorrectly pointed to $HOME\Format\CultureInfo.Format.ps1xml and $PSHOME\Format\MyFileSystem.Format.ps1xml. * Use consistent paths in 7.x about_Format.ps1xml Both Update-FormatData examples now use the $HOME\Format example path. This also updates the first example to create the directory before calling Export-FormatData, as the directory doesn't exist by default and Export-FormatData fails if part of the path is missing. * Minor style changes * Specify the correct formatting file extension This fixes the incorrect assertion that formatting files **must** use `.format.ps1xml` (only `.ps1xml` is required). * Adjust formatting file signing note The original note suggests that after copying Win PS formatting files, the signature block should be replaced. However, the files don't actually contain a signature block to begin with. This may cause confusion, so the note is updated with a more generalized suggestion on signing taken from about_Format.ps1xml. Also includes minor style changes and less Windows-specific references. * Use the same example path in all doc versions The 7.x docs use `$HOME\Format` as an example directory. This updates the 5.1 doc to use the same path. It also removes the suggestion to place custom formatting files in Win PS's `$PSHOME`. As this is a system directory, it's not an appropriate location for user files. * Fix formatting * Fix link references * Fix link references again * Apply suggestions from review --------- Co-authored-by: Mikey Lombardi (He/Him) <michael.t.lombardi@gmail.com>
1 parent 3dddc0c commit 6c4d0ff

File tree

5 files changed

+103
-74
lines changed

5 files changed

+103
-74
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Format.ps1xml.md

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: The `Format.ps1xml` files in PowerShell define the default display of objects in the PowerShell console. You can create your own `Format.ps1xml` files to change the display of objects or to define default displays for new object types that you create in PowerShell.
33
Locale: en-US
4-
ms.date: 04/25/2022
4+
ms.date: 12/26/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_format.ps1xml?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Format.ps1xml
@@ -88,7 +88,7 @@ headers, and the properties that are displayed in the body of the view. The
8888
format in `Format.ps1xml` files is applied just before the data is presented to
8989
the user.
9090

91-
## CREATING NEW FORMAT.PS1XML FILES
91+
## Creating new Format.ps1xml files
9292

9393
The `.ps1xml` files that are installed with PowerShell are digitally signed to
9494
prevent tampering because the formatting can include script blocks. To change
@@ -98,9 +98,7 @@ session.
9898

9999
To create a new file, copy an existing `Format.ps1xml` file. The new file can
100100
have any name, but it must have a `.ps1xml` file name extension. You can place
101-
the new file in any directory that is accessible to PowerShell, but it's useful
102-
to place the files in the PowerShell installation directory (`$PSHOME`) or in a
103-
subdirectory of the installation directory.
101+
the new file in any directory that is accessible to PowerShell.
104102

105103
To change the formatting of a current view, locate the view in the formatting
106104
file, and then use the tags to change the view. To create a view for a new
@@ -127,12 +125,11 @@ view of the culture objects. The following `Select-String` command finds the
127125
file:
128126

129127
```powershell
130-
$Parms = @{
131-
Path = "$PSHOME\*Format.ps1xml"
132-
Pattern = "System.Globalization.CultureInfo"
128+
$selectParams = @{
129+
Path = "$PSHOME\*Format.ps1xml"
130+
Pattern = 'System.Globalization.CultureInfo'
133131
}
134-
135-
Select-String @Parms
132+
Select-String @selectParams
136133
```
137134

138135
```Output
@@ -142,14 +139,20 @@ C:\Windows\System32\WindowsPowerShell\v1.0\DotNetTypes.format.ps1xml:115:
142139
<TypeName>System.Globalization.CultureInfo</TypeName>
143140
```
144141

145-
This command reveals that the definition is in the `DotNetTypes.Format.ps1xml`
142+
This command reveals that the definition is in the `DotNetTypes.format.ps1xml`
146143
file.
147144

148-
The next command copies the file contents to a new file,
149-
`MyDotNetTypes.Format.ps1xml`.
145+
The following commands copy the file contents to a new file named
146+
`MyDotNetTypes.Format.ps1xml` in a newly created `$HOME\Format` directory.
150147

151148
```powershell
152-
Copy-Item $PSHOME\DotNetTypes.format.ps1xml MyDotNetTypes.Format.ps1xml
149+
New-Item -Path $HOME\Format -ItemType Directory -Force
150+
151+
$copyParams = @{
152+
LiteralPath = "$PSHOME\DotNetTypes.format.ps1xml"
153+
Destination = "$HOME\Format\MyDotNetTypes.Format.ps1xml"
154+
}
155+
Copy-Item @copyParams
153156
```
154157

155158
Open the `MyDotNetTypes.Format.ps1xml` file in any XML or text editor, such as
@@ -289,10 +292,10 @@ the current PowerShell session.
289292

290293
This example uses the **PrependPath** parameter to place the new file in a
291294
higher precedence order than the original file. For more information, see
292-
[Update-FormatData](xref:Microsoft.PowerShell.Utility.Update-FormatData).
295+
[Update-FormatData][03].
293296

294297
```powershell
295-
Update-FormatData -PrependPath $HOME\Format\CultureInfo.Format.ps1xml
298+
Update-FormatData -PrependPath $HOME\Format\MyDotNetTypes.Format.ps1xml
296299
```
297300

298301
To test the change, type `Get-Culture` and review the output that includes the
@@ -310,8 +313,8 @@ LCID Name Calendar DisplayName
310313

311314
## The XML in Format.ps1xml files
312315

313-
The full schema definition can be found in [Format.xsd](https://github.com/PowerShell/PowerShell/blob/master/src/Schemas/Format.xsd)
314-
in the PowerShell source code repository on GitHub.
316+
The full schema definition can be found in [Format.xsd][04] in the PowerShell
317+
source code repository on GitHub.
315318

316319
The **ViewDefinitions** section of each `Format.ps1xml` file contains the
317320
`<View>` tags that define each view. A typical `<View>` tag includes the
@@ -376,13 +379,13 @@ that the `<ListControl>` tag is intended to display.
376379
### WideControl tag
377380

378381
The `<WideControl>` tag typically contains a `<WideEntries>` tag. The
379-
`<WideEntries>` tag contains one or more `<WideEntry>` tags. A `<WideEntry>` tag
380-
contains one `<WideItem>` tag.
382+
`<WideEntries>` tag contains one or more `<WideEntry>` tags. A `<WideEntry>`
383+
tag contains one `<WideItem>` tag.
381384

382385
A `<WideItem>` tag must include either a `<PropertyName>` tag or a
383-
`<ScriptBlock>` tag. A `<PropertyName>` tag specifies the property to display at
384-
the specified location in the view. A `<ScriptBlock>` tag specifies a script to
385-
evaluate and display at the specified location in the view.
386+
`<ScriptBlock>` tag. A `<PropertyName>` tag specifies the property to display
387+
at the specified location in the view. A `<ScriptBlock>` tag specifies a script
388+
to evaluate and display at the specified location in the view.
386389

387390
A `<WideItem>` tag can contain a `<FormatString>` tag that specifies how to
388391
display the property.
@@ -396,7 +399,7 @@ multiple `<CustomEntry>` tags. Each `<CustomEntry>` tag contains a
396399
formatting of the specified location in the view, including `<Text>`,
397400
`<Indentation>`, `<ExpressionBinding>`, and `<NewLine>` tags.
398401

399-
## DEFAULT DISPLAYS IN TYPES.PS1XML
402+
## Default displays in Types.ps1xml
400403

401404
The default displays of some basic object types are defined in the
402405
`Types.ps1xml` file in the `$PSHOME` directory. The nodes are named
@@ -417,15 +420,12 @@ value of the **Name** parameter:
417420
- FormatFileLoading
418421
- FormatViewBinding
419422

420-
For more information, see
421-
[Trace-Command](xref:Microsoft.PowerShell.Utility.Trace-Command) and
422-
[Get-TraceSource](xref:Microsoft.PowerShell.Utility.Get-TraceSource).
423+
For more information, see [Trace-Command][05] and [Get-TraceSource][06].
423424

424425
## Signing a Format.ps1xml file
425426

426427
To protect the users of your `Format.ps1xml` file, sign the file using a
427-
digital signature. For more information, see
428-
[about_Signing](about_Signing.md).
428+
digital signature. For more information, see [about_Signing][07].
429429

430430
## Sample XML for a Format-Table custom view
431431

@@ -434,25 +434,38 @@ The following sample creates a `Format-Table` custom view for the
434434
`Get-ChildItem`. The custom view is named **MyGciView** and adds the
435435
**CreationTime** column to the table.
436436

437+
Use `Select-String` to identify which `Format.ps1xml` file contains data for
438+
the type you're looking for.
439+
437440
The custom view is created from an edited version of the
438441
`FileSystem.Format.ps1xml` file that's stored in `$PSHOME` on PowerShell 5.1.
439442

440-
After your custom `.ps1xml` file is saved, use `Update-FormatData` to include
441-
the view in a PowerShell session. For this example, the custom view must use
442-
the table format, otherwise, `Format-Table` fails.
443+
After the custom `.ps1xml` file is saved, use the `Update-FormatData` cmdlet to
444+
include the view in the current PowerShell session. Or, add the update command
445+
to your PowerShell profile if you need the view available in all PowerShell
446+
sessions.
447+
448+
For this example, the custom view must use the table format, otherwise,
449+
`Format-Table` fails.
443450

444451
Use `Format-Table` with the **View** parameter to specify the custom view's
445-
name and format the table's output. For an example of how the command is run,
446-
see [Format-Table](xref:Microsoft.PowerShell.Utility.Format-Table).
452+
name, **MyGciView**, and format the table's output with the **CreationTime**
453+
column. For an example of how the command is run, see [Format-Table][08].
447454

448455
```powershell
449-
$Parms = @{
450-
Path = "$PSHOME\*Format.ps1xml"
451-
Pattern = "System.IO.DirectoryInfo"
456+
$selectParams = @{
457+
Path = "$PSHOME\*format.ps1xml"
458+
Pattern = 'System.IO.DirectoryInfo'
452459
}
453-
Select-String @Parms
454-
Copy-Item $PSHOME\FileSystem.format.ps1xml .\MyFileSystem.Format.ps1xml
455-
Update-FormatData -PrependPath $PSHOME\Format\MyFileSystem.Format.ps1xml
460+
Select-String @selectParams
461+
462+
$copyParams = @{
463+
LiteralPath = "$PSHOME\FileSystem.format.ps1xml"
464+
Destination = "$HOME\Format\MyFileSystem.Format.ps1xml"
465+
}
466+
Copy-Item @copyParams
467+
468+
Update-FormatData -PrependPath $HOME\Format\MyFileSystem.Format.ps1xml
456469
```
457470

458471
> [!NOTE]
@@ -582,9 +595,10 @@ Update-FormatData -PrependPath $PSHOME\Format\MyFileSystem.Format.ps1xml
582595
[01]: xref:Microsoft.PowerShell.Utility.Get-FormatData
583596
[02]: xref:Microsoft.PowerShell.Utility.Export-FormatData
584597
[03]: xref:Microsoft.PowerShell.Utility.Update-FormatData
585-
598+
[04]: https://github.com/PowerShell/PowerShell/blob/master/src/Schemas/Format.xsd
586599
[05]: xref:Microsoft.PowerShell.Utility.Trace-Command
587600
[06]: xref:Microsoft.PowerShell.Utility.Get-TraceSource
588-
601+
[07]: about_Signing.md
602+
[08]: xref:Microsoft.PowerShell.Utility.Format-Table
589603
[09]: /powershell/scripting/developer/format/format-schema-xml-reference
590604
[10]: /powershell/scripting/developer/format/writing-a-powershell-formatting-file

reference/7.4/Microsoft.PowerShell.Core/About/about_Format.ps1xml.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Beginning in PowerShell 6, the default views for objects are defined in PowerShell source code. You can create your own `Format.ps1xml` files to change the display of objects or to define default displays for new object types that you create in PowerShell.
33
Locale: en-US
4-
ms.date: 04/25/2022
4+
ms.date: 12/26/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_format.ps1xml?view=powershell-7.4&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Format.ps1xml
@@ -93,8 +93,10 @@ To begin, get the format data from the source code file and create a
9393
`Format.ps1xml` file that contains the current view of the culture objects.
9494

9595
```powershell
96+
New-Item -Path $HOME\Format -ItemType Directory -Force
97+
9698
Get-FormatData -TypeName System.Globalization.CultureInfo |
97-
Export-FormatData -Path $HOME\Format\CultureInfo.Format.ps1xml
99+
Export-FormatData -LiteralPath $HOME\Format\CultureInfo.Format.ps1xml
98100
```
99101

100102
Open the `CultureInfo.Format.ps1xml` file in any XML or text editor, such as
@@ -278,8 +280,8 @@ that the `<ListControl>` tag is intended to display.
278280
### WideControl tag
279281

280282
The `<WideControl>` tag typically contains a `<WideEntries>` tag. The
281-
`<WideEntries>` tag contains one or more `<WideEntry>` tags. A `<WideEntry>` tag
282-
contains one `<WideItem>` tag.
283+
`<WideEntries>` tag contains one or more `<WideEntry>` tags. A `<WideEntry>`
284+
tag contains one `<WideItem>` tag.
283285

284286
A `<WideItem>` tag must include either a `<PropertyName>` tag or a
285287
`<ScriptBlock>` tag. A `<PropertyName>` tag specifies the property to display
@@ -349,8 +351,9 @@ specific PowerShell version.
349351

350352
```powershell
351353
Get-FormatData -PowerShellVersion 5.1 -TypeName System.IO.DirectoryInfo |
352-
Export-FormatData -Path ./MyGciView.Format.ps1xml
353-
Update-FormatData -AppendPath ./MyGciView.Format.ps1xml
354+
Export-FormatData -LiteralPath $HOME\Format\MyGciView.Format.ps1xml
355+
356+
Update-FormatData -AppendPath $HOME\Format\MyGciView.Format.ps1xml
354357
```
355358

356359
```xml

reference/7.5/Microsoft.PowerShell.Core/About/about_Format.ps1xml.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Beginning in PowerShell 6, the default views for objects are defined in PowerShell source code. You can create your own `Format.ps1xml` files to change the display of objects or to define default displays for new object types that you create in PowerShell.
33
Locale: en-US
4-
ms.date: 04/25/2022
4+
ms.date: 12/26/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_format.ps1xml?view=powershell-7.5&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Format.ps1xml
@@ -93,8 +93,10 @@ To begin, get the format data from the source code file and create a
9393
`Format.ps1xml` file that contains the current view of the culture objects.
9494

9595
```powershell
96+
New-Item -Path $HOME\Format -ItemType Directory -Force
97+
9698
Get-FormatData -TypeName System.Globalization.CultureInfo |
97-
Export-FormatData -Path $HOME\Format\CultureInfo.Format.ps1xml
99+
Export-FormatData -LiteralPath $HOME\Format\CultureInfo.Format.ps1xml
98100
```
99101

100102
Open the `CultureInfo.Format.ps1xml` file in any XML or text editor, such as
@@ -278,8 +280,8 @@ that the `<ListControl>` tag is intended to display.
278280
### WideControl tag
279281

280282
The `<WideControl>` tag typically contains a `<WideEntries>` tag. The
281-
`<WideEntries>` tag contains one or more `<WideEntry>` tags. A `<WideEntry>` tag
282-
contains one `<WideItem>` tag.
283+
`<WideEntries>` tag contains one or more `<WideEntry>` tags. A `<WideEntry>`
284+
tag contains one `<WideItem>` tag.
283285

284286
A `<WideItem>` tag must include either a `<PropertyName>` tag or a
285287
`<ScriptBlock>` tag. A `<PropertyName>` tag specifies the property to display
@@ -349,8 +351,9 @@ specific PowerShell version.
349351

350352
```powershell
351353
Get-FormatData -PowerShellVersion 5.1 -TypeName System.IO.DirectoryInfo |
352-
Export-FormatData -Path ./MyGciView.Format.ps1xml
353-
Update-FormatData -AppendPath ./MyGciView.Format.ps1xml
354+
Export-FormatData -Path $HOME\Format\MyGciView.Format.ps1xml
355+
356+
Update-FormatData -AppendPath $HOME\Format\MyGciView.Format.ps1xml
354357
```
355358

356359
```xml

reference/7.6/Microsoft.PowerShell.Core/About/about_Format.ps1xml.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Beginning in PowerShell 6, the default views for objects are defined in PowerShell source code. You can create your own `Format.ps1xml` files to change the display of objects or to define default displays for new object types that you create in PowerShell.
33
Locale: en-US
4-
ms.date: 04/25/2022
4+
ms.date: 12/26/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_format.ps1xml?view=powershell-7.6&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Format.ps1xml
@@ -93,8 +93,10 @@ To begin, get the format data from the source code file and create a
9393
`Format.ps1xml` file that contains the current view of the culture objects.
9494

9595
```powershell
96+
New-Item -Path $HOME\Format -ItemType Directory -Force
97+
9698
Get-FormatData -TypeName System.Globalization.CultureInfo |
97-
Export-FormatData -Path $HOME\Format\CultureInfo.Format.ps1xml
99+
Export-FormatData -LiteralPath $HOME\Format\CultureInfo.Format.ps1xml
98100
```
99101

100102
Open the `CultureInfo.Format.ps1xml` file in any XML or text editor, such as
@@ -278,8 +280,8 @@ that the `<ListControl>` tag is intended to display.
278280
### WideControl tag
279281

280282
The `<WideControl>` tag typically contains a `<WideEntries>` tag. The
281-
`<WideEntries>` tag contains one or more `<WideEntry>` tags. A `<WideEntry>` tag
282-
contains one `<WideItem>` tag.
283+
`<WideEntries>` tag contains one or more `<WideEntry>` tags. A `<WideEntry>`
284+
tag contains one `<WideItem>` tag.
283285

284286
A `<WideItem>` tag must include either a `<PropertyName>` tag or a
285287
`<ScriptBlock>` tag. A `<PropertyName>` tag specifies the property to display
@@ -349,8 +351,9 @@ specific PowerShell version.
349351

350352
```powershell
351353
Get-FormatData -PowerShellVersion 5.1 -TypeName System.IO.DirectoryInfo |
352-
Export-FormatData -Path ./MyGciView.Format.ps1xml
353-
Update-FormatData -AppendPath ./MyGciView.Format.ps1xml
354+
Export-FormatData -Path $HOME\Format\MyGciView.Format.ps1xml
355+
356+
Update-FormatData -AppendPath $HOME\Format\MyGciView.Format.ps1xml
354357
```
355358

356359
```xml
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
---
2-
description: How to Create a Formatting File (.format.ps1xml)
3-
ms.date: 08/23/2021
4-
title: How to Create a Formatting File (.format.ps1xml)
2+
description: How to Create a Formatting File (Format.ps1xml)
3+
ms.date: 12/26/2025
4+
title: How to Create a Formatting File (Format.ps1xml)
55
---
6-
# How to Create a Formatting File (.format.ps1xml)
6+
# How to Create a Formatting File (Format.ps1xml)
77

8-
This topic describes how to create a formatting file (.format.ps1xml).
8+
This topic describes how to create a formatting file (`Format.ps1xml`).
99

1010
> [!NOTE]
1111
> You can also create a formatting file by making a copy of one of the files provided by Windows
12-
> PowerShell. If you make a copy of an existing file, delete the existing digital signature, and add
13-
> your own signature to the new file.
12+
> PowerShell. To protect the users of your `Format.ps1xml` file, sign the file using a digital
13+
> signature. For more information, see [about_Signing][01].
1414
15-
## Create a .format.ps1xml file.
15+
## Create a Format.ps1xml file
1616

17-
1. Create a text file (.txt) using a text editor such as Notepad.
17+
1. Open a new text file using a text editor such as Visual Studio Code.
1818

1919
1. Copy the following lines into the formatting file.
2020

2121
```xml
22-
<?xml version="1.0" encoding="utf-8" ?>
22+
<?xml version="1.0" encoding="utf-8"?>
2323
<Configuration>
2424
<ViewDefinitions>
2525
</ViewDefinitions>
@@ -32,14 +32,20 @@ This topic describes how to create a formatting file (.format.ps1xml).
3232
- The `<ViewDefinitions></ViewDefinitions>` tags define the `ViewDefinitions` node. All views are
3333
defined within this node.
3434

35-
1. Save the file to the Windows PowerShell installation folder, to your module folder, or to a
35+
1. Save the file to a folder of your choice. If you are writing a module, save the file to a
3636
subfolder of the module folder. Use the following name format when you save the file:
37-
`MyFile.format.ps1xml`. Formatting files must use the `.format.ps1xml` extension.
37+
`MyFile.Format.ps1xml`. Formatting files must use the `.ps1xml` extension.
3838

3939
You are now ready to add views to the formatting file. There is no limit to the number of views
4040
that can be defined in a formatting file. You can add a single view for each object, multiple
4141
views for the same object, or a single view that is used by multiple objects.
4242

43-
## See Also
43+
## See also
4444

45-
[Writing a Windows PowerShell Formatting and Types File](./writing-a-powershell-formatting-file.md)
45+
- [Formatting File Overview][02]
46+
- [Formatting File Concepts][03]
47+
48+
<!-- link references -->
49+
[01]: /powershell/module/microsoft.powershell.core/about/about_signing
50+
[02]: ./formatting-file-overview.md
51+
[03]: ./formatting-file-concepts.md

0 commit comments

Comments
 (0)