1

I have the following script:

New-PSDrive -Name X -PSProvider FileSystem -Root "$DeployLocation" -Credential $credentials
New-PSDrive -Name K -PSProvider FileSystem -Root "$autobuildSourceFiles" -Credential $credentials

When this runs, the first drive maps correctly, but the second one fails with the following error:

InvalidOperation: The specified network password is not correct

This is really a confusing error, because I pass in the exact same $credentials object for both calls. If one of them works, then I do not see how the password can be incorrect.

In case it is relevant, the variables look like this:

$DeployLocation = "\\dev-server\DevFiles\Technical\MyProjectNameHere"
$autobuildSourceFiles = "\\mainshare\build`$\Technical\MyProjectNameHere\1.0.0.94"

The user in the $credentials variable has read and write permissions to $DeployLocation and read-only permissiosn to $autobuildSourceFiles. But I don't see how that would cause a password error.

Things I have tried:

  • Swapping the order of the calls (to ensure that there is not an issue with making more than one PSDrive). When I swap the order, the same one (drive "K") fails.
  • Changing the drive letter. (I tried "Y" as well)
  • Using the exact same text for the command that does work, but substituting the path that does not. (It still failed).

Note: I am using Powershell Version 5.1.14393.5127 on Windows.

What could be causing this error, and how can I work around it?

Vaccano
  • 78,325
  • 149
  • 468
  • 850
  • Are both shares in the same server or different servers? Is the `$credentials` local or AD? – Santiago Squarzon Jun 22 '23 at 23:09
  • For remote computers to recognize a credential they must be in the same group and use the same password server(s). A network drive is mounted on a Server and to mount a drive you need the server to recognize the credentials and you have to have permission on the server to access the drive/folder – jdweng Jun 22 '23 at 23:20
  • $autobuildSourceFiles value includes `$`, which has special meaning in PowerShell. You have to replace `"` with `'`. I.e. `$autobuildSourceFiles = '\\mainshare\build$\Technical\MyProjectNameHere\1.0.0.94'`, instead of `$autobuildSourceFiles = "\\mainshare\build$\Technical\MyProjectNameHere\1.0.0.94"` – MikeSh Jun 23 '23 at 02:07
  • @SantiagoSquarzon - Different servers. The `$credentials` are AD creds. – Vaccano Jun 23 '23 at 18:05
  • @MikeSh - Yeah, I did that in my actual code. When I put it in the question, I was copy/pasting in actual values so I lost the back tick. I will update the question with the back tick. – Vaccano Jun 23 '23 at 18:06
  • @Vaccano, have you tried my suggestion? I.e. 'aaa$bbb' instead of "aaa`$bbb"? – MikeSh Jun 26 '23 at 23:12
  • @MikeSh - Yes. Sadly I got the same error. – Vaccano Jun 28 '23 at 00:03

0 Answers0