Solved

PowerShell Date Check

Posted on 2013-07-01
5
446 Views
Last Modified: 2013-07-08
Hi,

i am in the process of scripting the download of McAfee updates from their FTP site.  

Using PowerShell, I have created a script which pulls down the updates and then distributes them to different filers on the network.

I am trying to implement date check logic as follows.

##Delete Old Definition Files from the Share location
remove-item "\\$dest\avupdates\neta\*.*" -force -recurse

Do {remove-item "\\$dest\avupdates\EPO\commonupdater" -force -recurse
    c:\AVUpdateScripts\wget.exe ftp://ftp.nai.com/commonupdater/ -P \\$dest\avupdates\EPO -c -x -nH -r -l 0
    $file = get-item \\$dest\avupdates\EPO\comnmonupdater\*avv.gem}
    until($file.LastWriteTime -gt (Get-Date).AddDays(-2))

I use a Do Until Loop with the date check at the end.  There are times where we get files with the incorrect date,  such as out of date.

Thanks.
0
Comment
Question by:Resonetics
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
BT15 earned 250 total points
ID: 39290852
if it were me, I would do it without the loop. you can select just the old files to delete if you wish.:


this should delete all definitions from your specified locations, download all new ones, then delete any that are more than 2 days old.
remove-item "\\$dest\avupdates\neta\*.*" -force -recurse

remove-item "\\$dest\avupdates\EPO\commonupdater" -force -recurse
c:\AVUpdateScripts\wget.exe ftp://ftp.nai.com/commonupdater/ -P \\$dest\avupdates\EPO -c -x -nH -r -l 0
get-item \\$dest\avupdates\EPO\comnmonupdater\*avv.gem | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-2)} | del -confirm:$false

Open in new window

0
 
LVL 40

Expert Comment

by:footech
ID: 39290865
"There are times where we get files with the incorrect date,  such as out of date."

Can you explain further what you mean by this?  It's not clear to me.
0
 

Author Comment

by:Resonetics
ID: 39290876
Yes.  Often when I go to retrieve the updated definition files, they come back with a last modified date of 11/01/2012.

Is happens intermittently.
0
 
LVL 40

Expert Comment

by:footech
ID: 39291830
If the files have a timestamp other than 11/01/2012, but a query for $file.lastwritetime returns 11/01/2012 - sorry, I've never heard of an issue like you describe.  I can't think of any way that would happen, unless it is perhaps some temporary state that the files go through when they are being created by wget.
0
 

Author Closing Comment

by:Resonetics
ID: 39308065
Very similar to the logic I submitted, but less complicated.  Thanks for the easy solution.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question