{"id":9101,"date":"2006-12-14T09:07:00","date_gmt":"2006-12-14T09:07:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/12\/14\/file-aging-script\/"},"modified":"2019-02-18T13:21:03","modified_gmt":"2019-02-18T20:21:03","slug":"file-aging-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/file-aging-script\/","title":{"rendered":"File Aging Script"},"content":{"rendered":"<p>Jeffery Hicks as a very nice File Aging script.&nbsp; The thing that Iike about it is that it provides a very good illustration of how to use a number of PowerShell features including:<\/p>\n<ul>\n<li>Working with Files<\/li>\n<li>Working with Dates<\/li>\n<li>Control structures: if, foreach, switch<\/li>\n<li>Working with Formating strings<\/li>\n<li>Using colorized output<\/li>\n<\/ul>\n<p>He had one technique that could be improved.&nbsp; Here is a line from the script:&nbsp;<\/p>\n<blockquote>\n<p><font face=\"Courier New\">$GrandTotal=&#8221;{0:N2}&#8221; -f ($GrandTotal\/1048576)<\/font><\/p>\n<\/blockquote>\n<p>The question is, what is that number?&nbsp; Well you might guess that that is 1 MegaByte and you are probably correct but are you sure that a MegaByte isn&#8217;t 1045876?&nbsp; I transpose numbers all the time, maybe Jeffery did as well.&nbsp; He didn&#8217;t but you see the points 1) if it was wrong &#8211; would you be able to recognize that it was wrong? 2) if you had to write this yourself &#8211; are you going to (a) remember what to type and (b) type it correctly?&nbsp; You are much better off using our built-in support for &#8220;KB&#8221;, &#8220;MB&#8221;, &#8220;GB&#8221; and make this:<\/p>\n<blockquote>\n<p><font face=\"Courier New\">$GrandTotal=&#8221;{0:N2}&#8221; -f ($GrandTotal\/1mb)<\/font><\/p>\n<\/blockquote>\n<p>Here is a demo:<\/p>\n<p>PS&gt; 1kb<br \/>1024<br \/>PS&gt; 1mb<br \/>1048576<br \/>PS&gt; 1gb<br \/>1073741824<br \/>PS&gt; 1kb+2mb+3gb<br \/>3223323648<\/p>\n<p>Check&nbsp;out Jeffery&#8217;s File Aging&nbsp;script at: <a href=\"http:\/\/sapien.eponym.com\/blog\/_archives\/2006\/12\/14\/2571520.html\">http:\/\/sapien.eponym.com\/blog\/_archives\/2006\/12\/14\/2571520.html<\/a><\/p>\n<p>Jeffery and Don Jones have been doing lots of great stuff at that web site so you take some time to check it out.<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/MMC Architect<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jeffery Hicks as a very nice File Aging script.&nbsp; The thing that Iike about it is that it provides a very good illustration of how to use a number of PowerShell features including: Working with Files Working with Dates Control structures: if, foreach, switch Working with Formating strings Using colorized output He had one technique [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9101","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Jeffery Hicks as a very nice File Aging script.&nbsp; The thing that Iike about it is that it provides a very good illustration of how to use a number of PowerShell features including: Working with Files Working with Dates Control structures: if, foreach, switch Working with Formating strings Using colorized output He had one technique [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9101","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\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=9101"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9101\/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=9101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=9101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=9101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}