I'm trying to make an automation to map a network drive to an Azure virtual machine. But it always returns the same error.
From the run-command functionality using RunPowershellScript I have executed several scripts, which finish correctly.
But then inside the virtual machine I always get the following error:
Apart from the powershell scripts that Azure provides you, the PowerShell scripts that I have executed from run-command with the same result are:
cmd.exe /C "cmdkey /add:`"sta.file.core.windows.net`" /user:`"localhost\username`" /pass:`"pass1`""
New-PSDrive -Name J -Root "\\storageAccount\share" -Credential $cred -PSProvider filesystem -Scope Global
New-StoredCredential -Target test -UserName username -Password pass1 -Comment "test" -Persist Enterprise
$cred = New-Object System.Management.Automation.PSCredential (Get-StoredCredential -Target test)
New-PSDrive -Name J -Root "\\storageAccount\share" -Credential $cred -PSProvider filesystem -Scope Global
cmd.exe /C "cmdkey /add:`"sta.file.core.windows.net`" /user:`"localhost\username`" /pass:`"pass1`""
net use Q: \\storageAccount\share /savecred /persistent:yes
Out of curiosity, after researching, I realized that credentials are only created at the run-command level.
In the first image we have the output of the cmdkey /list executed in the VM and in the second image executed in the run-command. The same thing also happens with the Get-StoredCredential, the credential that I created from the run-command cannot be seen within the VM. And it should also be noted that the other way around does work, that is, I do see the credentials that I create in the VM from the run-command.
Please I need help.
Does anyone know what is happening? Does anyone know what I'm doing wrong? Has anyone else tried to do this and succeeded?

