0

I am just starting with PowerShell, so please be kind.

All I want to do is backup my directories and files from my laptop to the desktop computer, i.e. "server", using PowerShell and robocopy. I am the administrator to both machines (Windows 7).

This fails with access denied on the "server", i.e., desktop, despite the permissions being set for "Everybody" to do everything.

Any help (or better way) is really appreciated! Thanks.

$cred=get-credential

$sourcepath = ("\\localhost\C$\nova5");
$TargetPath = ("\\library\E$\nova5");


New-PSDrive -Name source -PSProvider FileSystem -Root $SourcePath 
New-PSDrive -Name target -PSProvider FileSystem -Root $TargetPath -Credential $cred

robocopy source target /e;

return;
Alan Wayne
  • 5,122
  • 10
  • 52
  • 95

2 Answers2

2

Psdrive is a feature for powershell cmdlet not for extrrnal command , change this line:

robocopy "\\localhost\C$\nova5" "$TargetPath" /e
walid toumi
  • 2,172
  • 1
  • 13
  • 10
  • Thanks. What is the difference between \\localhost\C$ and \\localhost\C -- no "$" ??? robocopy does not seem to handle C$. – Alan Wayne Oct 16 '14 at 14:00
  • The trick here is to use the original UNC path(s) for Robocopy, and it will still somehow use the credentials "stored" in the session by `New-PSDrive`. Somewhat hackish, but still cleaner and more secure this way than using `New-PSDrive -Name 'X' -Persist ...` or `net use X: ...`. – argonym Sep 01 '20 at 11:35
0

You could try this:

$cred=get-credential

$sourcepath = C:\nova5 ;
$TargetPath = "\\library\E$\nova5"

New-PSDrive -Name target -PSProvider FileSystem -Root $TargetPath -Credential $cred

.\robocopy.exe $source $target "/e"
Miriam Farber
  • 18,986
  • 14
  • 61
  • 76