Category filter

Script to backup files and folders on Windows devices

Windows 10 has a plethora of ways to back up and restore your data – File History, System Image Recovery, System Restore, just to name a few. However, if you’re someone who wants to doubly secure their data backups just to be on the safe side, you can also achieve the same by executing a custom script that’ll backup your data wherever you want. You’ll always have your data copied in a location of your choice.

Disclaimer:

The Sample Scripts provided below are adapted from third-party Open-Source sites.

Powershell script

  • The admin can pass the source and target directory parameters.
  • $src & $dest – Source and destination files to be entered as Arguments under Manage > Devices > (Chosen Device) > Actions > Execute Custom Script.
  • The Test-Path cmdlet determines whether all elements of the path exist. It returns $True if all elements exist and $False if any are missing. It can also specify whether the path syntax is valid and leads to a container, terminal or a leaf element.
  • Write-Host – Write-Host is a wrapper for Write-Information. This allows you to use Write-Host to emit output to the information stream. It also enables the capture or suppression of data written using Write-Host while preserving backward compatibility.
  • Remove-Item – deletes the specified items
  • Copy-Item – copies the specified items.
  • In the event that an older version of the file to be backed up exists, it will subsequently be deleted and replaced with the newer updated version. If not, a new file will be created in the target location to store the backed-up file.
Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository