Copy-Item error "network path not found"

Welcome Forums Web Site Feedback & Assistance Copy-Item error "network path not found"

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

 
Participant
6 months, 1 week ago.

  • Author
    Posts
  • #98409

    Participant
    Points: 0
    Rank: Member

    Hi,

    I try to use copy-item to copy file from one server to another server. Both of the servers are of the same subnet. But I get the error of "Network path not found".

    Code:
    $computers = Get-Content C:\CompList.txt
    $Computers | foreach{Copy-Item -Path C:\test.txt -Destination \\$_\D$\install}

    For your assistance, please. Thank you.

  • #98410

    Keymaster
    Points: 1
    Rank: Member

    Try a back tick in front of the second dollar sign. It's trying to read it as a variable. You need it to be a literal.

  • #98422

    Participant
    Points: 0
    Rank: Member

    Hi Don,

    Tried your suggestion:

    Code:
    $computers = Get-Content C:\CompList.txt
    $Computers | foreach{Copy-Item -Path C:\test.txt -Destination \\$_\D`$\install}

    got error still "network path not found".

  • #98436

    Participant
    Points: 15
    Rank: Member

    Literal strings should be quoted, to be sure they are read that way.
    Variable expansion of course is double quotes.

    ((Get-ADComputer -Filter *).Name)[7] | %{Get-ChildItem -Path "\\$_\c$\install"}
    
    ((Get-ADComputer -Filter *).Name)[7] | %{Copy-Item -Path 'C:\Temp\test.txt' -Destination "\\$_\c$\install" -WhatIf}
    
    What if: Performing the operation "Copy File" on target "Item: C:\Temp\test.txt Destination: \\WS01\c$\install\test.txt".
    
    ((Get-ADComputer -Filter *).Name)[7] | %{Copy-Item -Path 'C:\Temp\test.txt' -Destination "\\$_\c$\install"}
    
    ((Get-ADComputer -Filter *).Name)[7] | %{Get-ChildItem -Path "\\$_\c$\install"}
    
    
    
        Directory: \\WS01\c$\install
    
    
    Mode                LastWriteTime     Length Name                                                                                                             
    ----                -------------     ------ ----                                                                                                             
    -a---         1/25/2018   2:14 AM        542 test.txt 
    
  • #98455

    Participant
    Points: 0
    Rank: Member

    Hi postanote,

    the double " " won't work also.

    May I confirm that at the destination path the destination folder must be network share?

    $computers = Get-Content C:\CompList.txt
    $Computers | foreach{Copy-Item -Path C:\test.txt -Destination \\$_\D$\install}

    Thank you.

    Regards,
    Vincent

  • #98496

    Participant
    Points: 15
    Rank: Member

    Sound environmental on your side.
    As per my post back, these at the commands I ran in my lab and all worked as designed.
    The folder I user was not a network share name just a UNC to a folder I created on a remote system.
    Making it an network share, really should not matter, since as we know, a share name is by default the same name as the UNC folder name.
    You are using the default drive$ and a share folder in your post.

    So, are you saying that on that drive$, that, then install folder sharename as well?
    If so, then why use the drive$?
    You should only need the servername and the sharename.

    ((Get-ADComputer -Filter *).Name)[7] | %{Get-ChildItem -Path "\\$_\install"}
    
    
        Directory: \\WS01\install
    
    
    Mode                LastWriteTime     Length Name                                                                                                             
    ----                -------------     ------ ----                                                                                                             
    -a---         1/25/2018   2:14 AM        542 test1.txt                                                                                                        
    
    
    
    ((Get-ADComputer -Filter *).Name)[7] | %{Copy-Item -Path 'C:\Temp\test.txt' -Destination "\\$_\install" -WhatIf}
    
    What if: Performing the operation "Copy File" on target "Item: C:\Temp\test.txt Destination: \\WS01\install\test.txt".
    
    ((Get-ADComputer -Filter *).Name)[7] | %{Copy-Item -Path 'C:\Temp\test.txt' -Destination "\\$_\install"}
    
    ((Get-ADComputer -Filter *).Name)[7] | %{Get-ChildItem -Path "\\$_\install"}
    
    
        Directory: \\WS01\install
    
    
    Mode                LastWriteTime     Length Name                                                                                                             
    ----                -------------     ------ ----                                                                                                             
    -a---         1/25/2018   2:14 AM        542 test.txt                                                                                                         
    -a---         1/25/2018   2:14 AM        542 test1.txt    
    

The topic ‘Copy-Item error "network path not found"’ is closed to new replies.