How to create PSDrive using credentials?
<p>When I connect to shared "\\ip_address\" folder without using credentials I connect successfully:</p>

<pre><code>$driveInfo = New-PSDrive `
  -Name $driveName `
  -PSProvider "FileSystem" `
  -Root $targetDirectory `
  -Scope "Script"
</code></pre>

<p>When I specify credentials for this command:</p>

<pre><code>$driveInfo = New-PSDrive `
  -Name $driveName `
  -PSProvider "FileSystem" `
  -Root $targetDirectory `
  -Credential (Get-Credential) ` # Now ask credentials from user.
  -Scope "Script"
</code></pre>

<p>I get error:</p>

<blockquote>
  <p>System.ComponentModel.Win32Exception (0x80004005): The network path
  was not found</p>
</blockquote>

<p>What does this error mean?<br>
How can I ask credentials from user and use them to map the remote shared folder?</p>

<hr>

<p>OS: Windows 10<br>
PSVersion: 5.0.10586.672<br>
BuildVersion: 10.0.10586.672<br>
CLRVersion: 4.0.30319.42000<br>
WSManStackVersion: 3.0<br>
PSRemotingProtocolVersion: 2.3<br>
SerializationVersion: 1.1.0.1</p>

<hr>

<p>The following command is good:  </p>

<pre><code>New-PSDrive -Name "test" -PSProvider FileSystem -Root "\\server.ru\"
</code></pre>

<p>The following command is bad:  </p>

<pre><code>New-PSDrive -Name "test" -PSProvider FileSystem -Root "\\server.ru\" -Credential (Get-Credential)
</code></pre>