Solved

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

Posted on 2014-09-09
3
177 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
[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
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 22

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

749 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