Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Set OWA language and time zone in Exchange for individuals, all users or per database.
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 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

26 Experts available now in Live!

Get 1:1 Help Now