├── .gitignore ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SECURITY.md ├── azure-pipelines.yml └── src └── FormatMarkdownTable ├── FormatMarkdownTable.psd1 └── FormatMarkdownTable.psm1 /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | 352 | # Test files 353 | test/* -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "powershell.codeFormatting.addWhitespaceAroundPipe": true 3 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FormatMarkdownTable PowerShell Module 2 | 3 | FormatMarkdownTable is a PowerShell module which contains Format-MarkdownTableListStyle cmdlet and Format-MarkdownTableTableStyle cmdlet. 4 | 5 | ## Installing the FormatMarkdownTable PowerShell Module 6 | 7 | The module is published on the PowerShell Gallery. 8 | 9 | ```powershell 10 | Install-Module FormatMarkdownTable 11 | ``` 12 | 13 | ## Example 14 | 15 | ```powershell 16 | Get-ChildItem c:\ | Format-MarkdownTableListStyle Name, LastWriteTime, Mode 17 | ``` 18 | 19 | This example returns a summary of the child items in C drive, and markdown text will be copied to the clipboard. Each property is displayed on a separate row. 20 | 21 | ```powershell 22 | Get-ChildItem c:\ | Format-MarkdownTableTableStyle Name, LastWriteTime, Mode 23 | ``` 24 | 25 | This example returns a summary of the child items in C drive, and markdown text will be copied to the clipboard. Each property is displayed on a separate col. 26 | 27 | ## Alias 28 | 29 | You can also refer to Format-MarkdownTableListStyle by its built-in alias, FML. 30 | 31 | You can also refer to Format-MarkdownTableTableStyle by its built-in alias, FMT. 32 | 33 | If FML and FMT are not recognized, try `Import-Module FormatMarkdownTable` once to load the module explicitly. 34 | 35 | ## Switch 36 | 37 | ```powershell 38 | Get-ChildItem c:\ | fml Name, LastWriteTime, Mode -HideStandardOutput 39 | ``` 40 | 41 | HideStandardOutput indicates that the cmdlet hides the standard output. 42 | 43 | ```powershell 44 | Get-ChildItem c:\ | fml Name, LastWriteTime, Mode -HideStandardOutput -ShowMarkdown 45 | ``` 46 | 47 | ShowMarkdown indicates that the cmdlet outputs the markdown text to the console. 48 | 49 | ```powershell 50 | Get-ChildItem c:\ | fml Name, LastWriteTime, Mode -HideStandardOutput -ShowMarkdown -DoNotCopyToClipboard 51 | ``` 52 | 53 | DoNotCopyToClipboard indicates the the cmdlet does not copy the markdown text to the clipboard. 54 | 55 | ## Contributing 56 | 57 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 58 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 59 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. 60 | 61 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide 62 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions 63 | provided by the bot. You will only need to do this once across all repos using our CLA. 64 | 65 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 66 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 67 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 68 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)) of a security vulnerability, please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Starter pipeline 2 | # Start with a minimal pipeline that you can customize to build and deploy your code. 3 | # Add steps that build, run tests, deploy, and more: 4 | # https://aka.ms/yaml 5 | 6 | trigger: 7 | - master 8 | 9 | pool: 10 | vmImage: 'ubuntu-latest' 11 | 12 | steps: 13 | 14 | - task: CopyFiles@2 15 | inputs: 16 | SourceFolder: 'src/FormatMarkdownTable' 17 | Contents: | 18 | *.psm1 19 | *.psd1 20 | TargetFolder: '$(Build.ArtifactStagingDirectory)' 21 | OverWrite: true 22 | 23 | - task: PublishBuildArtifacts@1 24 | inputs: 25 | PathtoPublish: '$(Build.ArtifactStagingDirectory)' 26 | ArtifactName: 'FormatMarkdownTable' 27 | publishLocation: 'Container' -------------------------------------------------------------------------------- /src/FormatMarkdownTable/FormatMarkdownTable.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'FormatMarkdownTable' 3 | # 4 | # Generated by: Microsoft Corporation 5 | # 6 | # Generated on: 2/1/2020 7 | # 8 | 9 | @{ 10 | 11 | # Script module or binary module file associated with this manifest. 12 | # RootModule = '' 13 | 14 | # Version number of this module. 15 | ModuleVersion = '1.0.4' 16 | 17 | # Supported PSEditions 18 | # CompatiblePSEditions = @() 19 | 20 | # ID used to uniquely identify this module 21 | GUID = 'f5e3178a-8074-43fe-a947-9285f3ff33cf' 22 | 23 | # Author of this module 24 | Author = 'Microsoft Corporation' 25 | 26 | # Company or vendor of this module 27 | CompanyName = 'Microsoft Corporation' 28 | 29 | # Copyright statement for this module 30 | Copyright = '(c) Microsoft Corporation' 31 | 32 | # Description of the functionality provided by this module 33 | Description = 'Format PowerShell object to Markdown table' 34 | 35 | # Minimum version of the Windows PowerShell engine required by this module 36 | PowerShellVersion = '5.0' 37 | 38 | # Name of the Windows PowerShell host required by this module 39 | # PowerShellHostName = '' 40 | 41 | # Minimum version of the Windows PowerShell host required by this module 42 | # PowerShellHostVersion = '' 43 | 44 | # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 45 | # DotNetFrameworkVersion = '' 46 | 47 | # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 48 | CLRVersion = '4.0' 49 | 50 | # Processor architecture (None, X86, Amd64) required by this module 51 | # ProcessorArchitecture = '' 52 | 53 | # Modules that must be imported into the global environment prior to importing this module 54 | # RequiredModules = @() 55 | 56 | # Assemblies that must be loaded prior to importing this module 57 | # RequiredAssemblies = @() 58 | 59 | # Script files (.ps1) that are run in the caller's environment prior to importing this module. 60 | # ScriptsToProcess = @() 61 | 62 | # Type files (.ps1xml) to be loaded when importing this module 63 | # TypesToProcess = @() 64 | 65 | # Format files (.ps1xml) to be loaded when importing this module 66 | # FormatsToProcess = @() 67 | 68 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 69 | NestedModules = @('FormatMarkdownTable.psm1') 70 | 71 | # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. 72 | FunctionsToExport = 'Format-MarkdownTableListStyle', 'Format-MarkdownTableTableStyle' 73 | 74 | # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. 75 | CmdletsToExport = '*' 76 | 77 | # Variables to export from this module 78 | VariablesToExport = '*' 79 | 80 | # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. 81 | AliasesToExport = '*' 82 | 83 | # DSC resources to export from this module 84 | # DscResourcesToExport = @() 85 | 86 | # List of all modules packaged with this module 87 | # ModuleList = @() 88 | 89 | # List of all files packaged with this module 90 | # FileList = @() 91 | 92 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. 93 | PrivateData = @{ 94 | 95 | PSData = @{ 96 | 97 | # Tags applied to this module. These help with module discovery in online galleries. 98 | # Tags = @() 99 | 100 | # A URL to the license for this module. 101 | LicenseUri = 'https://github.com/microsoft/FormatPowerShellToMarkdownTable/blob/master/LICENSE' 102 | 103 | # A URL to the main website for this project. 104 | ProjectUri = 'https://github.com/microsoft/FormatPowerShellToMarkdownTable' 105 | 106 | # A URL to an icon representing this module. 107 | # IconUri = '' 108 | 109 | # ReleaseNotes of this module 110 | # ReleaseNotes = '' 111 | 112 | } # End of PSData hashtable 113 | 114 | } # End of PrivateData hashtable 115 | 116 | # HelpInfo URI of this module 117 | # HelpInfoURI = '' 118 | 119 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. 120 | # DefaultCommandPrefix = '' 121 | 122 | } 123 | 124 | -------------------------------------------------------------------------------- /src/FormatMarkdownTable/FormatMarkdownTable.psm1: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | # https://github.com/microsoft/FormatPowerShellToMarkdownTable 4 | 5 | <# 6 | .SYNOPSIS 7 | Formats the output as a Format-List style markdown table. 8 | 9 | .DESCRIPTION 10 | The Format-MarkdownTableListStyle cmdlet formats the output of a command as a Format-List style markdown table which each property is displayed on a separate col. 11 | 12 | Markdown text will be copied to the clipboard. 13 | 14 | .PARAMETER InputObject 15 | Specifies the objects to be formatted. Enter a variable that contains the objects or type a command or expression that gets the objects. 16 | 17 | .PARAMETER HideStandardOutput 18 | Indicates that the cmdlet hides the standard Format-List style output. 19 | 20 | .PARAMETER ShowMarkdown 21 | Indicates that the cmdlet outputs the markdown text to the console. 22 | 23 | .PARAMETER DoNotCopyToClipboard 24 | Indicates the the cmdlet does not copy the markdown text to the clipboard. 25 | 26 | .PARAMETER Property 27 | Specifies the object properties that appear in the display and the order in which they appear. Wildcards are permitted. 28 | 29 | If you omit this parameter, the properties that appear in the display depend on the object being displayed. The parameter name "Property" is optional. 30 | 31 | .EXAMPLE 32 | Get-Process notepad | Format-MarkdownTableListStyle 33 | 34 | .EXAMPLE 35 | Get-Process notepad | fml Name,Path 36 | 37 | .NOTES 38 | You can also refer to Format-MarkdownTableListStyle by its built-in alias, FML. 39 | #># 40 | function Format-MarkdownTableListStyle { 41 | [CmdletBinding()] 42 | [Alias("fml")] 43 | 44 | param ( 45 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 46 | [object] 47 | $InputObject, 48 | 49 | [Parameter(Mandatory = $false, ValueFromPipeline = $false)] 50 | [switch] 51 | $HideStandardOutput, 52 | 53 | [Parameter(Mandatory = $false, ValueFromPipeline = $false)] 54 | [switch] 55 | $ShowMarkdown, 56 | 57 | [Parameter(Mandatory = $false, ValueFromPipeline = $false)] 58 | [switch] 59 | $DoNotCopyToClipboard, 60 | 61 | [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline = $false)] 62 | [string[]] 63 | $Property = @() 64 | ) 65 | 66 | Begin { 67 | if ($null -ne $InputObject -and $InputObject.GetType().BaseType -eq [System.Array]) { 68 | Write-Error "InputObject must not be System.Array. Don't use InputObject, but use the pipeline to pass the array object." 69 | $NeedToReturn = $true 70 | return 71 | } 72 | 73 | $LastCommandLine = (Get-PSCallStack)[1].Position.Text 74 | 75 | $Result = "" 76 | 77 | $TempOutputList = New-Object System.Collections.Generic.List[object] 78 | } 79 | 80 | Process { 81 | if ($NeedToReturn) { return } 82 | 83 | $CurrentObject = $null 84 | 85 | if (($Property.Length -eq 0) -or ($Property.Length -eq 1 -and $Property[0] -eq "")) { 86 | $Property = @("*") 87 | } 88 | 89 | if ($_ -eq $null) { 90 | $CurrentObject = $InputObject 91 | } 92 | else { 93 | $CurrentObject = $_ 94 | } 95 | 96 | if ($CurrentObject.GetType().Name.ToLower() -eq "string") { 97 | # CurrentObject is a simple String object 98 | # Display like a FT style 99 | 100 | $Output = "" 101 | 102 | if ($Result -eq "") { 103 | $Output += "||`r`n" 104 | $Output += "|:--|`r`n" 105 | } 106 | 107 | $Output += "|$(EscapeMarkdown($CurrentObject))|`r`n" 108 | 109 | $Result += $Output 110 | 111 | $TempOutputList.Add($CurrentObject) 112 | } 113 | else { 114 | $CurrentObject = $CurrentObject | Select-Object -Property $Property -ErrorAction SilentlyContinue 115 | $Props = $CurrentObject | Get-Member -Name $Property -MemberType Property, NoteProperty 116 | 117 | $Output = "|Property|Value|`r`n" 118 | $Output += "|:--|:--|`r`n" 119 | 120 | $TempOutput = New-Object PSCustomObject 121 | 122 | foreach ($Prop in $Props) { 123 | $EscapedPropName = EscapeMarkdown($Prop.Name) 124 | $EscapedPropValue = EscapeMarkdown($CurrentObject.($($Prop.Name))) 125 | $Output += "|$EscapedPropName|$EscapedPropValue`r`n" 126 | $TempOutput | Add-Member -MemberType NoteProperty $Prop.Name -Value $CurrentObject.($($Prop.Name)) -Force 127 | } 128 | 129 | $Output += "`r`n" 130 | 131 | $Result += $Output 132 | 133 | $TempOutputList.Add($TempOutput) 134 | } 135 | } 136 | 137 | End { 138 | if ($NeedToReturn) { return } 139 | 140 | $ResultForConsole = $Result 141 | $Result = "**" + (EscapeMarkdown($LastCommandLine)) + "**`r`n`r`n" + $Result 142 | 143 | if ($HideStandardOutput.IsPresent -eq $false) { 144 | $TempOutputList | Format-List * 145 | } 146 | 147 | if ($ShowMarkdown.IsPresent) { 148 | Write-Output $ResultForConsole 149 | } 150 | 151 | if ($DoNotCopyToClipboard.IsPresent -eq $false) { 152 | Set-Clipboard $Result 153 | Write-Warning "Markdown text has been copied to the clipboard." 154 | } 155 | } 156 | } 157 | 158 | <# 159 | .SYNOPSIS 160 | Formats the output as a Format-Table style markdown table. 161 | 162 | .DESCRIPTION 163 | The Format-MarkdownTableTableStyle cmdlet formats the output of a command as a Format-Table style markdown table which each property is displayed on a separate row. 164 | 165 | Markdown text will be copied to the clipboard. 166 | 167 | .PARAMETER InputObject 168 | Specifies the objects to be formatted. Enter a variable that contains the objects or type a command or expression that gets the objects. 169 | 170 | .PARAMETER HideStandardOutput 171 | Indicates that the cmdlet hides the standard Format-Table style output. 172 | 173 | .PARAMETER ShowMarkdown 174 | Indicates that the cmdlet outputs the markdown text to the console. 175 | 176 | .PARAMETER DoNotCopyToClipboard 177 | Indicates the the cmdlet does not copy the markdown text to the clipboard. 178 | 179 | .PARAMETER Property 180 | Specifies the object properties that appear in the display and the order in which they appear. Wildcards are permitted. 181 | 182 | If you omit this parameter, the properties that appear in the display depend on the object being displayed. The parameter name "Property" is optional. 183 | 184 | .EXAMPLE 185 | Get-Process notepad | Format-MarkdownTableTableStyle 186 | 187 | .EXAMPLE 188 | Get-Process notepad | fmt Name,Path 189 | 190 | .NOTES 191 | You can also refer to Format-MarkdownTableTableStyle by its built-in alias, FMT. 192 | #> 193 | function Format-MarkdownTableTableStyle { 194 | [CmdletBinding()] 195 | [Alias("fmt")] 196 | 197 | param ( 198 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 199 | [object] 200 | $InputObject, 201 | 202 | [Parameter(Mandatory = $false, ValueFromPipeline = $false)] 203 | [switch] 204 | $HideStandardOutput, 205 | 206 | [Parameter(Mandatory = $false, ValueFromPipeline = $false)] 207 | [switch] 208 | $ShowMarkdown, 209 | 210 | [Parameter(Mandatory = $false, ValueFromPipeline = $false)] 211 | [switch] 212 | $DoNotCopyToClipboard, 213 | 214 | [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline = $false)] 215 | [string[]] 216 | $Property = @() 217 | ) 218 | 219 | Begin { 220 | ## Internal Function 221 | 222 | function UseAllProperty([object]$InputObject) { 223 | try { 224 | if ($null -eq $InputObject) { 225 | return $true 226 | } 227 | 228 | $DataType = ($InputObject | Get-Member)[0].TypeName 229 | 230 | if ($DataType.StartsWith("Selected.")) { 231 | return $true 232 | } 233 | elseif ($DataType.StartsWith("Deserialized.")) { 234 | $DataType = $DataType.Remove(0, 13) 235 | } 236 | 237 | $FormatData = Get-FormatData -TypeName $DataType -ErrorAction SilentlyContinue 238 | 239 | if ($null -eq $FormatData) { 240 | return $true 241 | } 242 | 243 | return $false 244 | } 245 | catch { 246 | return $true 247 | } 248 | } 249 | 250 | if ($null -ne $InputObject -and $InputObject.GetType().BaseType -eq [System.Array]) { 251 | Write-Error "InputObject must not be System.Array. Don't use InputObject, but use the pipeline to pass the array object." 252 | $NeedToReturn = $true 253 | return 254 | } 255 | 256 | $LastCommandLine = (Get-PSCallStack)[1].Position.Text 257 | 258 | $Result = "" 259 | 260 | $HeadersForFormatTableStyle = New-Object System.Collections.Generic.List[string] 261 | $ContentsForFormatTableStyle = New-Object System.Collections.Generic.List[object] 262 | 263 | $TempOutputList = New-Object System.Collections.Generic.List[object] 264 | } 265 | 266 | Process { 267 | if ($NeedToReturn) { return } 268 | 269 | $CurrentObject = $null 270 | 271 | if ($_ -eq $null) { 272 | $CurrentObject = $InputObject 273 | } 274 | else { 275 | $CurrentObject = $_ 276 | } 277 | 278 | if ($CurrentObject.GetType().Name.ToLower() -eq "string") { 279 | # CurrentObject is a simple String object 280 | $Props = @("") 281 | } 282 | elseif (($Property.Length -eq 0) -or ($Property.Length -eq 1 -and $Property[0] -eq "")) { 283 | if (UseAllProperty($CurrentObject)) { 284 | $Property = @("*") 285 | $CurrentObject = $CurrentObject | Select-Object -Property $Property 286 | $Props = $CurrentObject | Get-Member -Name $Property -MemberType Property, NoteProperty 287 | } 288 | else { 289 | $DataType = ($CurrentObject | Get-Member)[0].TypeName 290 | 291 | if ($DataType.StartsWith("Deserialized.")) { 292 | $DataType = $DataType.Remove(0, 13) 293 | } 294 | 295 | $FormatData = Get-FormatData -TypeName $DataType -ErrorAction SilentlyContinue 296 | 297 | $TempPSObject = New-Object PSCustomObject 298 | 299 | $TempHeaderList = New-Object System.Collections.Generic.List[string] 300 | 301 | if ($FormatData.FormatViewDefinition.Control.Headers) 302 | { 303 | for ($i = 0; $i -lt $FormatData.FormatViewDefinition.Control.Headers.Count; $i++) { 304 | $HeaderName = $FormatData.FormatViewDefinition.Control.Headers[$i].Label 305 | 306 | if ($null -eq $HeaderName -or $HeaderName -eq "") { 307 | $HeaderName = $FormatData.FormatViewDefinition.Control.Rows.Columns[$i].DisplayEntry.Value 308 | } 309 | 310 | $TempSelectedObject = $null 311 | 312 | if ($FormatData.FormatViewDefinition.Control.Rows.Columns[$i].DisplayEntry.ValueType -eq "ScriptBlock") { 313 | $TempSelectedObject = $CurrentObject | Select-Object @{ 314 | n = $HeaderName; 315 | e = ([scriptblock]::Create($FormatData.FormatViewDefinition.Control.Rows.Columns[$i].DisplayEntry.Value)) 316 | } 317 | } 318 | else { 319 | $PropertyName = $FormatData.FormatViewDefinition.Control.Rows.Columns[$i].DisplayEntry.Value 320 | 321 | $TempSelectedObject = $CurrentObject | Select-Object @{ 322 | n = $HeaderName; 323 | e = {$_.$($PropertyName)} 324 | } 325 | } 326 | 327 | $Value = $TempSelectedObject.$($HeaderName) 328 | $TempPSObject | Add-Member -MemberType NoteProperty $HeaderName -Value $Value 329 | $TempHeaderList.Add($HeaderName) 330 | } 331 | } 332 | else { 333 | for ($i = 0; $i -lt $FormatData.FormatViewDefinition.Control.Entries.Items.Count; $i++) { 334 | $HeaderName = $FormatData.FormatViewDefinition.Control.Entries.Items[$i].DisplayEntry.Value 335 | 336 | $TempSelectedObject = $null 337 | 338 | $TempSelectedObject = $CurrentObject | Select-Object @{ 339 | n = $HeaderName; 340 | e = {$_.$($HeaderName)} 341 | } 342 | 343 | $Value = $TempSelectedObject.$($HeaderName) 344 | $TempPSObject | Add-Member -MemberType NoteProperty $HeaderName -Value $Value 345 | $TempHeaderList.Add($HeaderName) 346 | } 347 | } 348 | 349 | $CurrentObject = $TempPSObject | Select-Object -Property $TempHeaderList 350 | $Props = $CurrentObject | Get-Member -Name $TempHeaderList -MemberType Property, NoteProperty 351 | } 352 | } 353 | else { 354 | $CurrentObject = $CurrentObject | Select-Object -Property $Property -ErrorAction SilentlyContinue 355 | $Props = $CurrentObject | Get-Member -Name $Property -MemberType Property, NoteProperty 356 | } 357 | 358 | foreach ($Prop in $Props) { 359 | if ($HeadersForFormatTableStyle.Contains($Prop.Name) -eq $false) { 360 | $HeadersForFormatTableStyle.Add($Prop.Name) 361 | } 362 | } 363 | 364 | $ContentsForFormatTableStyle.Add($CurrentObject) 365 | } 366 | 367 | End { 368 | if ($NeedToReturn) { return } 369 | 370 | $HeaderRow = "|" 371 | $SeparatorRow = "|" 372 | $ContentRow = "" 373 | 374 | foreach ($Prop in $HeadersForFormatTableStyle) { 375 | $HeaderRow += "$(EscapeMarkdown($Prop))|" 376 | $SeparatorRow += ":--|" 377 | 378 | } 379 | 380 | foreach ($Content in $ContentsForFormatTableStyle) { 381 | $TempOutput = New-Object PSCustomObject 382 | $ContentRow += "|" 383 | 384 | if ($HeadersForFormatTableStyle.Count -eq "1" -and $HeadersForFormatTableStyle[0] -eq "") { 385 | # Content is an array of simple data type, like String. 386 | $ContentRow += "$(EscapeMarkdown($Content))|" 387 | $TempOutput = $null 388 | $TempOutput = $Content 389 | } 390 | else { 391 | foreach ($Prop in $HeadersForFormatTableStyle) { 392 | $ContentRow += "$(EscapeMarkdown($Content.($($Prop))))|" 393 | 394 | $TempOutput | Add-Member -MemberType NoteProperty $Prop -Value $Content.($($Prop)) 395 | } 396 | } 397 | 398 | $ContentRow += "`r`n" 399 | 400 | $TempOutputList.Add($TempOutput) 401 | } 402 | 403 | $Result = $HeaderRow + "`r`n" + $SeparatorRow + "`r`n" + $ContentRow 404 | 405 | $ResultForConsole = $Result 406 | $Result = "**" + (EscapeMarkdown($LastCommandLine)) + "**`r`n`r`n" + $Result 407 | 408 | if ($HideStandardOutput.IsPresent -eq $false) { 409 | $TempOutputList | Format-Table * -AutoSize 410 | } 411 | 412 | if ($ShowMarkdown.IsPresent) { 413 | Write-Output $ResultForConsole 414 | } 415 | 416 | if ($DoNotCopyToClipboard.IsPresent -eq $false) { 417 | Set-Clipboard $Result 418 | Write-Warning "Markdown text has been copied to the clipboard." 419 | } 420 | } 421 | } 422 | 423 | function EscapeMarkdown([object]$InputObject) { 424 | $Temp = "" 425 | 426 | if ($null -eq $InputObject) { 427 | return "" 428 | } 429 | elseif ($InputObject.GetType().BaseType -eq [System.Array]) { 430 | $Temp = "{" + [System.String]::Join(", ", $InputObject) + "}" 431 | } 432 | elseif ($InputObject.GetType() -eq [System.Collections.ArrayList] -or $InputObject.GetType().ToString().StartsWith("System.Collections.Generic.List")) { 433 | $Temp = "{" + [System.String]::Join(", ", $InputObject.ToArray()) + "}" 434 | } 435 | elseif (Get-Member -InputObject $InputObject -Name ToString -MemberType Method) { 436 | $Temp = $InputObject.ToString() 437 | } 438 | else { 439 | $Temp = "" 440 | } 441 | 442 | return $Temp.Replace("\", "\\").Replace("*", "\*").Replace("_", "\_").Replace("``", "\``").Replace("$", "\$").Replace("|", "\|").Replace("<", "\<").Replace(">", "\>").Replace([System.Environment]::NewLine, "
") 443 | } 444 | 445 | Export-ModuleMember -Function Format-MarkdownTableListStyle, Format-MarkdownTableTableStyle -Alias * --------------------------------------------------------------------------------