File Cleanup Script - Assistance Required
hi all,
attempting write file cleanup script , can't seem working how like. first, let me explain trying accomplish. cleanup incoming/outgoing folders of our ftp server on regular basis. folder structure looks this:
\\data5\ftpdata\partnername\incoming
\\data5\ftpdata\partnername\outgoing
partnername have in path different each partner have ftp login setup for. script delete both files , folders last modified date (.lastwritetime property) of 30 days or older in of incoming/outgoing directories each of partnername sites. script should not delete of partnername folders or incoming\outgoing folders themselves, no matter date. so, while have script working primary issue can't figure out way tell not @ partnername folders (which have variable, add additional partner-names ftpdata folder). below script in it's current form, works, except delete partnername folders (which not correct).
script pretty works. doesn't delete incoming/outgoing folders , clean old files. deletes partnername folders well! please let me know if require additional clarification or information trying accomplish , happy provide it. appreciate help; there's simple solution i'm not seeing!
attempting write file cleanup script , can't seem working how like. first, let me explain trying accomplish. cleanup incoming/outgoing folders of our ftp server on regular basis. folder structure looks this:
\\data5\ftpdata\partnername\incoming
\\data5\ftpdata\partnername\outgoing
partnername have in path different each partner have ftp login setup for. script delete both files , folders last modified date (.lastwritetime property) of 30 days or older in of incoming/outgoing directories each of partnername sites. script should not delete of partnername folders or incoming\outgoing folders themselves, no matter date. so, while have script working primary issue can't figure out way tell not @ partnername folders (which have variable, add additional partner-names ftpdata folder). below script in it's current form, works, except delete partnername folders (which not correct).
$ftpdirs = get-childitem -path "\\data5\ftpdata" -exclude "do_not_delete.txt", "ftpevents.txt", "robocopy.exe"
#this variable had intended use pass -exclude parameter partnername folders excluded but
#the -exclude parameter appears ignore variable being passed it
$dir = get-childitem -path "\\data5\ftpdata" -exclude "do_not_delete.txt", "ftpevents.txt", "robocopy.exe", "incoming", "outgoing" -recurse `
| where-object {$_.lastwritetime -le (get-date).adddays(-30)}
#recurses through directory find files (not folders) lastwrite date 30 days or older
#excludes couple of specific files not want ever deleted
$dir | remove-item -recurse -force -whatif
#portion of script recurses through \\data5\ftpdata directory , deletes files , folders last written 30 days ago
script pretty works. doesn't delete incoming/outgoing folders , clean old files. deletes partnername folders well! please let me know if require additional clarification or information trying accomplish , happy provide it. appreciate help; there's simple solution i'm not seeing!
my fault
$ftpdirs |? {$_.name -notlike "*incoming" -and $_.name -notlike "*outgoing"}| % {if ($_.lastwritetime -le (get-date).adddays(-30) -and (!(gci $_))){ remove-item $_.fullname -whatif}}
$ftpdirs |? {$_.name -notlike "*incoming" -and $_.name -notlike "*outgoing"}| % {if ($_.lastwritetime -le (get-date).adddays(-30) -and (!(gci $_))){ remove-item $_.fullname -whatif}}
Windows Server > Windows PowerShell
Comments
Post a Comment