I have an assignment where I have to write a powershell command on windows server 2019 that copies my documents folder to another folder called backups. my current script looks like this:
copy-item C:\Users\Administrator\Documents\ -destination C:Users\Administrator\Backups(get-date format "dd_mm_yyyy--hh_mm_ss")however, when I run the script it creates a folder in my backups folder but it doesn't have anything in it. what should I fix so it has all the files in my documents folder in this backups folder?
41 Answer
Tested. This code works. Taken from
[string]$sourceDirectory = "C:\Temp\Random_Folder"
[string]$destinationDirectory = "C:\Users\anyuser\Documents"
Copy-item -Force -Recurse -Verbose $sourceDirectory -Destination $destinationDirectory