Solved

Send the Output of a Powershell to robocopy

Posted on 2015-02-24
2
82 Views
Last Modified: 2015-04-03
Hello experts . I have a powershell script that remove stale data on my File server  . I want the result of this script to be pipe to robocopy to remove the data from the Source and Copy them to the destination
this is the script

------------------------------------------------
dir c:\shares\public -recurse |

Select Fullname,CreationTime,LastWriteTime,

@{Name="Age";Expression={(Get-Date)-$_.LastWriteTime}},

@{Name="Days";Expression={[int]((Get-Date)

-$_.LastWriteTime).TotalDays}},

@{Name="Owner";Expression={(Get-ACL $_.fullname).Owner}} |

Where {$_.Days -ge 400} | Sort Days -Descending
----------------------------------------------------------------------------------------------------------


Thx
0
Comment
Question by:gazambey
2 Comments
 
LVL 29

Expert Comment

by:Rich Weissler
ID: 40627961
You might be able to pipe into something like:
ForEach-Object { robocopy "[sourcepath]\$_" "[destpath]\$_" <options> }

But I sure would be tempted to use move-item instead.
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40627962
Robocopy can do that out of the box; /MINAGE:400 will only copy files with a last write time of 400 days ago and older.
Example in test mode; with the /L at the end, it will only List what it would do, but not copy/move actually anything; remove the /L to run it for real. /mov will move files, but leave empty folders in the source; if you use /move instead, it will remove empty folders from the source.
& robocopy.exe "C:\shares\public" "D:\Archive\public" *.* /s /r:0 /mov /minage:400 /np /tee /log:C:\Temp\robocopy-archive.log /L

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Synchronize a new Active Directory domain with an existing Office 365 tenant
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

13 Experts available now in Live!

Get 1:1 Help Now