r/PowerShell • • 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.

5 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/Western-Rip-1559 Nov 26 '25

Thanks for the detailed explanation, I understand now.

In this case, the directory exists. Its a OneDrive backed up directory and should always be there.