Invoke-Command and copy-item

Welcome Forums General PowerShell Q&A Invoke-Command and copy-item

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 years, 1 month ago.

  • Author
    Posts
  • #30774

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    Just get rid of "*" in

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

    Participant
    Points: 0
    Rank: Member

    It really was that easy! Many Thanks!

The topic ‘Invoke-Command and copy-item’ is closed to new replies.