{"id":18048088,"url":"https://github.com/startautomating/ezout","last_synced_at":"2025-04-30T21:42:15.927Z","repository":{"id":16690107,"uuid":"19446553","full_name":"StartAutomating/EZOut","owner":"StartAutomating","description":"EZOut is a PowerShell module to help take the pain out of writing format and types XML","archived":false,"fork":false,"pushed_at":"2024-09-27T00:40:35.000Z","size":23573,"stargazers_count":68,"open_issues_count":49,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-22T02:55:21.694Z","etag":null,"topics":["formatting-output","powershell","powershell-module"],"latest_commit_sha":null,"homepage":"https://ezout.start-automating.com","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StartAutomating.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"contributing.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"Security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["StartAutomating"]}},"created_at":"2014-05-05T06:39:32.000Z","updated_at":"2025-04-21T23:19:18.000Z","dependencies_parsed_at":"2024-10-30T20:21:40.203Z","dependency_job_id":null,"html_url":"https://github.com/StartAutomating/EZOut","commit_stats":{"total_commits":661,"total_committers":2,"mean_commits":330.5,"dds":"0.40090771558245086","last_synced_commit":"1a1a7dda8f925e688e42d9de1c5138522c34f596"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FEZOut","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FEZOut/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FEZOut/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FEZOut/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StartAutomating","download_url":"https://codeload.github.com/StartAutomating/EZOut/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251788883,"owners_count":21644075,"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":["formatting-output","powershell","powershell-module"],"created_at":"2024-10-30T20:11:33.687Z","updated_at":"2025-04-30T21:42:15.872Z","avatar_url":"https://github.com/StartAutomating.png","language":"PowerShell","readme":"\u003cdiv align='center'\u003e\r\n\u003cimg src='Assets/EZOut.svg' /\u003e\r\n\u003ca href='https://www.powershellgallery.com/packages/EZOut/'\u003e\r\n\u003cimg src='https://img.shields.io/powershellgallery/dt/EZOut' /\u003e\r\n\u003c/a\u003e\r\n\u003c/div\u003e\r\n\r\n### Installing EZOut\r\n\r\nYou can install EZOut from the PowerShell Gallery.  Simply:\r\n~~~PowerShell\r\nInstall-Module EZOut -Scope CurrentUser\r\n~~~\r\n\r\n### Using EZOut as a GitHub Action:\r\n\r\nYou can use EZOut as a GitHub Action to automatically build your formatting and types files on every checkin.\r\n\r\n~~~yaml\r\n - name: Build Formatting and Types   \r\n   uses: StartAutomating/EZOut@master\r\n   id: BuildEZOut\r\n~~~\r\n\r\n### Understanding PowerShell Formatting\r\n\r\nUnlike many languages, PowerShell has a formatting engine built into the box.  \r\nYou can define one or more \"Views\" that will change how PowerShell will display an object.\r\nThese views are stored in a .format.ps1xml file, and loaded in a module manifest with the setting 'FormatsToProcess:'\r\nThis is an example of a minimal module with just a format file:\r\n\r\n~~~PowerShell\r\n@{\r\n    ModuleVersion = 0.1\r\n    FormatsToProcess = 'My.Format.ps1xml'\r\n}\r\n~~~\r\n\r\nPowerShell formatting primarily supports three different types of views for any typename:\r\n* A Table View\r\n* A List View \r\n* A Custom View\r\n\r\n\r\nTable and List Views are fairly straightforward:  You select some properties to display, and you get a table.\r\n\r\nCustom Views, as the name implies, are anything you'd like them to be.  Custom views can also be defined as a control, which can be referenced in other custom views.\r\n\r\nYou most likely see complex custom controls everyday:  The most complex formatter built into PowerShell is the formatter for Help.\r\n\r\nObjects in PowerShell are formatted according to their .pstypenames property.  If you're creating a normal .NET object, this property will be the inheritance hierarchy of the class.  For instance:\r\n\r\n~~~PowerShell\r\n# This will have three typenames:\r\n# System.Management.Automation.CmdletInfo, System.Management.Automation.CommandInfo, and System.Object\r\n# When you see the output of Get-Command, you're seeing the formatter for System.Management.CommandInfo\r\nGet-Command Get-Command | Select-Object -ExpandProperty PSTypenames\r\n~~~\r\nYou can switch out the typenames of any given object by manipulating the typenames property\r\n\r\n~~~PowerShell\r\n$helpCommand = Get-Command Get-Help  # Get the command Get-Help\r\n$helpCommand.pstypenames.clear()     # Clear it's typenames\r\n$helpCommand                         # When we echo it now, it will be unformatted.\r\n\r\n$helpCommand.pstypenames.add('System.Management.Automation.CommandInfo') # This adds the formatting back\r\n~~~\r\n\r\nYou can also define a single typename when creating an object from a hashtable.\r\nAs the typename in this example implies, you can have a valid typename in PowerShell that could never exist as a real type in .NET.\r\n\r\n~~~PowerShell\r\n[PSCustomObject]@{PSTypeName='http://My/TypeName/IsNot/A/Valid/.NET#Typename';N=1}\r\n~~~\r\n\r\n### Using EZOut\r\n\r\n#### Using EZOut to build your formatting:\r\n\r\nSwitch to your module directory, then run:\r\n\r\n~~~PowerShell\r\nWrite-EZFormatFile | Set-Content .\\MyModule.EzFormat.ps1 -Encoding UTF8 # Replace MyModule with the name of your module\r\n~~~\r\n\r\nThis file will contain the scaffolding to write your formatters.  Whenever you run this file, MyModule.format.ps1xml and MyModule.types.ps1xml will be regenerated.\r\n\r\nFor a working example of this, check out EZOut's own [.ezformat.ps1](/EZOut.ezformat.ps1) file.\r\n\r\nWe can declare formatters directly in the .ezformat.ps1 file, or within a /Formatting or /Views directory, in a file named .(format|view).(ps1|xml)\r\n\r\nIn the examples below, we will be piping to Out-FormatData (to combine all of the formatting) and Add-FormatData (to register it in a temporary module). \r\n\r\n##### Writing Table Views\r\n\r\nTable views are the most commonly used view in PowerShell, and the default of Write-FormatView\r\n\r\n~~~PowerShell\r\nWrite-FormatView -TypeName APerson -Property FirstName, LastName, Age |\r\n    Out-FormatData |\r\n    Add-FormatData\r\n        \r\n[PSCustomObject]@{PSTypeName='APerson';FirstName='James';LastName='Brundage';Age=41}\r\n~~~\r\n    \r\nWe can specify a -Width for each column.  Using a negative number will make the column right-aligned:\r\n\r\n~~~PowerShell\r\nWrite-FormatView -TypeName APerson -Property FirstName, LastName, Age -Width -20, 30, 5 |\r\n    Out-FormatData |\r\n    Add-FormatData\r\n        \r\n[PSCustomObject]@{PSTypeName='APerson';FirstName='James';LastName='Brundage';Age=41}\r\n~~~\r\n\r\nWe can also specify alignment using -AlignProperty, or use -FormatProperty to determine how a property is displayed, and even -HideHeader.\r\n\r\n~~~PowerShell\r\nWrite-FormatView -TypeName MenuItem -Property Name, Price -AlignProperty @{Name='Center';Price='Center'} -FormatProperty @{\r\n    Price = '{0:c}'\r\n} -Width 40, 40 -HideHeader |\r\n    Out-FormatData |\r\n    Add-FormatData\r\n\r\n[PSCustomObject]@{PSTypeName='MenuItem';Name='Coffee';Price=2.99}    \r\n~~~\r\n\r\nWe can define a -VirtualProperty, which will display as a column but does not really exist.\r\nAlso, in most hosts, we can conditionally -ColorProperty or -ColorRow:\r\n~~~PowerShell\r\nWrite-FormatView -Property Number, IsEven, IsOdd -AutoSize -ColorRow {\r\n    if ($_.N % 2) { \"#ff0000\"} else {\"#0f0\"}\r\n} -VirtualProperty @{\r\n    IsEven = { -not ($_.N % 2)}\r\n    IsOdd = { ($_.N % 2) -as [bool] }\r\n} -AliasProperty @{\r\n    Number = 'N'\r\n} -TypeName N |\r\n    Out-FormatData|\r\n    Add-FormatData\r\n        \r\n1..5 | Foreach-Object { [PSCustomObject]@{PSTypeName='N';N=$_} }           \r\n~~~\r\n#### Using EZOut Interactively\r\n\r\nAs shown in the examples above, we can use EZOut to add formatting interactively, by piping to Add-FormatData.\r\n\r\n~~~PowerShell\r\nImport-Module EZOut\r\n\r\nWrite-FormatView -TypeName 'System.TimeZoneInfo' -Property Id, DisplayName -AlignProperty @{\r\n    ID = 'Right'\r\n    DisplayName = 'Left'\r\n} -AutoSize |  \r\n        Out-FormatData |\r\n        Push-FormatData\r\n    \r\nGet-TimeZone\r\n~~~\r\n\r\n### Creating Types with EZOut\r\n\r\nEZOut can also create types files.\r\n\r\nYou can use [Write-TypeView](docs/Write-TypeView.md) to write a segment of a types.ps1xml directly.\r\n\r\nYou can also use [Import-TypeView](docs/Import-TypeView.md) to import an entire directory tree into a types.ps1xml file.\r\n\r\n#### Advanced EZOut examples\r\n\r\nDue to EZOut being a build tool, we want to impact your runspace as little as possible.\r\n\r\nTherefore, advanced EZOut formatting examples have been moved into a new module: [Posh](https://github.com/StartAutomating/Posh)\r\n\r\n","funding_links":["https://github.com/sponsors/StartAutomating"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstartautomating%2Fezout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstartautomating%2Fezout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstartautomating%2Fezout/lists"}