3

I am currently writing a script that requires copying a file from another machine using a different credential

I followed the step here

Using PowerShell credentials without being prompted for a password

It didn't work for me, when I run Start-BitsTransfer the command prompt still complains that the file I need to copy does not exist

I noticed that if I try and browse the directory I want to copy from and enter the credential when prompted, I was able to copy the file from then on because the credential is somehow cached

I also noticed that the prompt I mentioned above look a bit different from the prompt I would have gotten using "Get-Credential" command

Not sure if that means anything. Anyway, why didn't the solution I found work for me? Any Ideas?

P.S.

Start-BitsTransfer -Source \\RemoteFS\RemoteFile -Destination . -Credential $fsCred

Start-BitsTransfer : Cannot find path '\\RemoteFS\RemoteFile' because it does not exist.
At line:1 char:1
+ Start-BitsTransfer -Source \\RemoteFS\RemoteFile -Destinatio ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (\\RemoteFS\RemoteFile:String) [Start-BitsTransfer], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.BackgroundIntelligentTransfer.Management.NewBitsTransferCommand

Note that, again, after I try and access \RemoteFS\RemoteFile in file explorer and got prompted for credential I was able to run the command just fine because the credential is cached I think

Community
  • 1
  • 1
user1763590
  • 117
  • 2
  • 14
  • Would you mind showing the command and error message? – jpmc26 Apr 29 '14 at 01:30
  • UNC path should start with two backslashes `\\RemoteFS\RemoteFile` – Cole9350 Apr 29 '14 at 19:48
  • A UNC path is a network path. If your remote session is executing on the same machine as the folder, it should use a local path, not a network path. Is the folder on the same machine as the remote session? If the folder is *not* on the same machine, could accessing the network folder require different credentials than the remote session has? @Cole9350 Looks like Markdown ate some slashes; there are double slashes once I put everything in a code block. – jpmc26 Apr 29 '14 at 21:19
  • @jpmc26 in powershell a unc path will work just as well as a local path. I figured it was just a copy mistake but the path doesn't make sense still. You can't share out an individual file on windows without it being in some sort of shared folder, so it would have to be more like `\\RemoteServer\RemoteFS\RemoteFile.file` – Cole9350 Apr 30 '14 at 14:07
  • @Cole9350 Right, UNC paths work, but if it's a local file, wouldn't that make the command unnecessarily pull the file from the network? That's what I meant about using a local path. If it's not local, though, the point about additional credentials is still valid. – jpmc26 Apr 30 '14 at 17:32
  • @Cole9350 I just tested a `cd` to a remote path I know exists but requires different credentials than I'm logged on as. I get a `Cannot find path ... because it does not exist` error. This makes sense. An accessed denied error would inform an attacker that they had found a directory that actually exists but they can't access; generally speaking, you would rather hide information like that from an attacker. Even HTTP allows for a 404 when you don't want to reveal whether the path exists or not. – jpmc26 Apr 30 '14 at 18:19
  • Ah yes that makes sense, I falsely assumed read access would be shared to everyone – Cole9350 Apr 30 '14 at 18:59
  • please try with Copy-item instead of Start-BitsTransfer, and report the the results – idarryl Jun 23 '14 at 16:30

1 Answers1

2

Why not the most elegant way, I would simply use "Net Use" and "Net Use /Delete". This definitely works, I'm using it to access a computer that is not part of my domain (during sysprep).

Start-BitsTransfer supports custom credentials, however we have run into few different issues while testing it (I don't remember the details, but good old Net Use work working perfectly for our needs).

Martin

Martin Zugec
  • 165
  • 1
  • 7