Solved

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

Posted on 2014-09-09
3
171 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 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A brief introduction to what I consider to be the best editor for PowerShell.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…

809 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