{"id":434,"date":"2009-10-09T14:08:08","date_gmt":"2009-10-09T18:08:08","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/2009\/10\/get-numberedcontent\/"},"modified":"2009-10-09T14:51:24","modified_gmt":"2009-10-09T18:51:24","slug":"get-numberedcontent","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/","title":{"rendered":"Get-NumberedContent"},"content":{"rendered":"<p>One of the reasons I enjoy Twitter is that it exposes me to PowerShell ideas and enthusiasts beyond my immediate circle. I came across a blog <a title=\"view the original blog post\" href=\"http:\/\/tiredblogger.wordpress.com\/2009\/10\/08\/powershell-easy-line-numbers-using-cat-get-content\/\" target=\"_blank\">post<\/a> from <a title=\"Follow David Longnecker on Twitter\" href=\"http:\/\/www.twitter.com\/dlongnecker\" target=\"_blank\">David Longnecker<\/a> about a short function to display file content in a numbered format. Basically taking <strong>Get-Content<\/strong> and adding a line number to the output. Well I\u2019m like a raccoon drawn by shiny objects and was easily distracted enough to add my own variations on the idea.<\/p>\n<p><!--more-->  <\/p>\n<p>Since David was using <strong>Write-Host<\/strong>, I decided to take advantage of the color opportunities. Since I typically use <strong>Get-Content<\/strong> to quickly look at scripts, I decided that if the line began with a comment character, to display it in Green. But I do more than PowerShell, so I added code to see if the file was a script file (.bat, .cmd, .wsf, .vbs or .ps1). If so then it checks for the beginning comment character. Perhaps you\u2019d like to see what I\u2019m talking about.<\/p>\n<div style=\"border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px\" id=\"codeSnippetWrapper\">\n<div style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\" id=\"codeSnippet\">\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">Function Get-NumberedContent {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">    <span style=\"color: #0000ff\">param<\/span> ([string] $filename=$profile)<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">&#160;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">    If (Test-Path $filename) {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">        $counter = 0<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">        get-content $filename | <span style=\"color: #0000ff\">foreach<\/span> {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">            $counter++<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">            <span style=\"color: #008000\">#default font color<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">            $fcolor=<span style=\"color: #006080\">&quot;White&quot;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">&#160;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">            <span style=\"color: #008000\">#determine if file is a script<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">            <span style=\"color: #0000ff\">if<\/span> ((Get-Item $filename).extension <span style=\"color: #cc6633\">-match<\/span> <span style=\"color: #006080\">&quot;bat|vbs|cmd|wsf|ps1&quot;<\/span>) {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">                <span style=\"color: #008000\">#determine if line is a comment. If so we want to write it in Green<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">                <span style=\"color: #0000ff\">if<\/span> ($_.Trim().StartsWith(<span style=\"color: #006080\">&quot;#&quot;<\/span>) -or `<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">                    $_.Trim().StartsWith(<span style=\"color: #006080\">&quot;'&quot;<\/span>) -or `<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">                    $_.Trim().StartsWith(<span style=\"color: #006080\">&quot;::&quot;<\/span>) -or `<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">                    $_.Trim().ToLower().StartsWith(<span style=\"color: #006080\">&quot;rem&quot;<\/span>)) {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">&#160;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">                   $fcolor=<span style=\"color: #006080\">&quot;Green&quot;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">                }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">            }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">            <span style=\"color: #008000\">#write a 4 digit line number the | bar an.d then the line of text from the file<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">            <span style=\"color: #008000\">#trimming off any trailing spaces<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">            Write-Host (<span style=\"color: #006080\">&quot;{0:d4} | {1}&quot;<\/span> -f $counter,$_.TrimEnd()) -foregroundcolor $fcolor<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">&#160;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">             }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">    }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">    <span style=\"color: #0000ff\">else<\/span> {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">        Write-Warning <span style=\"color: #006080\">&quot;Failed to find $filename&quot;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">        }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\"> } <span style=\"color: #008000\">#end function<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px\">&#160;<\/pre>\n<p><!--CRLF--><\/div>\n<\/div>\n<p>The other change I made was formatting the line number so that it is always 4 digits with leading zeros.&#160; I rarely look at files with more than 10K lines with <strong>Get-Content<\/strong> so this seems reasonable.&#160; Oh..I also added minor error handling if you try to look at a file that doesn\u2019t exist and the function defaults to your PowerShell profile.<\/p>\n<p>I gave my function an alias of gnc. Here\u2019s some sample output:<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/captured_Image1.png1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px\" title=\"captured_Image.png\" border=\"0\" alt=\"captured_Image.png\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/captured_Image1.png_thumb1.png\" width=\"324\" height=\"210\" \/><\/a> <\/p>\n<p>I can think of a few more enhancements but I have to get <strong><em>something<\/em><\/strong> done today!<\/p>\n<div style=\"padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px\" id=\"scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:e33c16a8-beae-42c7-afaf-d1d07235bc2b\" class=\"wlWriterEditableSmartContent\">\n<div><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/GetNumberedContent.txt\" target=\"_blank\">Download Get-NumberedContent.<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>One of the reasons I enjoy Twitter is that it exposes me to PowerShell ideas and enthusiasts beyond my immediate circle. I came across a blog post from David Longnecker about a short function to display file content in a numbered format. Basically taking Get-Content and adding a line number to the output. Well I\u2019m&#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":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,8],"tags":[32,102,534,101],"class_list":["post-434","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-functions","tag-get-content","tag-powershell","tag-write-host"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Get-NumberedContent &#8226; The Lonely Administrator<\/title>\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\/434\/get-numberedcontent\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get-NumberedContent &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"One of the reasons I enjoy Twitter is that it exposes me to PowerShell ideas and enthusiasts beyond my immediate circle. I came across a blog post from David Longnecker about a short function to display file content in a numbered format. Basically taking Get-Content and adding a line number to the output. Well I\u2019m...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2009-10-09T18:08:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2009-10-09T18:51:24+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/captured_Image1.png_thumb1.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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Get-NumberedContent\",\"datePublished\":\"2009-10-09T18:08:08+00:00\",\"dateModified\":\"2009-10-09T18:51:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/\"},\"wordCount\":256,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2009\\\/10\\\/captured_Image1.png_thumb1.png\",\"keywords\":[\"functions\",\"Get-Content\",\"PowerShell\",\"Write-Host\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/\",\"name\":\"Get-NumberedContent &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2009\\\/10\\\/captured_Image1.png_thumb1.png\",\"datePublished\":\"2009-10-09T18:08:08+00:00\",\"dateModified\":\"2009-10-09T18:51:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2009\\\/10\\\/captured_Image1.png_thumb1.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2009\\\/10\\\/captured_Image1.png_thumb1.png\",\"width\":\"324\",\"height\":\"210\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/434\\\/get-numberedcontent\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get-NumberedContent\"}]},{\"@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":"Get-NumberedContent &#8226; The Lonely Administrator","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\/434\/get-numberedcontent\/","og_locale":"en_US","og_type":"article","og_title":"Get-NumberedContent &#8226; The Lonely Administrator","og_description":"One of the reasons I enjoy Twitter is that it exposes me to PowerShell ideas and enthusiasts beyond my immediate circle. I came across a blog post from David Longnecker about a short function to display file content in a numbered format. Basically taking Get-Content and adding a line number to the output. Well I\u2019m...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/","og_site_name":"The Lonely Administrator","article_published_time":"2009-10-09T18:08:08+00:00","article_modified_time":"2009-10-09T18:51:24+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/captured_Image1.png_thumb1.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":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Get-NumberedContent","datePublished":"2009-10-09T18:08:08+00:00","dateModified":"2009-10-09T18:51:24+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/"},"wordCount":256,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/captured_Image1.png_thumb1.png","keywords":["functions","Get-Content","PowerShell","Write-Host"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/","name":"Get-NumberedContent &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/captured_Image1.png_thumb1.png","datePublished":"2009-10-09T18:08:08+00:00","dateModified":"2009-10-09T18:51:24+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/captured_Image1.png_thumb1.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/captured_Image1.png_thumb1.png","width":"324","height":"210"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/434\/get-numberedcontent\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Get-NumberedContent"}]},{"@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":1220,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1220\/friday-fun-virtual-demos\/","url_meta":{"origin":434,"position":0},"title":"Friday Fun Virtual Demos","author":"Jeffery Hicks","date":"March 11, 2011","format":false,"excerpt":"I've been prepping my demo scripts for Techmentor using the ubiquitous Start-Demo, and realized I could take things further. I mean, why do I have to do all the talking? Windows 7 has a terrific text to speech engine so why not take advantage of it. With a little work\u2026","rel":"","context":"In &quot;Conferences&quot;","block_context":{"text":"Conferences","link":"https:\/\/jdhitsolutions.com\/blog\/category\/conferences\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6101,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6101\/powershell-calendaring-revisited\/","url_meta":{"origin":434,"position":1},"title":"PowerShell Calendaring Revisited","author":"Jeffery Hicks","date":"September 28, 2018","format":false,"excerpt":"Early this week, I came across an old snippet of code in my scripts folder, originally published by Lee Holmes. It was an old script, from 2008, on using PowerShell to display a calendar with out of office information.\u00a0 I seem to recall that I had been trying to do\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\/09\/show-calendar-2_thumb.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/show-calendar-2_thumb.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/show-calendar-2_thumb.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/show-calendar-2_thumb.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":37,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/37\/get-active-directory-user-information-in-powershell\/","url_meta":{"origin":434,"position":2},"title":"Get Active Directory User Information in PowerShell","author":"Jeffery Hicks","date":"July 5, 2006","format":false,"excerpt":"One feature that PowerShell will likely be missing when it first ships is solid support for ADSI and working with Active Directory. You can use .NET DirectoryEntry objects but it feels more like programming and less like scripting. Another option for working with Active Directory in PowerShell is to use\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5958,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5958\/friday-fun-perk-up-your-powershell-prompt\/","url_meta":{"origin":434,"position":3},"title":"Friday Fun: Perk Up Your PowerShell Prompt","author":"Jeffery Hicks","date":"April 6, 2018","format":false,"excerpt":"I haven't written a Friday Fun post in quite a while. Often these posts don't have much practical value but hopefully illustrate a concept or technique. Although what I have today is something you could use immediately. I have a version of a PowerShell prompt function that will color code\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/04\/pslocationprompt-2_thumb.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/04\/pslocationprompt-2_thumb.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/04\/pslocationprompt-2_thumb.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":49,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/49\/reading-the-registry-in-powershell\/","url_meta":{"origin":434,"position":4},"title":"Reading the Registry in PowerShell","author":"Jeffery Hicks","date":"August 26, 2006","format":false,"excerpt":"One of the great PowerShell features is that it treats the registry like any other location or directory. In PowerShell you can connect directly to the registry and navigate the key hierarchy just as if it as a logical drive with folders. I have a very brief demonstration script you\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5005,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5005\/memory-reporting-with-powershell\/","url_meta":{"origin":434,"position":5},"title":"Memory Reporting with PowerShell","author":"Jeffery Hicks","date":"May 20, 2016","format":false,"excerpt":"I've started a new project and I'm hoping a few of you will give it a spin and let me know how it works for you. I've created a PowerShell module called MemoryTools that uses a few WMI classes and performance counters to provide insight into memory utilization and configuration\u2026","rel":"","context":"In &quot;GitHub&quot;","block_context":{"text":"GitHub","link":"https:\/\/jdhitsolutions.com\/blog\/category\/github\/"},"img":{"alt_text":"show-memoryusage","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/show-memoryusage_thumb.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/show-memoryusage_thumb.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/show-memoryusage_thumb.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/434","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=434"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/434\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}