{"id":20055,"date":"2023-07-17T12:53:32","date_gmt":"2023-07-17T20:53:32","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/powershell\/?p=20055"},"modified":"2024-04-26T10:46:36","modified_gmt":"2024-04-26T18:46:36","slug":"microsoft-powershell-textutility-module-updates","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/microsoft-powershell-textutility-module-updates\/","title":{"rendered":"Microsoft.PowerShell.TextUtility module updates"},"content":{"rendered":"<h2>TextUtility module gets new functionality<\/h2>\n<p>We have recently released another preview of the TextUtility module. This module is a collection of tools that\nare meant to help with working with text content.<\/p>\n<h2>Installing the module<\/h2>\n<p>You can install this module from the <a href=\"https:\/\/www.powershellgallery.com\/packages\/Microsoft.PowerShell.TextUtility\/0.1.0-Preview1\">PowerShellGallery<\/a> with PowerShellGet via:<\/p>\n<pre><code class=\"language-powershell\">Install-Module -Name Microsoft.PowerShell.TextUtility -AllowPrerelease<\/code><\/pre>\n<p>Or you can install it with PSResourceGet via:<\/p>\n<pre><code class=\"language-powershell\">Install-PSResource -Name Microsoft.PowerShell.TextUtility -Prerelease<\/code><\/pre>\n<h2>ConvertFrom-TextTable<\/h2>\n<p>The most recent pre-release of Microsoft.PowerShell.TextUtility\nhas some new exciting functionality.\nThe new <code>ConvertFrom-TextTable<\/code> cmdlet allows you to take tabular text\nand convert it into objects.\nAlso, there is a way to convert some of types of those objects into something other than a string.\nUsing the <code>-ConvertPropertyValue<\/code> parameter will change the value of the property to a strongly typed value.\nThis means you can do the following:<\/p>\n<pre><code class=\"language-powershell\">\r\nPS&gt; df | select -first 6 | convertfrom-texttable -ConvertPropertyValue |Ft                       \r\n\r\nFilesystem     512-blocks     Used  Available Capacity  iused      ifree %iused Mounted_on\r\n----------     ----------     ----  --------- --------  -----      ----- ------ ----------\r\n\/dev\/disk4s1s1 3907805752 17699080 1242895000 2%       355382 4291123926 0%     \/\r\ndevfs                 462      462          0 100%        800          0 100%   \/dev\r\n\/dev\/disk4s3   3907805752  3676600 1242895000 1%         3745 6214475000 0%     \/System\/Volumes\/Preboot\r\n\/dev\/disk4s5   3907805752  4194376 1242895000 1%            2 6214475000 0%     \/System\/Volumes\/VM\r\n\/dev\/disk4s6   3907805752    19992 1242895000 1%           19 6214475000 0%     \/System\/Volumes\/Update\r\n\r\nPS&gt; df | select -first 6 | convertfrom-texttable -ConvertPropertyValue |?{$_.available -lt 10}|Ft\r\n\r\nFilesystem 512-blocks Used Available Capacity iused ifree %iused Mounted_on\r\n---------- ---------- ---- --------- -------- ----- ----- ------ ----------\r\ndevfs             462  462         0 100%       800     0 100%   \/dev\r\n<\/code><\/pre>\n<p><code>ConvertFrom-TextTable<\/code> also allows you to specify where the header line is defined, or skip lines until you get to where the data starts.\nAdditionally, it is possible to take the text output and explicitly create properties by defining where a column starts.<\/p>\n<pre><code class=\"language-powershell\">PS&gt; $string = $(\"a\"..\"z\";\"A\"..\"Z\";0..9) -join \"\"                                                      \r\nPS&gt; 1..10 | %{$string}|convertfrom-texttable -noheader -columnoffset 0,15,23,40,55 | ft\r\n\r\nProperty_01     Property_02 Property_03       Property_04     Property_05\r\n-----------     ----------- -----------       -----------     -----------\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789\r\nabcdefghijklmno pqrstuvw    xyzABCDEFGHIJKLMN OPQRSTUVWXYZ012 3456789<\/code><\/pre>\n<p>Finally, you can also emit the data as JSON with the <code>-AsJson<\/code> parameter:<\/p>\n<pre><code class=\"language-powershell\">PS&gt; who -p | %{$_.trim()} | convertfrom-texttable -noheader -AsJson  \r\n{ \"Property_01\": \"james\", \"Property_02\": \"console\", \"Property_03\": \"Jun\", \"Property_04\": \"22\", \"Property_05\": \"08:34\" }\r\n{ \"Property_01\": \"james\", \"Property_02\": \"ttys016\", \"Property_03\": \"Jun\", \"Property_04\": \"22\", \"Property_05\": \"10:00\" }\r\n{ \"Property_01\": \"james\", \"Property_02\": \"ttys017\", \"Property_03\": \"Jun\", \"Property_04\": \"22\", \"Property_05\": \"14:42\" }\r\n{ \"Property_01\": \"james\", \"Property_02\": \"ttys004\", \"Property_03\": \"Jun\", \"Property_04\": \"22\", \"Property_05\": \"22:08\" }\r\n{ \"Property_01\": \"james\", \"Property_02\": \"ttys025\", \"Property_03\": \"Jun\", \"Property_04\": \"23\", \"Property_05\": \"00:38\" }<\/code><\/pre>\n<h3>Next Steps<\/h3>\n<p>This is still in pre-release and we know that there is still work to be done.\nFor example, the parser will create an object out of the header\/data separator.\nThis is a little trickier than at first it would seem.\nThe text is inspected and columns width is decided based on the inspected text.\nThese header\/data separator lines help the parser understand where the columns are separated.\nThis means we can&#8217;t just toss them out as the text is being read.\nI&#8217;m sure you&#8217;ll find more things that we can do,\nand we would love to get your feedback on this new cmdlet so please give this module a try.\nPlease submit your feedback to the repo directly via the issues tab, <a href=\"https:\/\/github.com\/PowerShell\/TextUtility\/issues\">here<\/a>.<\/p>\n<p>Thanks so much!<\/p>\n<p>Jim Truher<\/p>\n<p>PowerShell Team<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TextUtility module gets new functionality We have recently released another preview of the TextUtility module. This module is a collection of tools that are meant to help with working with text content. Installing the module You can install this module from the PowerShellGallery with PowerShellGet via: Install-Module -Name Microsoft.PowerShell.TextUtility -AllowPrerelease Or you can install it [&hellip;]<\/p>\n","protected":false},"author":2413,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3192],"class_list":["post-20055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-textutility"],"acf":[],"blog_post_summary":"<p>TextUtility module gets new functionality We have recently released another preview of the TextUtility module. This module is a collection of tools that are meant to help with working with text content. Installing the module You can install this module from the PowerShellGallery with PowerShellGet via: Install-Module -Name Microsoft.PowerShell.TextUtility -AllowPrerelease Or you can install it [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/20055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/2413"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=20055"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/20055\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=20055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=20055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=20055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}