PowerShell 2.0: One Cmdlet at a Time 87 Get-FormatData
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-FormatData cmdlet.
What can I do with it?
Retrive format data from the current session. Within a session formatting data could include formatting from *.ps1xml format files stored in the PowerShell installation directory, formatting from imported modules or snapins, or formatting from commands imported with Import-PSSession.
Example:
Retrieve the formatting for the TypeName Microsoft.Win32.RegistryKey and view some of its properties.
$registryformatting = Get-FormatData -TypeName Microsoft.Win32.RegistryKey $registryformatting.FormatViewDefinition[0].control.headers | Format-Table -Autosize
You will notice that some properties are obtained by drilling down into its XML style format.
This same data can be viewed in the file Registry.format.ps1xml which is located in the PowerShell installation folder. You can determine this location by examining the $pshome variable, typically it is C:\Windows\System32\WindowsPowerShell\v1.0 .
Notice below the same data in the file Registry.format.ps1xml .
How could I have done this in PowerShell 1.0?
In the example above you could have viewed the Registry.format.ps1xml in an XML viewer or used
Get-Content C:\Windows\System32\WindowsPowerShell\v1.0\Registry.format.ps1xml
to read in the XML file.