Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Send the Output of a Powershell to robocopy

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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

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 …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

715 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