05 November,2019 by Tom Collins
Question : I'm attempting to use Powershell copy-item , to copy a file from a remote location onto a local drive. This is the code I'm executing :
Copy-Item \\myremotelocation\servers.csv \\mylocaldrive\temp
The problem I'm getting is a "denied" type of error:
Copy-Item : Access to the path ' \\mylocaldrive\temp\servers.csv ' is denied.
At line:1 char:1
+ Copy-Item - \\myremotelocation\servers.csv...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (\\myremotelocation...servers.csv:FileInfo) [Copy-Item], Unauthorized
AccessException
+ FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
I can copy the file manually i.e outside of the Powershell environment and I am using the same logon for both the Powershell console and the manual drag and drop.
How can I fix this issue?
Answer: Based on the error message - you are missing using the -Force parameter . The error message can be misleading . The error message refers to a path being denied - whereas the message in these circumstances means the item cannot be replaced.
There is a full list of parameters if you use - help copy-file -full .
Test this out by changing your code to :
Copy-Item -Force \\myremotelocation\servers.csv \\mylocaldrive\temp
If you would like to know how to dig into Powershell read - Expand your Powershell mind – Three key cmdlets
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |