Solved

Send the Output of a Powershell to robocopy

Posted on 2015-02-24
2
121 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

615 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