Solved

Powershell Script  - I want to move Logs from \\server01\Stroage\subfolders to \\server02\stroage\newfolderwithdate\subfolders

Posted on 2014-09-09
3
166 Views
Last Modified: 2014-09-18
I want to move Logs older than 3 moths from \\server01\Stroage\subfolders to \\server02\stroage\newfolderwithdate\subfolders (as from destination) , after copied ,verfied , delete all copied ones.

many thanks
0
Comment
Question by:SAIMSKY ADMIN
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40313073
Try this code and see if it works for you..
#Update the source and destination folder path
$Source = "\\server01\Stroage"
$Dest = "\\server02\stroage"

#Create destination folder if it doesn't exist
$D = "$Dest\Folder$(get-date -f dd-MM-yyyy)"
 If (!(Test-Path $D)) {New-Item $D -ItemType directory -Force}

#Move files older than 3 months
robocopy $Source $D /s /mov /minage:$(((Get-Date) - (get-date).AddMonths(-3)).TotalDays)

#or you can change the parameter value /minage:90 if you are not worried about the exact 3 moths period

Open in new window

0
 
LVL 21

Expert Comment

by:yo_bee
ID: 40313200
You can all try this.
$soruce = "\\netapp01\AdminData\FLH Confidental"
$dest = "\\netapp01\itdata"
$a = Get-ChildItem $soruce\* -recurse  ##-Include Archive*
 ForEach ($x in $a)
    {
        $y=((Get-Date)-$x.lastwritetime).days
        ##Write-Host $x.FullName
        If ($y -gt 90 )
       {Move-Item -Path $x.FullName -Destination $dest}
       
         
    }

Open in new window

0
 

Author Closing Comment

by:SAIMSKY ADMIN
ID: 40329793
thanks
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

746 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

12 Experts available now in Live!

Get 1:1 Help Now