[Azure DSC] Scale Sets Mapped Drives

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.

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:

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:
			}
		}

I’ve also attempted this code in the SetScript section:

<pre>(New-Object -ComObject WScript.Network).MapNetworkDrive('W:','\\azurestorage.file.core.windows.net\storage',$true,'username','passwordhere')</pre>

Troubleshooting I’ve done:

    * 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. * 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). * 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.) * 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:). * If I open Powershell, I receive an error: "Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed." * If I run "Get-PSDrive" the W: drive does not appear. * If I run the SetScript code manually inside a Powershell Console, the mapped drive works fine under a different drive letter. * If I try to disconnect the W: drive, I receive "This network connection does not exist."

Yeah, it really isn’t what DSC is for ;). I’m not sure Azure is trying to solve this problem space, either.

Drives are only mapped in a user context, and the LCM doesn’t run in a user context. So I’m not even sure this would be something DSC could do. You’re seeing it work when you’re logged on, because THEN there’s a user context.