{"id":6518,"date":"2019-02-18T12:57:27","date_gmt":"2019-02-18T17:57:27","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=6518"},"modified":"2019-02-18T12:57:35","modified_gmt":"2019-02-18T17:57:35","slug":"powershell-format-files-the-easy-way","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/","title":{"rendered":"PowerShell Format Files the Easy Way"},"content":{"rendered":"<p>Whenever I teach or present on PowerShell scripting, I'm always talking about writing objects to the pipeline. Most of the time you can simply let PowerShell format and display output of your command to the best of its ability. However, you may wish to take matters into your own hands and create custom output. For example, when your run <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113324\" target=\"_blank\" rel=\"noopener\">Get-Process<\/a> PowerShell displays a formatted table. But you know that the display is not necessary the underlying object that you see with <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113322\" target=\"_blank\" rel=\"noopener\">Get-Member<\/a>. PowerShell defines a default view for Process objects. You can do the same thing with your commands.<\/p>\n<h2>Creating Custom Output<\/h2>\n<p>Here's a relatively simple script that writes a custom object to the pipeline with properties derived from a number of WMI classes.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">Function Get-SysInfo {\n\n    [cmdletbinding()]\n\n    Param(\n        [Parameter(Position = 0, ValueFromPipeline)]\n        [ValidateNotNullorEmpty()]\n        [string]$Computername = $env:computername,\n        [PSCredential]$Credential\n    )\n\n    Begin {\n        $cimParams = @{\n            Classname   = \"\"\n            CimSession  = \"\"\n            Property    = \"*\"\n            ErrorAction = \"stop\"\n        }\n    }\n\n    Process {\n        Try {\n            $sess = New-CimSession @PSBoundParameters\n            $cimParams.cimSession = $sess\n        }\n        Catch {\n            Throw $_\n        }\n\n        $cimParams.Classname = \"Win32_Operatingsystem\"\n        $cimParams.Property = \"CSName\", \"Caption\",\"Version\"\n        Try {\n            $os = Get-CimInstance @cimParams\n        }\n        Catch {\n            Throw $_\n        }\n        $cimParams.Classname = \"Win32_Computersystem\"\n        $cimParams.Property = \"Manufacturer\", \"Model\"\n        $cs = Get-CimInstance @cimParams\n\n        $cimParams.Classname = \"Win32_Process\"\n        $cimParams.Property = \"Name\"\n        $procs = Get-CimInstance @cimParams\n\n        $cimParams.Classname = \"Win32_Service\"\n        $cimParams.Filter = \"State = 'running'\"\n        $running = Get-Ciminstance @cimParams\n\n        [PSCustomobject]@{\n            PSTypeName   = \"mySysInfo\"\n            Computername = $os.CSName\n            OS           = $os.Caption\n            Version      = $os.Version\n            System       = (\"{0} {1}\" -f $cs.Manufacturer.Trim(), $cs.Model.Trim())\n            Services     = $Running.Count\n            Processes    = $Procs.count\n        }\n\n        $cimParams.remove(\"filter\")\n        Remove-CimSession $sess\n\n    } #close Process\n    End {\n        #not used\n    }\n} #close function\n<\/pre>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Sample default output\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-4.png\" alt=\"Sample default output\" width=\"805\" height=\"322\" border=\"0\"><\/a><\/p>\n<p>I'm defining a custom type name as part of the custom object.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Viewing the custom object\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-5.png\" alt=\"Viewing the custom object\" width=\"1028\" height=\"529\" border=\"0\"><\/a><\/p>\n<p>Let's say I prefer the default output to be a table instead of a list. This will require a table definition stored in a format.ps1xml file. These files can be tricky to create. I used to find something in an existing file like $PSHome\\DotnetTypes.format.ps1xml and copy it into a new file which I then updated. But now I have a much better solution.<\/p>\n<h2>New-PSFormatXML<\/h2>\n<p>My <a title=\"check out the module's repository on GitHub\" href=\"https:\/\/github.com\/jdhitsolutions\/PSScriptTools\" target=\"_blank\" rel=\"blank noopener\">PSScriptTools<\/a> module (which you can install from the PowerShell Gallery) now includes a command called <a title=\"read the online help\" href=\"https:\/\/github.com\/jdhitsolutions\/PSScriptTools\/blob\/master\/docs\/New-PSFormatXML.md\" target=\"_blank\" rel=\"blank noopener\">New-PSFormatXML<\/a>. The command is designed to analyze an object and by default create a table view of all properties, although you can specify which properties to include. The format.ps1xml file will autosize the table but you can remove the directive and use the widths which are best guesses. Expect some trial and error when defining a new view.<\/p>\n<p>Creating a new file is as easy as this:<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">Get-SysInfo | New-PSFormatXML -Path .\\mySysInfo.format.ps1xml\n<\/pre>\n<p>You only need a single instance of an object. You can pipe multiple objects to New-PSFormatXML but subsequent ones will be ignored. The command will generate an xml file like this:<\/p>\n<pre class=\"lang:xml mark:0 decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;!--\nformat type data generated 02\/18\/2019 12:19:49\nby BOVINE320\\Jeff\n--&gt;\n&lt;Configuration&gt;\n  &lt;ViewDefinitions&gt;\n    &lt;View&gt;\n      &lt;!--Created 02\/18\/2019 12:19:49 by BOVINE320\\Jeff--&gt;\n      &lt;Name&gt;default&lt;\/Name&gt;\n      &lt;ViewSelectedBy&gt;\n        &lt;TypeName&gt;mySysInfo&lt;\/TypeName&gt;\n      &lt;\/ViewSelectedBy&gt;\n      &lt;TableControl&gt;\n        &lt;!--Delete the AutoSize node if you want to use the defined widths.--&gt;\n        &lt;AutoSize \/&gt;\n        &lt;TableHeaders&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Computername&lt;\/Label&gt;\n            &lt;Width&gt;15&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;OS&lt;\/Label&gt;\n            &lt;Width&gt;27&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Version&lt;\/Label&gt;\n            &lt;Width&gt;13&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;System&lt;\/Label&gt;\n            &lt;Width&gt;20&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Services&lt;\/Label&gt;\n            &lt;Width&gt;11&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Processes&lt;\/Label&gt;\n            &lt;Width&gt;12&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n        &lt;\/TableHeaders&gt;\n        &lt;TableRowEntries&gt;\n          &lt;TableRowEntry&gt;\n            &lt;TableColumnItems&gt;\n              &lt;!--\n            By default the entries use property names, but you can replace them with scriptblocks.\n            &lt;Scriptblock&gt;$_.foo \/1mb -as [int]&lt;\/Scriptblock&gt;\n--&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Computername&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;OS&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Version&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;System&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Services&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Processes&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n            &lt;\/TableColumnItems&gt;\n          &lt;\/TableRowEntry&gt;\n        &lt;\/TableRowEntries&gt;\n      &lt;\/TableControl&gt;\n    &lt;\/View&gt;\n  &lt;\/ViewDefinitions&gt;\n&lt;\/Configuration&gt;\n<\/pre>\n<p>From here I could edit the file as necessary. But since I'm happy displaying all the properties in a table I'll update PowerShell with this information.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">Update-FormatData -AppendPath .\\mySysInfo.format.ps1xml\n<\/pre>\n<p>Now when I run my function, I get a table display by default.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Default table view\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-6.png\" alt=\"Default table view\" width=\"644\" height=\"78\" border=\"0\"><\/a><\/p>\n<h2>Adding More Views<\/h2>\n<p>I can also create additional views.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">Get-SysInfo | New-PSFormatXML -Path .\\mySysInfo.format.ps1xml -Properties \"Computername\",\"OS\",\"Version\" -ViewName OS -Append\n<\/pre>\n<p>Again, I modify the view, even adding custom properties. Here's my revised format file.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;!--\nformat type data generated 02\/18\/2019 12:30:50\nby BOVINE320\\Jeff\n--&gt;\n&lt;Configuration&gt;\n  &lt;ViewDefinitions&gt;\n    &lt;View&gt;\n      &lt;!--Created 02\/18\/2019 12:30:50 by BOVINE320\\Jeff--&gt;\n      &lt;Name&gt;default&lt;\/Name&gt;\n      &lt;ViewSelectedBy&gt;\n        &lt;TypeName&gt;mySysInfo&lt;\/TypeName&gt;\n      &lt;\/ViewSelectedBy&gt;\n      &lt;TableControl&gt;\n        &lt;!--Delete the AutoSize node if you want to use the defined widths.--&gt;\n        &lt;AutoSize \/&gt;\n        &lt;TableHeaders&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Computername&lt;\/Label&gt;\n            &lt;Width&gt;15&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;OS&lt;\/Label&gt;\n            &lt;Width&gt;27&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Version&lt;\/Label&gt;\n            &lt;Width&gt;13&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;System&lt;\/Label&gt;\n            &lt;Width&gt;20&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Services&lt;\/Label&gt;\n            &lt;Width&gt;11&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Processes&lt;\/Label&gt;\n            &lt;Width&gt;12&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n        &lt;\/TableHeaders&gt;\n        &lt;TableRowEntries&gt;\n          &lt;TableRowEntry&gt;\n            &lt;TableColumnItems&gt;\n              &lt;!--\n            By default the entries use property names, but you can replace them with scriptblocks.\n            &lt;Scriptblock&gt;$_.foo \/1mb -as [int]&lt;\/Scriptblock&gt;\n--&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Computername&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;OS&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Version&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;System&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Services&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Processes&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n            &lt;\/TableColumnItems&gt;\n          &lt;\/TableRowEntry&gt;\n        &lt;\/TableRowEntries&gt;\n      &lt;\/TableControl&gt;\n    &lt;\/View&gt;\n    &lt;View&gt;\n      &lt;!--Created 02\/18\/2019 12:31:00 by BOVINE320\\Jeff--&gt;\n      &lt;Name&gt;OS&lt;\/Name&gt;\n      &lt;ViewSelectedBy&gt;\n        &lt;TypeName&gt;mySysInfo&lt;\/TypeName&gt;\n      &lt;\/ViewSelectedBy&gt;\n      &lt;TableControl&gt;\n        &lt;TableHeaders&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Computername&lt;\/Label&gt;\n            &lt;Width&gt;15&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;OS&lt;\/Label&gt;\n            &lt;Width&gt;40&lt;\/Width&gt;\n            &lt;Alignment&gt;left&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n          &lt;TableColumnHeader&gt;\n            &lt;Label&gt;Version&lt;\/Label&gt;\n            &lt;Width&gt;13&lt;\/Width&gt;\n            &lt;Alignment&gt;right&lt;\/Alignment&gt;\n          &lt;\/TableColumnHeader&gt;\n        &lt;\/TableHeaders&gt;\n        &lt;TableRowEntries&gt;\n          &lt;TableRowEntry&gt;\n            &lt;TableColumnItems&gt;\n              &lt;!--\n            By default the entries use property names, but you can replace them with scriptblocks.\n            &lt;Scriptblock&gt;$_.foo \/1mb -as [int]&lt;\/Scriptblock&gt;\n--&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Computername&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;Scriptblock&gt;$($_.OS -replace \"^Microsoft\",\"\").trim()&lt;\/Scriptblock&gt;\n              &lt;\/TableColumnItem&gt;\n              &lt;TableColumnItem&gt;\n                &lt;PropertyName&gt;Version&lt;\/PropertyName&gt;\n              &lt;\/TableColumnItem&gt;\n            &lt;\/TableColumnItems&gt;\n          &lt;\/TableRowEntry&gt;\n        &lt;\/TableRowEntries&gt;\n      &lt;\/TableControl&gt;\n    &lt;\/View&gt;\n  &lt;\/ViewDefinitions&gt;\n&lt;\/Configuration&gt;\n<\/pre>\n<p>In this view I'm using a scriptblock to define the OS property that strips off 'Microsoft' from the name.&nbsp; To use I update the format data and pipe the command to <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113303\" target=\"_blank\" rel=\"noopener\">Format-Table<\/a> specifying the view name.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image-7.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Using a custom table view\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-7.png\" alt=\"Using a custom table view\" width=\"1028\" height=\"274\" border=\"0\"><\/a><\/p>\n<h2>Make it Pretty<\/h2>\n<p>Now there is no reason not have pretty or at least meaningful output from your functions. If you are writing custom objects to the pipeline, as long as you define a typename, it should now be much easier to create the formatting directives. In your module manifest, specify your format.ps1xml files in the <em>FormatsToProcess<\/em> section.<\/p>\n<p>I hope you find this a useful addition to your PowerShell toolbox. I know this is something I will be using all the time now in my work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whenever I teach or present on PowerShell scripting, I&#8217;m always talking about writing objects to the pipeline. Most of the time you can simply let PowerShell format and display output of your command to the best of its ability. However, you may wish to take matters into your own hands and create custom output. For&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New on the blog: #PowerShell Format Files the Easy Way","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,8],"tags":[282,534],"class_list":["post-6518","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-formatdata","tag-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PowerShell Format Files the Easy Way &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"Here is a super simple way to create custom format files that you include with your PowerShell functions and modules. You don&#039;t even need to know XML!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell Format Files the Easy Way &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Here is a super simple way to create custom format files that you include with your PowerShell functions and modules. You don&#039;t even need to know XML!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-18T17:57:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-18T17:57:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-4.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"PowerShell Format Files the Easy Way\",\"datePublished\":\"2019-02-18T17:57:27+00:00\",\"dateModified\":\"2019-02-18T17:57:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/\"},\"wordCount\":523,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/image_thumb-4.png\",\"keywords\":[\"FormatData\",\"PowerShell\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/\",\"name\":\"PowerShell Format Files the Easy Way &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/image_thumb-4.png\",\"datePublished\":\"2019-02-18T17:57:27+00:00\",\"dateModified\":\"2019-02-18T17:57:35+00:00\",\"description\":\"Here is a super simple way to create custom format files that you include with your PowerShell functions and modules. You don't even need to know XML!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/image_thumb-4.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/image_thumb-4.png\",\"width\":805,\"height\":322},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6518\\\/powershell-format-files-the-easy-way\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell Format Files the Easy Way\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PowerShell Format Files the Easy Way &#8226; The Lonely Administrator","description":"Here is a super simple way to create custom format files that you include with your PowerShell functions and modules. You don't even need to know XML!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell Format Files the Easy Way &#8226; The Lonely Administrator","og_description":"Here is a super simple way to create custom format files that you include with your PowerShell functions and modules. You don't even need to know XML!","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/","og_site_name":"The Lonely Administrator","article_published_time":"2019-02-18T17:57:27+00:00","article_modified_time":"2019-02-18T17:57:35+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-4.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"PowerShell Format Files the Easy Way","datePublished":"2019-02-18T17:57:27+00:00","dateModified":"2019-02-18T17:57:35+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/"},"wordCount":523,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-4.png","keywords":["FormatData","PowerShell"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/","name":"PowerShell Format Files the Easy Way &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-4.png","datePublished":"2019-02-18T17:57:27+00:00","dateModified":"2019-02-18T17:57:35+00:00","description":"Here is a super simple way to create custom format files that you include with your PowerShell functions and modules. You don't even need to know XML!","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-4.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-4.png","width":805,"height":322},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6518\/powershell-format-files-the-easy-way\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"PowerShell Format Files the Easy Way"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":4707,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4707\/a-better-powershell-more\/","url_meta":{"origin":6518,"position":0},"title":"A Better PowerShell More","author":"Jeffery Hicks","date":"December 23, 2015","format":false,"excerpt":"In PowerShell, when I have a lot of output, I can use the legacy more.com command to page the results to the screen. Get-Process | more There's not anything inherently wrong with this approach. Although one drawback is that it doesn't work in the PowerShell ISE. For that reason alone\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"More PowerShell Output","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png?resize=525%2C300 1.5x"},"classes":[]},{"id":840,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/840\/pipelines-consoles-and-hosts\/","url_meta":{"origin":6518,"position":1},"title":"Pipelines, Consoles and Hosts","author":"Jeffery Hicks","date":"August 19, 2010","format":false,"excerpt":"I continue to come across a particular topic in discussion forums that causes many PowerShell beginners a lot of headaches and more than a little frustration. I know I've written about this before and I'm sure I'll cover it again, but when writing anything in PowerShell that you see in\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/08\/write-demo.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":7937,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7937\/creating-powershell-property-names\/","url_meta":{"origin":6518,"position":2},"title":"Creating PowerShell Property Names","author":"Jeffery Hicks","date":"December 8, 2020","format":false,"excerpt":"The last week or so I've been playing with a new PowerShell project from Dave Carroll for using Twitter from a PowerShell prompt. The module is called BluebirdPS and you can install it from the PowerShell Gallery. The module is very much still in its early stages but is functional\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/psobject-properites.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/psobject-properites.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/psobject-properites.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/psobject-properites.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":9074,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/","url_meta":{"origin":6518,"position":3},"title":"The Value of Objects","author":"Jeffery Hicks","date":"July 5, 2022","format":false,"excerpt":"This is a reprint of an article published earlier this year in my premium PowerShell newsletter, Behind the PowerShell Pipeline. This is a sample of what my subscribers get 6-8 times a month. I expect I will write several articles about PowerShell and its relationship with objects. I know that\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/getting-drive-usage.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/getting-drive-usage.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/getting-drive-usage.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":6478,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/","url_meta":{"origin":6518,"position":4},"title":"Getting Git Size with PowerShell Retooled","author":"Jeffery Hicks","date":"January 30, 2019","format":false,"excerpt":"A few days ago I wrote about my experiences in designing a PowerShell function that reports on the size of the hidden .git folder. In that version of the function I decided to include a parameter that would permit the user to get the size pre-formatted as either KB, MB\u2026","rel":"","context":"In &quot;Git&quot;","block_context":{"text":"Git","link":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-29.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-29.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-29.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-29.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":6855,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6855\/powershell-scripting-for-linux-is-still-about-the-objects\/","url_meta":{"origin":6518,"position":5},"title":"PowerShell Scripting for Linux is Still About the Objects","author":"Jeffery Hicks","date":"October 8, 2019","format":false,"excerpt":"I've been trying to increase my Linux skills, especially as I begin to write PowerShell scripts and tools that can work cross-platform. One very important concept I want to make sure you don't overlook is that even when scripting for non-Windows platforms, you must still be thinking about objects. The\u2026","rel":"","context":"In &quot;PowerShell 7&quot;","block_context":{"text":"PowerShell 7","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-7\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=6518"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6518\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=6518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=6518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=6518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}