Powershell xcopy for file backup

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

4 thoughts on “Powershell xcopy for file backup

Add yours

  1. 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.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

A WordPress.com Website.

Up ↑

%d bloggers like this: