Here is a Powershell script that uses Robocopy to copy a user profile or any directory to the specified destination.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$source = "C:\Users\username\"
$timefolder='yyyy-MM-dd'
$destname = (Get-Date).ToString($timefolder)
$destination = "\\DESTINATION\$destname\"
 
$timeformat='yyyy-MM-dd hh:mm:ss tt'
$time = (Get-Date).ToString($timeformat)
 
$dircheck = Test-Path $source
 
#Creating Log File
$time + "Creating Log" | Out-File log.txt
 
#Checks if source exists
if($dircheck -eq $true) {
    Write-Host "Backing up $source"
    $time + "Starting Backup" | Out-File log.txt
    ROBOCOPY $source $destination /COPYALL /SEC /MIR /S /E /W:3 /A-:SH| Out-file log.txt -Append
}
else {
    $time + "Source does not exist" | Out-File log.txt -Append
    Write-Host "Source does not exist!"
}