Solved

Send the Output of a Powershell to robocopy

Posted on 2015-02-24
2
111 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 84

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

739 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