Solved

PowerShell Date Check

Posted on 2013-07-01
5
437 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 39

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 39

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now