Need help on Powershell Copy-Item from network drives Need help on Powershell Copy-Item from network drives powershell powershell

Need help on Powershell Copy-Item from network drives


This seems to work as is on PowerShell v3. I don't have v2 handy to test with, but there are two options that I'm aware of, which ought to work. First, you could map PSDrives:

New-PSDrive -Name source -PSProvider FileSystem -Root \\machine1\abc\123 | Out-NullNew-PSDrive -Name target -PSProvider FileSystem -Root \\machine2\c$\Logs | Out-NullCopy-Item -Path source:\log_1.zip -Destination target:Remove-PSDrive sourceRemove-PSDrive target

If this is something you're going to do a lot, you could even wrap this in a function:

Function Copy-ItemUNC($SourcePath, $TargetPath, $FileName){   New-PSDrive -Name source -PSProvider FileSystem -Root $SourcePath | Out-Null   New-PSDrive -Name target -PSProvider FileSystem -Root $TargetPath | Out-Null   Copy-Item -Path source:\$FileName -Destination target:   Remove-PSDrive source   Remove-PSDrive target}

Alternately, you can explicitly specify the provider with each path:

Copy-Item -Path "Microsoft.PowerShell.Core\FileSystem::\\machine1\abc\123\log 1.zip" -Destination "Microsoft.PowerShell.Core\FileSystem::\\machine2\\c$\Logs\"


this works all day for me:

$strLFpath = "\\compname\e$\folder"$strLFpath2 = "\\Remotecomputer\networkshare\remotefolder"  #this is a second option that also will work$StrRLPath = "E:\localfolder"  Copy-Item -Path "$StrRLPath\*" -Destination "$strLFpath" -Recurse -force -Verbose

things to watch:Copy-item define the LAST item as the object.for copying the content of a folder you NEED the \*

If you are copying the folder it self to a new location then you do not need to declare the content.