Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #check date and select files in N: from bfeore today's date
  2. $todayDate = Get-Date -UFormat "%m / %d / %Y"
  3. $FKPLC1 = Get-ChildItem -Path "F:\KPLC1"
  4. $FKPLC2 = Get-ChildItem -Path "F:\KPLC2"
  5. $NKPLC1 = Get-ChildItem -Path "N:\KPLC1"
  6. $NKPLC2 = Get-ChildItem -Path "N:\KPLC2"
  7. $copied1 = @()
  8. $copied2 = @()
  9.  
  10. #For each item in F:\KPLC1, if the creation date is before today's date, copy it to N:\KPLC1 and add it to an array named "copied"
  11. foreach ($item in $FKPLC1) {
  12. if ($_.CreationDate -lt $todayDate) {
  13. copy-item -path "F:\KPLC1\$_" -Destination "N:\KPLC1"
  14. $copied1 += ,"$_"
  15. } else {
  16. "There is nothing to copy in KPLC1"
  17. }
  18. }
  19.  
  20. #For each item in F:\KPLC2, if the creation date is before today's date, copy it to N:\KPLC2 and add it to an array named "copied"
  21. foreach ($item in $FKPLC2) {
  22. if ($_.CreationDate -lt $todayDate) {
  23. copy-item -path "F:\KPLC2\$_" -Destination "N:\KPLC2"
  24. $copied2 += ,"$_"
  25. } else {
  26. "There is nothing to copy in KPLC1"
  27. }
  28. }
  29.  
  30. #Check that the items copied are in the correct directories, and if they are, delete them. (Ignoring any extra items that might be in N:\ but not in F:\)
  31.  
  32. #Display items in F that are not in N and assign those into an array
  33. $missing1 = $NKPLC1 | Where {$FKPLC1 -NotContains $_}
  34.  
  35. #Display items in F that are not in N and assign those into an array
  36. $missing2 = $NKPLC2 | where {$FKPLC2 -NotContains $_}
  37.  
  38. #if there are one or more items in the array, copy those items to N: and then delete the originals, otherwise delete all items in F:\KPLC1 that were in copied1
  39. if ($missing1.Count -gt 0) {
  40. $missing1 | copy-item -Path "F:\KPLC1\$_" -Destination "N:\KPLC1"
  41. } else {
  42. $copied1 | remove-item -Path "F:\KPLC1\$_"
  43. }
  44.  
  45. #if there are one or more items in the array, copy those items to N: and then delete the originals, otherwise delete all items in F:\KPLC2 that were in copied2
  46. if ($missing2.Count -gt 0) {
  47. $missing2 | copy-item -Path "F:\KPLC2\$_" -Destination "N:\KPLC2"
  48. } else {
  49. $copied2 | remove-item -Path "F:\KPLC2\$_"
  50. }
  51.  
  52. read-host "Press ENTER when finished."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement