{"id":22574420,"url":"https://github.com/kirkmunro/formatpx","last_synced_at":"2025-04-10T16:10:38.460Z","repository":{"id":24385255,"uuid":"27785067","full_name":"KirkMunro/FormatPx","owner":"KirkMunro","description":"Better Formatting in PowerShell","archived":false,"fork":false,"pushed_at":"2016-01-23T15:02:07.000Z","size":354,"stargazers_count":72,"open_issues_count":3,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-24T13:51:23.109Z","etag":null,"topics":["module","powershell","powershell-modules"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KirkMunro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-09T20:15:15.000Z","updated_at":"2024-11-28T09:44:18.000Z","dependencies_parsed_at":"2022-08-22T07:20:09.856Z","dependency_job_id":null,"html_url":"https://github.com/KirkMunro/FormatPx","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KirkMunro%2FFormatPx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KirkMunro%2FFormatPx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KirkMunro%2FFormatPx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KirkMunro%2FFormatPx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KirkMunro","download_url":"https://codeload.github.com/KirkMunro/FormatPx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248250796,"owners_count":21072683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["module","powershell","powershell-modules"],"created_at":"2024-12-08T03:05:54.627Z","updated_at":"2025-04-10T16:10:38.445Z","avatar_url":"https://github.com/KirkMunro.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿## FormatPx\n\n### Overview\n\nFormatPx separates the formatting layer from the data layer in PowerShell. By\ndefault, PowerShell's native Format-* cmdlets convert data objects into format\nobjects when are then rendered in the console. This reduces the usefulness of\nthe Format-* cmdlets, making it harder to work with formatting in PowerShell.\nFormatPx fixes this problem by attaching format data to objects rather than\nreplacing objects with format data. This allows for data processing to\ncontinue beyond Format-* cmdlets, without losing any of the capabilities of\nthe formatting engine in PowerShell.\n\n### Minimum requirements\n\n- PowerShell 3.0\n- SnippetPx module\n\n### License and Copyright\n\nCopyright 2016 Kirk Munro\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n### Installing the FormatPx module\n\nFormatPx is dependent on the SnippetPx module. You can download and install the\nlatest versions of FormatPx and SnippetPx using any of the following methods:\n\n#### PowerShellGet\n\nIf you don't know what PowerShellGet is, it's the way of the future for PowerShell\npackage management. If you're curious to find out more, you should read this:\n\u003ca href=\"http://blogs.msdn.com/b/mvpawardprogram/archive/2014/10/06/package-management-for-powershell-modules-with-powershellget.aspx\" target=\"_blank\"\u003ePackage Management for PowerShell Modules with PowerShellGet\u003c/a\u003e\n\nNote that these commands require that you have the PowerShellGet module installed\non the system where they are invoked.\n\n```powershell\n# If you don’t have FormatPx installed already and you want to install it for all\n# all users (recommended, requires elevation)\nInstall-Module FormatPx,SnippetPx\n\n# If you don't have FormatPx installed already and you want to install it for the\n# current user only\nInstall-Module FormatPx,SnippetPx -Scope CurrentUser\n\n# If you have FormatPx installed and you want to update it\nUpdate-Module\n```\n\n#### PowerShell 3.0 or Later\n\nTo install from PowerShell 3.0 or later, open a native PowerShell console (not ISE,\nunless you want it to take longer), and invoke one of the following commands:\n\n```powershell\n# If you want to install FormatPx for all users or update a version already installed\n# (recommended, requires elevation for new install for all users)\n\u0026 ([scriptblock]::Create((iwr -uri http://tinyurl.com/Install-GitHubHostedModule).Content)) -ModuleName FormatPx,SnippetPx\n\n# If you want to install FormatPx for the current user\n\u0026 ([scriptblock]::Create((iwr -uri http://tinyurl.com/Install-GitHubHostedModule).Content)) -ModuleName FormatPx,SnippetPx -Scope CurrentUser\n```\n\n### Loading the FormatPx module\n\nWhen it comes to module auto-loading, FormatPx does not function the same way\nthat other modules do, because the proxy commands it includes are part of core\nPowerShell modules that take priority during command lookup. As a result, you\nshould manually load FormatPx in order to take advantage of the improvements\nit makes to the PowerShell formatting engine by invoking the following command:\n\n```powershell\nImport-Module FormatPx\n```\n\nIf you use FormatPx on a regular basis, you can add that to your profile\nscript so that it is automatically loaded in every session.\n\nNote that if you also use the HistoryPx module, FormatPx should be imported\nbefore HistoryPx so that HistoryPx works directly with object data instead\nof format data both in the extended history table and in the automatic\noutput capture feature.\n\n### Using the FormatPx module\n\nThe FormatPx module is designed to work transparently within PowerShell. Once\nthe module is loaded in PowerShell, you can continue using Format-Table,\nFormat-List, Format-Wide and Format-Custom as normally would have before. What\nyou can also do though that you could not do before is pipe the objects that\nwere passed into one of the core Format-* cmdlets into other cmdlets after the\nFormat-* cmdlet. For example, consider the following command and its output:\n\n```\nPS C:\\\u003e Get-Service c* | Format-Table Name,Status -AutoSize\n\nName              Status\n----              ------\nc2wts            Stopped\nCertPropSvc      Running\nCOMSysApp        Stopped\ncphs             Stopped\nCrmSqlStartupSvc Running\nCryptSvc         Running\nCscService       Running\n```\n\nNormally after running such a command, you wouldn't be able to pipe any further\nbecause by default, Format-Table converts object data into format data. FormatPx\nchanges that, such that the format data is added to the object data instead. This\nallows you to then take further action beyond a call to a core Format-* cmdlet,\nlike this:\n\n```powershell\nPS C:\\\u003e Get-Service c* | Format-Table Name,Status -AutoSize | Stop-Service -WhatIf\nWhat if: Performing the operation \"Stop-Service\" on target \"Claims to Windows Token Service (c2wts)\".\nWhat if: Performing the operation \"Stop-Service\" on target \"Certificate Propagation (CertPropSvc)\".\nWhat if: Performing the operation \"Stop-Service\" on target \"COM+ System Application (COMSysApp)\".\nWhat if: Performing the operation \"Stop-Service\" on target \"Intel(R) Content Protection HECI Service (cphs)\".\nWhat if: Performing the operation \"Stop-Service\" on target \"SQL Server (CRM) On-Demand Shutdown (CrmSqlStartupSvc)\".\nWhat if: Performing the operation \"Stop-Service\" on target \"Cryptographic Services (CryptSvc)\".\nWhat if: Performing the operation \"Stop-Service\" on target \"Offline Files (CscService)\".\n```\n\nThis separation of the formatting layer from the data processing layer in\nPowerShell allows you to use Format-Table, Format-List, Format-Wide, or\nFormat-Custom inside of a function to define a rich format layout for the data\nreturned by your function without compromising the ability to work with the\nobject data in PowerShell. For example, consider this function:\n\n```\nPS C:\\\u003e function Get-SystemInfo {\n    [CmdletBinding()]\n    [OutputType('System.Info')]\n    param()\n    $computerSystem = Get-CimInstance Win32_ComputerSystem\n    $operatingSystem = Get-CimInstance Win32_OperatingSystem\n    $systemInfo = [pscustomobject]@{\n        PSTypeName = 'System.Info'\n        ComputerName = $computerSystem.Name\n        DomainName = $computerSystem.Domain\n        Manufacturer = $computerSystem.Manufacturer\n        Model = $computerSystem.Model\n        NumProcessors = $computerSystem.NumberOfProcessors\n        OperatingSystem = $operatingSystem.Caption \n    }\n    $systemInfo | Format-Table ComputerName,OperatingSystem -AutoSize -PersistWhenOutput\n}\n```\n\nIf you run that function, you will get back a custom object of type System.Info\nalong with a well defined default format for that custom object type. This sort\nof thing would have required using complicated format ps1xml files in the past,\nbut now you can apply custom formatting much easier by simply using Format-*\ncmdlets!\n\nIn addition to the separation of format data from object data, FormatPx also\nmodifies the default PowerShell behaviour that would prevent certain types of\nobjects from being displayed in the format that you desired without using the\n-Force parameter. For example, consider this snippet:\n\n```\nPS C:\\\u003e $sb = {'Script block'}\nPS C:\\\u003e $sb | Format-List\n```\n\nWithout FormatPx, you would simply see this displayed to your console:\n\n```\n'ScriptBlock'\n```\n\nWith FormatPx, however, you now see the format that you asked for, without having\nto be redundant about how you request it by using -Force. It would look like this:\n\n```\nAttributes      : {}\nFile            :\nIsFilter        : False\nIsConfiguration : False\nModule          :\nStartPosition   : System.Management.Automation.PSToken\nDebuggerHidden  : False\nAst             : {'ScriptBlock'}\n```\n\nThis trick also works for errors in the $error variable, exceptions in the Exception\nproperty on ErrorRecord objects, and other object types that are configured by\ndefault to hide details that really are important enough to be able to see without\nusing -Force.\n\nThere are a few technical details that you should know about if you want to give\nthis module a spin in your environment.\n\nFirst, when you are defining a default format, whether it be a table, list, wide\ntable, or a custom format, you should use the new -PersistWhenOutput switch\nparameter. That parameter instructs PowerShell to keep the format data attached\nto the objects that are output even after the format data has been rendered in\nthe current console. By default, format data is removed after it is rendered to\nthe console, allowing you to continue using Format-* cmdlets as you would have\nin the past.\n\nSecond, you can define (or override) the default format for any object by simply\npassing it to the format cmdlet of your choice and applying the -PersistWhenOutput\nswitch.\n\nThird, since format data is now simply added to an object, you can apply multiple\nformat cmdlets to a single set of data in one pipeline. You would likely only do\nthis if the format defined inside of a function was not what you wanted, but you\ncan mix and match format calls however you choose. For example:\n\n```\nPS C:\\\u003e Get-Service c* | ft | fw | fc | fl\n```\n\nLastly, there is a new format cmdlet in this module called Format-Default. The\nFormat-Default cmdlet allows you to take anything that has format data associated\nwith it and instruct PowerShell to render it using the default format instead,\nwhatever that may be. You can also invoke Format-Default using the convenient fd\nalias as well.\n\nHere's a short video demonstrating the FormatPx module in action:\n[![Better PowerShell formatting with FormatPx](http://img.youtube.com/vi/OpXNeg_2cfM/0.jpg)](http://www.youtube.com/watch?v=OpXNeg_2cfM)\n\nThat should give you a good idea of what is included in this module. If you have\nideas on what else you might like to see related to formatting in PowerShell, please\nlet me know on the GitHub page.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirkmunro%2Fformatpx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkirkmunro%2Fformatpx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirkmunro%2Fformatpx/lists"}