{"id":4493,"date":"2012-12-08T00:01:00","date_gmt":"2012-12-08T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/12\/08\/weekend-scripter-use-powershell-to-count-pictures-on-a-picture-volume\/"},"modified":"2012-12-08T00:01:00","modified_gmt":"2012-12-08T00:01:00","slug":"weekend-scripter-use-powershell-to-count-pictures-on-a-picture-volume","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-use-powershell-to-count-pictures-on-a-picture-volume\/","title":{"rendered":"Weekend Scripter: Use PowerShell to Count Pictures on a Picture Volume"},"content":{"rendered":"<p><strong>Summary:<\/strong> Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to count pictures and to display free space on his picture volume.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. One of the cool things about visiting places is the opportunity to take pictures&mdash;at least that is a major attraction for me. Don&rsquo;t get me wrong. Charlotte, North Carolina, is a pretty city, and there are lots of nice places to take pictures, but dude, nothing in Charlotte compares with the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Prague_Castle\" target=\"_blank\">castle in Prague<\/a> that we saw while the Scripting Wife and I were visiting Windows PowerShell MVP <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/12\/03\/use-powershell-default-parameter-values-to-simplify-scripts.aspx\" target=\"_blank\">David Moravec<\/a> and his lovely wife, Andrea. I mean the <a href=\"http:\/\/www.memorylaneautomuseum.com\/\" target=\"_blank\">NASCAR museum<\/a> is nice (and it is not even really in Charlotte), but it&rsquo;s not quite as cool as a 1,200-year-old castle seen here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2548.WES-12-8-12-1.jpg\"><img decoding=\"async\" title=\"1,200-year-old castle\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2548.WES-12-8-12-1.jpg\" alt=\"1,200-year-old castle\" \/><\/a><\/p>\n<h2>Counting picture files<\/h2>\n<p>So, anyway, I went crazy and took over 800 pictures while we were in Prague. But how many pictures did I take during the entire trip? Well, here I can easily use Windows PowerShell to perform the count. My camera takes two types of pictures, RAW CR2 types of files and JPG files. I took a bit of both. The following is a Windows PowerShell 3.0 command (use of the <strong>&ndash;file switch<\/strong>).<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-ChildItem f: -Recurse -Include *.cr2,*.jpg -File | measure<\/p>\n<p style=\"padding-left: 30px\">Count&nbsp;&nbsp;&nbsp; : 9417<\/p>\n<p style=\"padding-left: 30px\">Average&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Sum&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Maximum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Minimum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Property :<\/p>\n<p>To do this on Windows PowerShell 2.0, I would use the following command.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-ChildItem f: -Recurse -Include *.cr2,*.jpg | where {!($_.ispscontainer) } | measure<\/p>\n<p style=\"padding-left: 30px\">Count&nbsp;&nbsp;&nbsp; : 9417<\/p>\n<p style=\"padding-left: 30px\">Average&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Sum&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Maximum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Minimum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Property :<\/p>\n<p>If I only want to know how many CR2 files I took, I use the command shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-ChildItem f: -Recurse -filter *.cr2 -File | measure<\/p>\n<p style=\"padding-left: 30px\">Count&nbsp; &nbsp;&nbsp;: 4706<\/p>\n<p style=\"padding-left: 30px\">Average&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Sum&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Maximum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Minimum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Property :<\/p>\n<p>Here is the Windows PowerShell 2.0 version of the command.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-ChildItem f: -Recurse -filter *.cr2 | where {!($_.ispscontainer) } | measure<\/p>\n<p style=\"padding-left: 30px\">Count&nbsp;&nbsp;&nbsp; : 4706<\/p>\n<p style=\"padding-left: 30px\">Average&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Sum&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Maximum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Minimum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Property :<\/p>\n<p>I can do the same thing for the JPG files, as shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-ChildItem f: -Recurse -filter *.jpg -File | measure<\/p>\n<p style=\"padding-left: 30px\">Count&nbsp;&nbsp;&nbsp; : 4711<\/p>\n<p style=\"padding-left: 30px\">Average&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Sum&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Maximum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Minimum&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">Property :<\/p>\n<h2>Finding disk space info<\/h2>\n<p>Because I took nearly 10,000 pictures, I am concerned about disk space. On my laptop running Windows&nbsp;8, I can use the following command to quickly obtain disk space information, as shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-Volume -DriveLetter f<\/p>\n<p>The command and the output associated with the command is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5353.hsg-12-8-12-02.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5353.hsg-12-8-12-02.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>To use Windows PowerShell 2.0 (or even Windows PowerShell 3.0 on a computer <em>not<\/em> running Windows 8), you need to query the Win32_Volume WMI class (this class appears on Windows Server&nbsp;2003 and later&mdash;not on Windows XP). The following command illustrates this technique, where&nbsp;<strong>GWMI<\/strong> is an alias for the <strong>Get-WmiObject<\/strong> cmdlet, and <strong>FT<\/strong> is an alias for the <strong>Format-Table<\/strong> cmdlet. Because WMI returns disk-sizing information in bytes, it is better to calculate the output and to convert it into at least gigabytes for easier reading. This is what the custom label commands do in the <strong>Format-Table<\/strong> cmdlet.<\/p>\n<p style=\"padding-left: 30px\">gwmi win32_volume -Filter &#8220;driveletter = &#8216;f:'&#8221; | ft driveletter, label, @{LAB<\/p>\n<p style=\"padding-left: 30px\">EL=&#8217;Size GB&#8217;;EXPRESSION = {$_.capacity\/1GB}}, @{LABEL=&#8217;FREE GB&#8217;;EXPRESSION = {$_.FreeSpace\/1GB}} &ndash;AutoSize<\/p>\n<p>The command and its associated output are shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6242.hsg-12-8-12-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6242.hsg-12-8-12-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto: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.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to count pictures and to display free space on his picture volume. Microsoft Scripting Guy, Ed Wilson, is here. One of the cool things about visiting places is the opportunity to take pictures&mdash;at least that is a major attraction for me. Don&rsquo;t get me [&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":[38,3,12,61,45],"class_list":["post-4493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-files","tag-scripting-guy","tag-storage","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to count pictures and to display free space on his picture volume. Microsoft Scripting Guy, Ed Wilson, is here. One of the cool things about visiting places is the opportunity to take pictures&mdash;at least that is a major attraction for me. Don&rsquo;t get me [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4493","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=4493"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4493\/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=4493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}