{"id":13291,"date":"2011-07-17T00:01:00","date_gmt":"2011-07-17T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/07\/17\/learn-how-to-use-sysinternals-ntfsinfo-cmd-in-powershell\/"},"modified":"2011-07-17T00:01:00","modified_gmt":"2011-07-17T00:01:00","slug":"learn-how-to-use-sysinternals-ntfsinfo-cmd-in-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/learn-how-to-use-sysinternals-ntfsinfo-cmd-in-powershell\/","title":{"rendered":"Learn How to Use Sysinternals Ntfsinfo Cmd in PowerShell"},"content":{"rendered":"<p><strong>Summary<\/strong>: Learn how to use Sysinternals ntfsinfo command in Windows PowerShell.\n&nbsp;\n<span style=\"font-size: large\"><strong>Weekend Scripter: Windows PowerShell and the Legacy&#8211;Hero Worship<\/strong><\/span>\nMicrosoft Scripting Guy Ed Wilson here. Sean Kearney writes today more about legacy and Windows PowerShell. See <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/06\/05\/use-powershell-to-pass-credentials-to-legacy-systems.aspx\">his first blog posts on the topic<\/a>, as well as <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/07\/16\/working-around-legacy-redirection-issues-with-powershell.aspx\">yesterday&rsquo;s blog post<\/a>.\n<b><span style=\"text-decoration: underline\"><\/span><\/b>&nbsp;\nThe door to the Scripting Room opens to an unusual sight. The student is bowing and paying homage to a square blue object. &ldquo;I am not worthy! I am not worthy! Please be kind upon thy little servant! Oh, mighty digital one! Oh, King of Security! I am not worthy! I am not worthy! I am not&hellip;&rdquo;\nThe Scripting Guy quietly peers about to find his student kneeling and bowing before a copy of <i>Zero Day<\/i> by Mark Russinovich. &ldquo;Good choice,&rdquo; he thinks to himself &ldquo;but we need to break this hero worship. If he ever sees Mark, he&rsquo;ll fall down the stairs running away.&rdquo; He taps the student on the shoulder, which causes arms flailing in the air. &ldquo;Aihaihgiahgihaighiaghghighaghih!!&rdquo;\nThe Scripting Guy shakes his head in wonder. &ldquo;You do know that no program is perfect, don&rsquo;t you? Even things written by the Great One can be improved.&rdquo; Again, the clunking of the jaw against the ground in disbelief is heard and a shaking of the head is witnessed.\n&ldquo;You know of a great utility called NTFSINFO.EXE that <a title=\"Sysinternals\" href=\"http:\/\/www.sysinternals.com\/\" target=\"_blank\">Sysinternals<\/a> wrote to display details about NTFS volumes, don&rsquo;t you?&rdquo; The student nods vigorously and is about to begin bowing to his newly acquired copy of <i>Zero Day<\/i> when the Scripting Guy gently moves the book away with one phrase. &ldquo;We can improve NTFSINFO.EXE with Windows PowerShell, you know.&#8221; Knowing The Scripting Guy would never lie, the young one sits down for this lesson. &ldquo;Oooooooo&rdquo; is all that can be heard from his lips.\n&ldquo;We know that if you run NTFSINFO.EXE with a drive letter like this&hellip;&rdquo;<\/p>\n<p style=\"padding-left: 30px\">NTFSINFO.EXE C:<i><\/i>\n&ldquo;&hellip;it will return details like this.&rdquo;<\/p>\n<p style=\"padding-left: 30px\">NTFS Information Dump V1.01<br \/>Copyright (C) 1997 Mark Russinovich<br \/>http:\/\/www.sysinternals.com<\/p>\n<p style=\"padding-left: 30px\">Volume Size<br \/>&#8212;&#8212;&#8212;&#8211;<br \/>Volume size : 304931 MB<br \/>Total sectors : 624500735<br \/>Total clusters : 78062591<br \/>Free clusters : 6429565<br \/>Free space : 25115 MB (8% of drive)<\/p>\n<p style=\"padding-left: 30px\">Allocation Size<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>Bytes per sector : 512<br \/>Bytes per cluster : 4096<br \/>Bytes per MFT record : 1024<br \/>Clusters per MFT record: 0<\/p>\n<p style=\"padding-left: 30px\">MFT Information<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>MFT size : 327 MB (0% of drive)<br \/>MFT start cluster : 786432<br \/>MFT zone clusters : 16593056 &#8211; 16593088<br \/>MFT zone size : 0 MB (0% of drive)<br \/>MFT mirror start : 2<\/p>\n<p style=\"padding-left: 30px\">Meta-Data files<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;<i><\/i>\n&ldquo;So! Let&rsquo;s just say we would like to have all of this data broken out so that we could access it in an easier-to-use fashion, or perhaps bring it to something like Out-Gridview. This program won&rsquo;t do that.&rdquo;\nThe student nods. &ldquo;It is just text on the screen.&rdquo;\n&ldquo;No, remember. It&rsquo;s an object. So we just need to figure out how to manipulate it. So looking at this object it appears there is a pattern in the output. Each line we want has a blank space, a colon, and another blank space following. So our first task is to search out the data with a SELECT-STRING statement and store it away&rdquo;:<\/p>\n<p style=\"padding-left: 30px\">$RESULTS=(NTFSINFO.EXE C:) | SELECT-STRING &ldquo; : &ldquo;<i><\/i>\nIf we examine $RESULTS, we will find we have nothing but lines with the needed data. We can now step through the list and grab the header and data from each line with a quick FOREACH and a bit of splitting and trimming. But we need to switch the output to a string first. If we run a GET-MEMBER, we&rsquo;ll note that the output of SELECT-STRING isn&rsquo;t actually a string but a <b>MatchInfo<\/b> object. But we have a <b>tostring()<\/b> method available with this object, so we can leverage that\nSo we&rsquo;ll build a small advanced function to parse the data with New-Object. This way we can leverage the power of the pipeline and send the data to other Windows PowerShell cmdlets, such as OUT-GRIDVIEW:<\/p>\n<p style=\"padding-left: 30px\">function global:Split-Result()<br \/>{<br \/>param<br \/>(<br \/>[parameter(ValueFromPipeline=$true,<br \/>Mandatory=$true)]<br \/>[Array]$MATCHRESULT<br \/>)<\/p>\n<p style=\"padding-left: 30px\">process<br \/>{ <br \/>$ReturnData=NEW-OBJECT PSOBJECT &ndash;property @{Title=&rsquo;&rsquo;;Value=&rsquo;&rsquo;}<br \/>$DATA=$Matchresult[0].tostring().split(&#8220;:&#8221;)<br \/>$ReturnData.Title=$Data[0].trim()<br \/>$ReturnData.Value=$Data[1].trim()<br \/>Return $ReturnData<br \/>}<br \/>}<\/p>\n<p style=\"padding-left: 30px\">Now that we can work through the data results in the pipeline, we can do something fun like this:<\/p>\n<p style=\"padding-left: 30px\">$Results | Split-Result | Out-Gridview<i><\/i>\n&ldquo;This will output the results from Mr. Russinovich&rsquo;s program into a GUI. So what do you think of that?&rdquo;\nHis only answer was to quickly replace his copy of <i>Zero Day<\/i> with <i>Windows<\/i> <i>PowerShell Step by Step<\/i> and began prostrating anew.\n&ldquo;I am not worthy! Please be kind to this meek one! Oh, mighty scripter! Oh, King of the Shell! I am humbled! I am your servant. I am&hellip;.&rdquo;\nThe Scripting Guy walked out of the room quietly shaking his head with a smile. &ldquo;Hero worship, I remember it well.&rdquo;<em><b><\/b><\/em>\n&nbsp;\nThanks again, Sean!\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.\n<b>Ed Wilson, Microsoft Scripting Guy<\/b>\n&nbsp;\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use Sysinternals ntfsinfo command in Windows PowerShell. &nbsp; Weekend Scripter: Windows PowerShell and the Legacy&#8211;Hero Worship Microsoft Scripting Guy Ed Wilson here. Sean Kearney writes today more about legacy and Windows PowerShell. See his first blog posts on the topic, as well as yesterday&rsquo;s blog post. &nbsp; The door to the [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[51,56,2,3,4,154,45],"class_list":["post-13291","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-guest-blogger","tag-running","tag-scripting-guy","tag-scripting-techniques","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use Sysinternals ntfsinfo command in Windows PowerShell. &nbsp; Weekend Scripter: Windows PowerShell and the Legacy&#8211;Hero Worship Microsoft Scripting Guy Ed Wilson here. Sean Kearney writes today more about legacy and Windows PowerShell. See his first blog posts on the topic, as well as yesterday&rsquo;s blog post. &nbsp; The door to the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=13291"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13291\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=13291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=13291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=13291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}