Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

copy latest diff or full to another directory

$
0
0

I am a newbie to Powershell.

I am using Powershell as a step within my SQL job to copy the latest diff or full backup to another folder. The first step (backup database) is done thru the maintenance plan I set up and I have added the second step to copy it to another location. I have Powershell selected as my Type. I am using the following script:

foreach ($File in Get-ChildItem Source Directory X
{
    if ($File.LastWriteTiem - lt (Get-Date).ADDHOUR (-1))
        {
           Copy-Item $File.SourceDirectoryX -Destination Destination Directory Y

         }
}

I believe the If (test) and condition (Copy-Item)is right but get errors either relating to system time (Get-Date) or "Cannot bind arguement to parameter 'Path' because it is NULL.

 

The foreach does a loop thru the source sirectory and if I run just the Get-ChildItem, I get results.

The source directory has 2 folders (DIFF and FUll) which I need to retain and only want to copy the last full or diff (every hour) into destination.

 

Not sure of where I am going wrong. Any help would be much appreciated.

 

Respectfully,

Carl


Viewing all articles
Browse latest Browse all 10624

Latest Images

Trending Articles



Latest Images