Powershell copy-item replaced a directory with a file
12:17 24 Nov 2025

I'm using a command similar to the one below to copy a file to a directory:

copy-item 'C:\some\source\directory\filename.txt' -Destination 'T:\some\destination\dir'

C:\ is local disk. T:\ is a mounted NTFS shared drive.

When I do this, most times it works fine and the 'filename.txt' file becomes a new file in the 'dir' directory.

However, sometimes the behavior is different. The 'dir' directory is completely deleted and replaced with a 'dir' file which has the same contents as filename.txt.

Can't figure out what would cause the change in behavior sometimes.

Thoughts? Thanks in advance for any help.

powershell file-copying copy-item