r/PowerShell • u/Western-Rip-1559 • Nov 26 '25
Help with copy-item command
Hi,
(OS=Windows 10 Pro)
I have a PowerShell script that I set up years ago to copy the entire directory structure of a legacy windows program that has no native backup capability.
This script is triggered daily by a windows task scheduler event with the following action:
Program/script = Powershell.exe
arguments = -ExecutionPolicy Bypass -WindowStyle Hidden C:\PEM\copyPEMscript.ps1
The contents of copyPEMscript.ps1 is as follows:
Copy-Item -Path C:\PEM\*.* -Destination "D:\foo\foo2\PEM Backup" -Force -Recurse
Unfortunately, I didn't keep good enough notes. What I don't understand is, the script appears to be producing a single file in the foo2 directory, not the entire source directory structure I thought would be produced by the -Recurse flag.
What am I missing?
Thanks.
View all comments
Show parent comment
1
u/Western-Rip-1559 Nov 26 '25
I tried the modification and it works! Thank you.
What I still don't understand is, the source directory contains a number of files with extensions. It seems that the old *.* wildcard did not even copy those, which it seems it should have.