{"id":12229,"date":"2022-09-30T03:03:30","date_gmt":"2022-09-29T21:33:30","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/"},"modified":"2022-09-30T03:03:30","modified_gmt":"2022-09-29T21:33:30","slug":"solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/","title":{"rendered":"[Solved] In Powershell, how to copy files with common file name string (i.e. &#8220;ABC*&#8221;) last written in a specific date range?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-46891353\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"46891353\" data-parentid=\"46890406\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>This is a common task, here&#8217;s the general approach we take to solving an issue like this in PowerShell.  <\/p>\n<ol>\n<li>Get a list of files, VMs, Items, ETC<\/li>\n<li>Pipe this into the <code>Where-Object<\/code> cmdlet to filter and apply one or more constraints<\/li>\n<li>That&#8217;s it!<\/li>\n<\/ol>\n<p>With your requirements, we&#8217;ll actually do Step 2 in two separate steps, to highlight the approach needed.   I choose a different date range (From Sept 1 ~ Sept 30) but once you understand the concepts, you&#8217;ll know how to change this to fit your needs.  To start things off, here is the directory I&#8217;m testing against (pay close attention to the <code>LastWriteTime<\/code> column). <\/p>\n<pre><code>Mode                LastWriteTime         Length Name                                                                                           \n----                -------------         ------ ----                                                                                           \n-a----        9\/22\/2017   3:40 PM          64307 AcfBIns.jpg                                                                                    \n-a----        9\/23\/2017  10:15 PM           7047 beer-mug_1f37a.png                                                                             \n-a----        6\/30\/2017  12:15 PM          63304 bg.png                                                                                         \n-a----        9\/20\/2017  10:07 AM            938 certnew (1).p7b                                                                                \n-a----         6\/1\/2017  12:42 PM            822 DistributeMe.cer                                                                               \n-a----        7\/27\/2017   3:38 PM          95234 EFIESP.png                                                                                     \n-a----         7\/5\/2017   2:37 PM        1920416 Encoding Time.csv                                                                              \n-a----        9\/22\/2017   3:46 PM       66932648 en_remote_tools_for_visual_studio_2015.exe                               \n-a----        5\/26\/2017  12:31 PM            306 F0X_PPKG_PROD.cat                                                                              \n-a----        5\/26\/2017  12:31 PM           5529 F0X_PPKG_PROD.ppkg                                                                             \n-a----        6\/23\/2017   3:29 PM          50541 Fox.jpg                                                                                        \n-a----         7\/8\/2017   1:20 AM          10240 GetStats.exe                                                                                   \n-a----       10\/12\/2017   9:49 AM         126868 GIF.gif                                                                                        \n-a----        9\/21\/2017   9:28 AM       10427442 giphy (1).gif                                                                                  \n<\/code><\/pre>\n<p>First, a baseline of my folder to see how many items are there.<\/p>\n<pre><code>dir C:\\source | measure | select Count\n&gt;Count : 14\n<\/code><\/pre>\n<p>Now, for Step 2, building a filter: I&#8217;ll start by making a pointer to my earliest file start date, using the <code>Get-Date<\/code> cmdlet.  This will give me an &#8216;earliest file age&#8217; to compare against.<\/p>\n<pre><code>$Sept1  = Get-Date -Year 2017 -Month 09 -Day 01\n<\/code><\/pre>\n<p>Here&#8217;s the cool part, I can <em>filter<\/em> the files by looking only for ones Modified AFTER the date contained in <code>$Sept1<\/code> with one simple command, the <code>Where-Object<\/code> cmdlet.  In DotNet terms, Greater Than refers to after a date, while Lesser Than refers to taking place before a date.<\/p>\n<pre><code>dir c:\\source | where LastWriteTime -ge $Sept1 | measure | select Count\n&gt; Count : 6\n<\/code><\/pre>\n<p>After applying the first half of the filter, I have a list of only files modified beginning with September 1st.  You can then add an additional <code>Where-Object<\/code> command to narrow down to just your desired timespan like so:<\/p>\n<pre><code>#Make a pointer to the end of Sept\n$Sept30 = Get-Date -Year 2017 -Month 09 -Day 30\ndir c:\\source | where LastWriteTime -ge $Sept1 |\n    Where LastWriteTime -le $Sept30 | measure | select Count\n\n&gt;Count : 5\n<\/code><\/pre>\n<p>Now, just modify the dates to match your timespan and I think you can get this problem solved.<\/p>\n<h3>Older versions of PowerShell<\/h3>\n<p>Did you get an error like <code>\"cannot bind parameter 'FilterScript'. Cannot convert the 'LastWriteTime\" value of type System.String to type \"System.Management.Automation.ScriptBlock\"<\/code>, if so, then try this syntax instead.<\/p>\n<pre><code> $Sept30 = Get-Date -Year 2017 -Month 09 -Day 30 \n dir \\\\0.0.0.100\\C$\\source | where {$_.LastWriteTime -ge $Sept1} | \n   where {$_.LastWriteTime -le $Sept30} | measure | select Count\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">4<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved In Powershell, how to copy files with common file name string (i.e. &#8220;ABC*&#8221;) last written in a specific date range? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] This is a common task, here&#8217;s the general approach we take to solving an issue like this in PowerShell. Get a list of files, VMs, Items, ETC Pipe this into the Where-Object cmdlet to filter and apply one or more constraints That&#8217;s it! With your requirements, we&#8217;ll actually do Step 2 in two separate &#8230; <a title=\"[Solved] In Powershell, how to copy files with common file name string (i.e. &#8220;ABC*&#8221;) last written in a specific date range?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/\" aria-label=\"More on [Solved] In Powershell, how to copy files with common file name string (i.e. &#8220;ABC*&#8221;) last written in a specific date range?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[1153],"class_list":["post-12229","post","type-post","status-publish","format-standard","hentry","category-solved","tag-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] In Powershell, how to copy files with common file name string (i.e. &quot;ABC*&quot;) last written in a specific date range? - JassWeb<\/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:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] In Powershell, how to copy files with common file name string (i.e. &quot;ABC*&quot;) last written in a specific date range? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] This is a common task, here&#8217;s the general approach we take to solving an issue like this in PowerShell. Get a list of files, VMs, Items, ETC Pipe this into the Where-Object cmdlet to filter and apply one or more constraints That&#8217;s it! With your requirements, we&#8217;ll actually do Step 2 in two separate ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-29T21:33:30+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\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:\\\/\\\/jassweb.com\\\/solved\\\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] In Powershell, how to copy files with common file name string (i.e. &#8220;ABC*&#8221;) last written in a specific date range?\",\"datePublished\":\"2022-09-29T21:33:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\\\/\"},\"wordCount\":316,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"powershell\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\\\/\",\"name\":\"[Solved] In Powershell, how to copy files with common file name string (i.e. \\\"ABC*\\\") last written in a specific date range? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-09-29T21:33:30+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] In Powershell, how to copy files with common file name string (i.e. &#8220;ABC*&#8221;) last written in a specific date range?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] In Powershell, how to copy files with common file name string (i.e. \"ABC*\") last written in a specific date range? - JassWeb","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:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] In Powershell, how to copy files with common file name string (i.e. \"ABC*\") last written in a specific date range? - JassWeb","og_description":"[ad_1] This is a common task, here&#8217;s the general approach we take to solving an issue like this in PowerShell. Get a list of files, VMs, Items, ETC Pipe this into the Where-Object cmdlet to filter and apply one or more constraints That&#8217;s it! With your requirements, we&#8217;ll actually do Step 2 in two separate ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/","og_site_name":"JassWeb","article_published_time":"2022-09-29T21:33:30+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] In Powershell, how to copy files with common file name string (i.e. &#8220;ABC*&#8221;) last written in a specific date range?","datePublished":"2022-09-29T21:33:30+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/"},"wordCount":316,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["powershell"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/","url":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/","name":"[Solved] In Powershell, how to copy files with common file name string (i.e. \"ABC*\") last written in a specific date range? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-29T21:33:30+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-in-powershell-how-to-copy-files-with-common-file-name-string-i-e-abc-last-written-in-a-specific-date-range\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] In Powershell, how to copy files with common file name string (i.e. &#8220;ABC*&#8221;) last written in a specific date range?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/12229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=12229"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/12229\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=12229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=12229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=12229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}