PowerShell – Backup File Plan with OneDrive and task scheduler

  1. Setup OneDrive Account, set on your computer for syn purpose
  2. use powershell script (below) to copy target data into onedrive folder

 

PowerShell script to copy file into other file

#source: https://blog.csdn.net/zhang_ruisen/article/details/51038028
#https://www.pstips.net/
#
#

#Source_Path is string that from backup path folder
$Source_Path=”F:\Database\PassDatabase”

#Destination_Home is to backup path
$Destination_Home=”G:\OneDriverFolder\OneDrive\Database”
$Destination_Path=$Destination_Home+”\”+(Get-Date).ToString(“yyyyMMdd”)

#Test if destination if exsit, if no create new one
if(!(Test-Path -Path $Destination_Path))
{
New-Item -ItemType directory -Path $Destination_Path
}

#foreach copy, will run backup path folder and copy each file to the destination folder
foreach($Path in $Source_Path)
{
Copy-Item -Path $Path -Destination $Destination_Path -Recurse -Force
}

About: Raymond