PowerShell script is to automate the process of copying a file from a source directory to a destination directory
Purpose of the Script
The purpose of this PowerShell script is to automate the process of copying a file (abc.xlsx) from a source directory to a destination directory, ensuring that:
- The source file exists before attempting any further actions.
- The destination directory exists or is created if it doesn't.
- No overwriting of existing files occurs in the destination directory. If a file with the same name already exists, the script appends a numeric counter (-1, -2, etc.) to the filename to ensure that each copied file has a unique name.
- Safe file operations are ensured by checking for file existence and automatically generating a unique file name when necessary.
Main Use Case:
This script is useful when automating tasks like backing up files, copying reports, logs, or other documents, where the filenames may need to be adjusted based on the date or incremented to avoid conflicts with existing files.
It ensures that the latest copy of the file is always transferred to the destination directory without any risk of overwriting existing files.
In summary, this script is designed to automate the process of file copying, making it safe, efficient, and organized, especially in environments where files with the same name (but potentially different versions) need to be handled daily or periodically.
backupfile.ps1