Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

PowerShell Date Check

Posted on 2013-07-01
5
Medium Priority
?
466 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
BT15 earned 1000 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 41

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 41

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastrā€¦

647 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