Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Send the Output of a Powershell to robocopy

Posted on 2015-02-24
2
Medium Priority
?
134 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 30

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 85

Accepted Solution

by:
oBdA earned 2000 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

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

916 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