Author Posts

October 14, 2015 at 2:48 am

I am trying to copy files on a remote machine to another location on the same machine, effectively a backup. I build the source and destination paths from various bits of data, and use Invoke-Command to complete the action from a remote machine. From the command line, everything works.
But from within a scrip:
Invoke-Command -ComputerName Server6 { Copy-Item -Path C:\program files\software\BIN\* -Destination E:\sw_install\1\BIN_6.2\ -Recurse -Force }
Container cannot be copied onto existing leaf item.
+ CategoryInfo : InvalidArgument: (C:\program file...BIN\Plugins:String) [Copy-Item], PSArgumentException
+ FullyQualifiedErrorId : CopyContainerItemToLeafError,Microsoft.PowerShell.Commands.CopyItemCommand

The files are all copied, but the sub folders and their contents are not.

What do I need to do?

October 14, 2015 at 3:54 am

Just get rid of "*" in

Copy-Item -Path C:\program files\software\BIN\* -Destination E:\sw_install\1\BIN_6.2\ -Recurse -Force 

October 14, 2015 at 4:04 am

It really was that easy! Many Thanks!