title: Drive Mapping with Azure Scale Sets using Desired State Configuration
body: <p>I am running into an interesting issue. Maybe you fine folks can help me understand what's happening here. If there's a better method, I'm all ears.</p>
  
  <p>I am running a DSC Configuration on Azure and would like to map a drive. I've read this really isn't what DSC is for, but I am not aware of any other way of doing this outside of DSC with Azure Scalesets. Here's the portion of the script I am running into issues:</p>
  
  <pre><code>Script MappedDrive
      {
          SetScript = 
          {
          $pass = "passwordhere" | ConvertTo-SecureString -AsPlainText -force
          $user = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "username",$pass
          New-PSDrive -Name W -PSProvider FileSystem -root \\azurestorage.file.core.windows.net\storage -Credential $user -Persist
          }
          TestScript = 
          {
              Test-Path -path "W:"
          }
          GetScript = 
          {
          $hashresults = @{}
          $hashresults['Exists'] = test-path W:
          }
      }
  </code></pre>
  
  <p>I've also attempted this code in the SetScript section:</p>
  
  <pre><code>(New-Object -ComObject WScript.Network).MapNetworkDrive('W:','\\azurestorage.file.core.windows.net\storage',$true,'username','passwordhere')
  </code></pre>
  
  <p>I've also tried a simple net use command to map the drive instead of the fancy, New-Object or New-PSDrive cmdlets. Same behavior.</p>
  
  <p>If I run these commands (New-Object/Net Use/New-PSDrive) <strong>manually</strong>, the machine will map the drive if I run it with a separate drive letter. Somehow, the drive is attempting to be mapped but isn't mapping. </p>
  
  <p>Troubleshooting I've done:</p>
  
  <ul>
  <li>There is no domain in my environment. I am simply attempting to create a scale set and run DSC to configure the machine using the storage account credentials granted upon creation of the storage account.</li>
  <li>I am using the username and password that is given to me by the Storage Account user id and access key (randomly generated key, with usually the name of the storage account as the user). </li>
  <li>Azure throws no errors on running the DSC module (No errors in Event Log, Information Only - Resource execution sequence properly lists all of my sequences in the DSC file.)</li>
  <li>When I log into the machine and check to see if the drive is mapped, I run into a disconnected network drive on the drive letter I want (W:).</li>
  <li>If I open Powershell, I receive an error: "Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed."</li>
  <li>If I run "Get-PSDrive" the W: drive does not appear.</li>
  <li>If I run the SetScript code manually inside a Powershell Console,  the mapped drive works fine under a different drive letter.</li>
  <li>If I try to disconnect the W: drive, I receive "This network connection does not exist."</li>
  <li>I thought maybe DSC needed some time before mapping and added a Sleep Timer, but that didn't work. Same behavior.</li>
  </ul>