Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

copy the correct file based on date??

$
0
0

$whatdate = (Get-Date).Date

$today = $whatdate.ToShortDateString()

 

$file = (Get-ChildItem 'C:\pstfiles\*.pst').LastWriteTime.ToShortDateString()

 

foreach ($pst in $file)  

    {$day = $today -like $file} 

        if ($day -like "TRUE") {Copy-Item c:\pstfiles\$pst "c:\temp\PSTTSP"}

 

this code executes without error but nothing gets copied.  This is because my $file is a date (7/24/2014).   How do I modify this code so I capture the file name yet still do the date comparison?   

 

I have 3 files in my folder.  File1 modified today.  File2 and File3 modified yesterday.  When when I run my code I want to to see that File1 was modified today and then copy File1.pst to my target location.   Sounds easy but proving to be hard.


mqh7


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>