{"id":7774,"date":"2020-10-15T14:18:34","date_gmt":"2020-10-15T18:18:34","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7774"},"modified":"2020-10-15T14:20:52","modified_gmt":"2020-10-15T18:20:52","slug":"easy-powershell-custom-formatting","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/","title":{"rendered":"Easy PowerShell Custom Formatting"},"content":{"rendered":"\n<p>One of the features I truly enjoy about PowerShell, is the ability to have it present information that I need in a form that I want. Here's a good example. Running Get-Process is simple enough and the output is pretty complete. But one thing that would make it better for me, is that sometimes I want an easy way to see high-memory use properties. Yes, I can pipe Get-Process to Sort-Object and Where-Object. However, in this particular situation, what I <em>really<\/em> want is to see high-memory usage processes displayed in red. Maybe those that are getting close to my arbitrary limit I'd like to see in Yellow. This isn't that difficult to achieve using ANSI escape sequences.<\/p>\n\n\n\n<p>To try this out, I defined an array of custom properties that in essence duplicates the default output from Get-Process.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$props = @(\n    \"Handles\",\n    @{Name = \"NPM(K)\"; Expression = { [int]($_.npm \/ 1kb) } },\n    @{Name = \"PM(K)\"; Expression = { [int]($_.pm \/ 1kb) } },\n    @{Name = \"WS(M)\"; Expression = {\n            if ($_.ws -ge 500MB) {\n                \"$([char]0x1b)[91m$([int]($_.ws\/1mb))$([char]0x1b)[0m\"\n            }\n            elseif ($_.ws -ge 250MB) {\n                \"$([char]0x1b)[93m$([int]($_.ws\/1mb))$([char]0x1b)[0m\"\n            }\n            else {\n                [int]($_.ws \/ 1mb)\n            }\n        }\n    },\n    @{Name = \"CPU\"; Expression = { New-TimeSpan -Seconds $_.cpu } },\n    \"ID\",\n    @{Name = \"ProcessName\"; Expression = {\n            if ($_.ws -ge 500MB) {\n                \"$([char]0x1b)[1;91m$($_.processname)$([char]0x1b)[0m\"\n            }\n            elseif ($_.ws -ge 250MB) {\n                \"$([char]0x1b)[1;93m$($_.processname)$([char]0x1b)[0m\"\n            }\n            else {\n                $_.processname\n            }\n        }\n    }\n)\n<\/code><\/pre>\n\n\n\n<p>The custom properties are defined as hashtables, just as you would when using Select-Object. In this code, if the WorkingSet value is greater or equal to MB then the WS and Process name values are formatted in red using an ANSI escape sequence that will work in both Windows PowerShell and PowerShell 7.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">\"$([char]0x1b)[1;91m$($_.processname)$([char]0x1b)[0m\"<\/code><\/pre>\n\n\n\n<p>I also renamed the WS heading to reflect the value in MB as an [INT]. And while I was at it, I realized the CPU property is really a number of seconds, so I'll display it as a timespan.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">@{Name = \"CPU\"; Expression = { New-TimeSpan -Seconds $_.cpu } }<\/code><\/pre>\n\n\n\n<p>With this array loaded into my PowerShell session, I can run a command like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-Process | Where-Object WS -ge 100MB | Format-Table -Property $props -AutoSize<\/code><\/pre>\n\n\n\n<p>I added some filtering to make the screen shot easier to read.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"582\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi-1024x582.png\" alt=\"\" class=\"wp-image-7775\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi-1024x582.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi-300x170.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi-768x436.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi-850x483.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi.png 1348w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now for the fun part.<\/p>\n\n\n\n<p>I don't want to have to type all of that code for the custom properties. One thing I <em>can<\/em> do is create a custom table view with a name like <strong>WS<\/strong>. Custom formatting is done with a .ps1xml file. Yes. XML. But I made it an easy process and last week I made it even easier.<\/p>\n\n\n\n<p>The PSScriptTools module, which you can download from the PowerShell Gallery, has a command called <a href=\"https:\/\/github.com\/jdhitsolutions\/PSScriptTools\/blob\/master\/docs\/New-PSFormatXML.md\" target=\"_blank\" rel=\"noreferrer noopener\">New-PSFormatXML<\/a>. The premise is that you pipe a sample object to the command, specifying what type of custom formatting you want, including properties, and it will create the .ps1xml file for you. Last week, I added the ability to support scriptblocks which will automatically create the ScriptBlock tags in the file. In previous versions, you had to manually create them. With the PSScriptTools module installed, I can run a command like this to generate a file, using my previously defined array of custom properties.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-Process -Id $pid | New-PSFormatXML -Properties $props -ViewName WS -FormatType Table -Path c:\\scripts\\wsprocess.format.ps1xml -Passthru<\/code><\/pre>\n\n\n\n<p>The function only needs a single object. By the way, if you run this command in VSCode and use the -Passthru parameter, the new .ps1xml file will automatically be opened. Here's my result.<\/p>\n\n\n\n<pre title=\"wsprocess.format.ps1xml\" class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;!--\nFormat type data generated 10\/11\/2020 13:02:12 by PROSPERO\\Jeff\nThis file was created using the New-PSFormatXML command that is part\nof the PSScriptTools module.\nhttps:\/\/github.com\/jdhitsolutions\/PSScriptTools\n-->\n&lt;Configuration>\n  &lt;ViewDefinitions>\n    &lt;View>\n      &lt;!--Created 10\/11\/2020 13:02:12 by PROSPERO\\Jeff-->\n      &lt;Name>WS&lt;\/Name>\n      &lt;ViewSelectedBy>\n        &lt;TypeName>System.Diagnostics.Process&lt;\/TypeName>\n      &lt;\/ViewSelectedBy>\n      &lt;TableControl>\n        &lt;!--Delete the AutoSize node if you want to use the defined widths.-->\n        &lt;AutoSize \/>\n        &lt;TableHeaders>\n          &lt;TableColumnHeader>\n            &lt;Label>Handles&lt;\/Label>\n            &lt;Width>10&lt;\/Width>\n            &lt;Alignment>right&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>NPM(K)&lt;\/Label>\n            &lt;Width>20&lt;\/Width>\n            &lt;Alignment>right&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>PM(K)&lt;\/Label>\n            &lt;Width>19&lt;\/Width>\n            &lt;Alignment>right&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>WS(M)&lt;\/Label>\n            &lt;Width>212&lt;\/Width>\n            &lt;Alignment>right&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>CPU&lt;\/Label>\n            &lt;Width>31&lt;\/Width>\n            &lt;Alignment>center&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>Id&lt;\/Label>\n            &lt;Width>8&lt;\/Width>\n            &lt;Alignment>right&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>ProcessName&lt;\/Label>\n            &lt;Width>210&lt;\/Width>\n            &lt;Alignment>left&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n        &lt;\/TableHeaders>\n        &lt;TableRowEntries>\n          &lt;TableRowEntry>\n            &lt;TableColumnItems>\n              &lt;TableColumnItem>\n                &lt;PropertyName>Handles&lt;\/PropertyName>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;ScriptBlock>[int]($_.npm\/1kb)&lt;\/ScriptBlock>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;ScriptBlock>[int]($_.pm\/1kb)&lt;\/ScriptBlock>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;ScriptBlock>\n                  if ($_.ws -ge 500MB) {\n                      \"$([char]0x1b)[91m$([int]($_.ws\/1mb))$([char]0x1b)[0m\"\n                  }\n                  elseif ($_.ws -ge 250MB) {\n                      \"$([char]0x1b)[93m$([int]($_.ws\/1mb))$([char]0x1b)[0m\"\n                  }\n                  else {\n                      [int]($_.ws\/1mb)\n                  }\n                &lt;\/ScriptBlock>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;ScriptBlock>New-Timespan -Seconds $_.cpu&lt;\/ScriptBlock>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;PropertyName>Id&lt;\/PropertyName>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;ScriptBlock>\n                  if ($_.ws -ge 500MB) {\n                      \"$([char]0x1b)[1;91m$($_.processname)$([char]0x1b)[0m\"\n                  }\n                  elseif ($_.ws -ge 250MB) {\n                      \"$([char]0x1b)[1;93m$($_.processname)$([char]0x1b)[0m\"\n                  }\n                  else {\n                      $_.processname\n                  }\n                &lt;\/ScriptBlock>\n              &lt;\/TableColumnItem>\n            &lt;\/TableColumnItems>\n          &lt;\/TableRowEntry>\n        &lt;\/TableRowEntries>\n      &lt;\/TableControl>\n    &lt;\/View>\n  &lt;\/ViewDefinitions>\n&lt;\/Configuration><\/code><\/pre>\n\n\n\n<p>The .ps1xml file defaults to auto-sizing, which is fine with me. All that I have to do is load the file into my PowerShell session.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Update-FormatData C:\\scripts\\wsprocess.format.ps1xml<\/code><\/pre>\n\n\n\n<p>This file has no effect if I simply run Get-Process. But if I want to use it, all I need to do is specify the view name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-Process | Where-Object WS -ge 100MB | Format-Table -View ws<\/code><\/pre>\n\n\n\n<p>Again, I added some filtering for the sake of the demo.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"582\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ws-1024x582.png\" alt=\"\" class=\"wp-image-7777\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ws-1024x582.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ws-300x170.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ws-768x436.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ws-850x483.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ws.png 1348w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>If I want this to always be available, I can put the Update-FormatData expression into my PowerShell profile script. And as a reminder, when you pipe to one of the format cmdlets, you're telling PowerShell all you want is something pretty to look at. You can't pipe again to a command Sort-Object or Export-CSV. All you can do is pipe the output to Out-File or Out-Printer.<\/p>\n\n\n\n<p>Now I have PowerShell doing my work for me. I can tell at a glance what processes are using the most memory, Heck, I could take this concept a step further and define a \"cheater\" function in my profile.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">function ws { Get-Process | Format-Table -view ws}<\/code><\/pre>\n\n\n\n<p>I'm only going to use this interactively in my console so the fact that I'm not following the verb-noun naming convention is irrelevant. <\/p>\n\n\n\n<p>I could modify the ps1xml further. Here are some things I (or you) might consider:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Remove AutoSize and adjust column widths.<\/li><li>Modify other properties like PM and format them as MB.<\/li><li>Add a property like Runtime.<\/li><li>Make my colorized view the default for Process objects.<\/li><\/ul>\n\n\n\n<p>I'd love to hear what custom formatting you came up with and what problems it solved.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the features I truly enjoy about PowerShell, is the ability to have it present information that I need in a form that I want. Here&#8217;s a good example. Running Get-Process is simple enough and the output is pretty complete. But one thing that would make it better for me, is that sometimes I&#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: Easy #PowerShell Custom Formatting","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":[350,295,534,140,623],"class_list":["post-7774","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-format","tag-format-table","tag-powershell","tag-ps1xml","tag-psscripttools"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Easy PowerShell Custom Formatting &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"See how easy it is to add custom formatting to PowerShell and how much easier it will make your work.\" \/>\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\/7774\/easy-powershell-custom-formatting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Easy PowerShell Custom Formatting &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"See how easy it is to add custom formatting to PowerShell and how much easier it will make your work.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-15T18:18:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-15T18:20:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi-1024x582.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Easy PowerShell Custom Formatting\",\"datePublished\":\"2020-10-15T18:18:34+00:00\",\"dateModified\":\"2020-10-15T18:20:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/\"},\"wordCount\":720,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/get-process-ansi-1024x582.png\",\"keywords\":[\"Format\",\"format-table\",\"PowerShell\",\"ps1xml\",\"PSScriptTools\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/\",\"name\":\"Easy PowerShell Custom Formatting &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/get-process-ansi-1024x582.png\",\"datePublished\":\"2020-10-15T18:18:34+00:00\",\"dateModified\":\"2020-10-15T18:20:52+00:00\",\"description\":\"See how easy it is to add custom formatting to PowerShell and how much easier it will make your work.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/get-process-ansi.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/get-process-ansi.png\",\"width\":1348,\"height\":766},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7774\\\/easy-powershell-custom-formatting\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Easy PowerShell Custom Formatting\"}]},{\"@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":"Easy PowerShell Custom Formatting &#8226; The Lonely Administrator","description":"See how easy it is to add custom formatting to PowerShell and how much easier it will make your work.","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\/7774\/easy-powershell-custom-formatting\/","og_locale":"en_US","og_type":"article","og_title":"Easy PowerShell Custom Formatting &#8226; The Lonely Administrator","og_description":"See how easy it is to add custom formatting to PowerShell and how much easier it will make your work.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/","og_site_name":"The Lonely Administrator","article_published_time":"2020-10-15T18:18:34+00:00","article_modified_time":"2020-10-15T18:20:52+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi-1024x582.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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Easy PowerShell Custom Formatting","datePublished":"2020-10-15T18:18:34+00:00","dateModified":"2020-10-15T18:20:52+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/"},"wordCount":720,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi-1024x582.png","keywords":["Format","format-table","PowerShell","ps1xml","PSScriptTools"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/","name":"Easy PowerShell Custom Formatting &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi-1024x582.png","datePublished":"2020-10-15T18:18:34+00:00","dateModified":"2020-10-15T18:20:52+00:00","description":"See how easy it is to add custom formatting to PowerShell and how much easier it will make your work.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-process-ansi.png","width":1348,"height":766},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7774\/easy-powershell-custom-formatting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Easy PowerShell Custom Formatting"}]},{"@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":4959,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4959\/the-power-of-custom-properties\/","url_meta":{"origin":7774,"position":0},"title":"The Power of Custom Properties","author":"Jeffery Hicks","date":"March 1, 2016","format":false,"excerpt":"The other day fellow PowerShell MVP Adam Bertram published an article about using custom properties with Select-Object. It is a good article in that it gets you thinking about PowerShell in terms of objects and not simple text. But I want to take Adam's article as a jumping off point\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/03\/image_thumb.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/03\/image_thumb.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/03\/image_thumb.png?resize=525%2C300 1.5x"},"classes":[]},{"id":6336,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6336\/building-a-powershell-process-memory-tool\/","url_meta":{"origin":7774,"position":1},"title":"Building a PowerShell Process Memory Tool","author":"Jeffery Hicks","date":"December 28, 2018","format":false,"excerpt":"This week I've been testing out a new browser, Brave, as a possible replacement for Firefox. One of the reasons I switched to Firefox from Chrome was performance and better resource utilization. Brave may now be a better choice, but that's not what this article is about. In order to\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\/2018\/12\/image_thumb-20.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/12\/image_thumb-20.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/12\/image_thumb-20.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/12\/image_thumb-20.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":6478,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/","url_meta":{"origin":7774,"position":2},"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":8798,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8798\/tell-powershell-what-you-want\/","url_meta":{"origin":7774,"position":3},"title":"Tell PowerShell What You Want","author":"Jeffery Hicks","date":"January 18, 2022","format":false,"excerpt":"I saw a question on Twitter the other day about how to include the Notes property when running the Get-VM Hyper-V cmdlet. I'm reading between the lines, but I think the desired goal was to include the Notes property. Here are a few ways you might tackle this problem. And\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\/01\/new-formatview.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/new-formatview.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/new-formatview.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/new-formatview.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":7937,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7937\/creating-powershell-property-names\/","url_meta":{"origin":7774,"position":4},"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":8143,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8143\/solving-the-powershell-memory-challenge\/","url_meta":{"origin":7774,"position":5},"title":"Solving the PowerShell Memory Challenge","author":"Jeffery Hicks","date":"February 8, 2021","format":false,"excerpt":"I hope you tried your hand at this Iron Scripter PowerShell challenge on reporting memory usage. The basic challenge was to find the total percent of working set memory that a specific process or service is using. Here's how I approached it, with my usual disclaimer that my solution is\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\/2021\/02\/get-wspct.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7774","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=7774"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7774\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}