title: NET USE only works once in powershell
body: <p>My requirement is to connect to a remote computer, copy files with the extension of <code>.TRA</code> to a different remote computer.</p>
  
  <p>Now my difficulty arises in that the source machine aren't on the domain so I need to connect with alternate credentials. </p>
  
  <p>My first sticking point is trying to use <code>New-PSDrive</code>. It doesn't appear to allow me to pass stored credentials. I have tried various versions of this:</p>
  
  <pre><code>$cred = Get-Credential
  New-PSDrive -NAME Z: -PSprovider Filesystem -root \\Computer\Exchange -credentials $cred
  </code></pre>
  
  <p>and I get an error</p>
  
  <blockquote>
    <p>The provider does not support the use of credentials. Perform the operation again without specifying credentials.</p>
  </blockquote>
  
  <p>This appears to be a bug (see halr9000's comment here : <a href="https://stackoverflow.com/questions/303045/connecting-to-a-network-folder-with-username-password-in-powershell">Connecting to a network folder with username/password in Powershell</a>)</p>
  
  <p>My alternative was to use <code>NET USE</code>, which works fine but only once.</p>
  
  <p>In the full script below I map to 8 different machines. The first of these works. After that any attempt to use <code>NET USE</code> (or <code>New-Object WScript.NETWORK</code>, mentioned as a work around on the Technet article linked above) fails. Or rather it doesn't fail. </p>
  
  <p>Its creates a mapped drive, which I can see if I type <code>NET USE</code>, or if I look in explorer (and its browsable). But I cannot connect to that drive in Powershell. Its like it doesn't exist, <code>Test-Path Z:</code> returns False. Right up until I run <code>NET USE Z: /D</code> which successfully deletes the drive.</p>
  
  <p>Can someone please help me with one or other of my issues please? Don't make me do this in DOS!</p>
  
  <p>Full script :</p>
  
  <pre><code>$int = 0
  $arrStagePC = "BOX42", "BOX43", "BOX44", "BOX45", "BOX46", "BOX47", "BOX48", "BOX49" 
  $arrData = "0848","5144","5292","5383","2158","2646","0061","2331"
  Foreach($strComp in $arrStagePC)
      {
      $arr = $arrData[$int]
      $comp = $strComp
      net use z: \\$arr\Exchange /user:admin password
      Copy-Item z:\*$date.tra \\$comp\Export$
      net use z: /d
      $int++
      }
  </code></pre>
  
  <p><strong>EDIT</strong>
  Have a look at @Christians accepted answer below. I didn't actually need to Get-Content that folder, I just needed to copy data from the source so the bit of the script doing the business on there now looks like :</p>
  
  <pre><code>Foreach($strComp in $arrStagePC)
          {
          $arr = $arrData[$int]
          $comp = $strComp
          net use z: \\$arr\Exchange /user:admin password
          Copy-Item FILESYSTEM::Z:\*.TRA \\$comp\Export$
          net use z: /d
          $int++
          }
  </code></pre>