A handy powershell script for xcopying data – useful for database backups that need copying to tape:
function xCopy
(
[string]$src = $(throw "Specify the source directory"),
[string]$dest = $(throw "Specify the destination diirectory")
)
{
$src = $src -replace '\*$'
if (test-path $dest)
{
switch -regex ($src)
{
'\\$' {$src = "$src*"; break}
'\w$' {$src = "$src\*"; break}
default {break}
}
}
copy-item $src $dest -recurse -force
}
xCopy "C:\Source Folder\Location" "\\servername\foldershare\valid UNC path"
Save this to a script “xcopy.ps1” and then execute as a scheduled task:
powershell “c:\xcopy.ps1” -arguments
Thanks I tried this and it works a treat. I does not check if files are older than a certain date but it does not copy file across if they are already there and I can modify it myself.
Cheers
Steven
New to powershell (and scripting). Would appreciate knowing about how to implement the date checking for this script.
Thanks,
Shad
Add -verbose to the copy-file to get the information on the copy into the log.
Great tip – thanks Verena.