Invoke-Command and copy-item

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Mark Brown Mark Brown 1 year ago.

  • Author
  • #30774
    Profile photo of Mark Brown
    Mark Brown

    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?

  • #30779
    Profile photo of Cyril Muffat
    Cyril Muffat

    Just get rid of "*" in

    Copy-Item -Path C:\program files\software\BIN\* -Destination E:\sw_install\1\BIN_6.2\ -Recurse -Force 
  • #30781
    Profile photo of Mark Brown
    Mark Brown

    It really was that easy! Many Thanks!

You must be logged in to reply to this topic.