{"id":142,"date":"2013-04-09T09:58:05","date_gmt":"2013-04-09T14:58:05","guid":{"rendered":"https:\/\/linux.asberry.org\/blog_tech\/?p=142"},"modified":"2013-04-09T09:58:05","modified_gmt":"2013-04-09T14:58:05","slug":"using-powershell-to-keep-directories-clean","status":"publish","type":"post","link":"https:\/\/asberry.org\/blog_tech\/?p=142","title":{"rendered":"Using Powershell to Keep Directories Clean"},"content":{"rendered":"<p>As an integration engineer I have log files that provide me an audit trail so I can track things down when they go astray. \u00a0Now this is fine and well but what happens when you&#8217;ve had an integration in place since 2007 and never needed to look at those files? \u00a0Yes you&#8217;ve got 5 years worth of files that are taking up space on the drive. \u00a0To\u00a0alleviate the issue you can use Powershell to clear the directories of any files over a certain age. \u00a0Here is the code on how to do it:<\/p>\n<pre class=\"brush: powershell; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n# Delete all Files in the TCC Archives over 60 days old\r\n$Path = &quot;C:\\Taleo\\TCC\\Prod\\Export\\AirlandRequisition\\Archive&quot;\r\n$Daysback = &quot;-60&quot;\r\n$CurrentDate = Get-Date\r\n$DatetoDelete = $CurrentDate.AddDays($Daysback)\r\nGet-ChildItem $Path -Recurse | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item\r\n\r\nclear-variable -name Path\r\nclear-variable -name Daysback\r\nclear-variable -name CurrentDate\r\nclear-variable -name DatetoDelete\r\n\r\n$Path = &quot;C:\\Taleo\\TCC\\Prod\\Export\\AppTrackCSW\\Archive&quot;\r\n$Daysback = &quot;-60&quot;\r\n$CurrentDate = Get-Date\r\n$DatetoDelete = $CurrentDate.AddDays($Daysback)\r\nGet-ChildItem $Path -Recurse | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item\r\n\r\nclear-variable -name Path\r\nclear-variable -name Daysback\r\nclear-variable -name CurrentDate\r\nclear-variable -name DatetoDelete\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As an integration engineer I have log files that provide me an audit trail so I can track things down when they go astray. \u00a0Now this is fine and well but what happens when you&#8217;ve had an integration in place since 2007 and never needed to look at those files? \u00a0Yes you&#8217;ve got 5 years [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_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},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-uncategorized","author-aron"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4bBkH-2i","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=142"}],"version-history":[{"count":2,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":144,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions\/144"}],"wp:attachment":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}