I've kludged together a little script which, displays on screen the files as they're being processed to let the admin know the script is working, and then outputs the names of any files older modified within the last 6 months to a tx.t or csv:
get-childitem z:\directory\ -recurse | %(write-host Processing File: $_.fullname; $_} | Where{$_.lastwritetime -gt (get-date).addDays(-182) + out-file C:\scriptoutput\
This seems to work really well but I'd like to tweak it to come so that 1. it still mentions that the files are being process. 2. if are no items that are in that directory and subdirectories it doesn't output a file but just prints on the screen that there are no files older than 6 months.
I'd been tryign something along the lines of:
$Files= @(get-childitem z:\directory\ -recurse | where{$_.lastwritetime -gt (get-date).AddDays(182)} | %{write-host processing file: %_.fullname' $_})
If ($Files.lastwritetime -gt (get-date.adddays(-182))} | outfile 'c:\scriptoutput\'
Else ($files.lastwritetime lt (get-date.adddays(-182))} | {write-host "****NO FILES WERE MODIFIED IN THE LAST 6 MONTHS****})
Obviously this isn't working, I'm getting a Missing statemnt block after if (condition) error. Can anyone assist a TOTAL NOOB with where to go with this one?
Much appreciated,
Aucun commentaire:
Enregistrer un commentaire