Mohsen Kokabi
Mohsen Kokabi

Reputation: 31

azure run command script to mount file storage

I have created VM which needs to download some files from Azure File Storage. I am looking for a way to automate this and I am trying the Azure VM Run command Script.

The first step CmdKey is all working fine but the next step which is:

net use Z: \\my123storageaccount.file.core.windows.net\databases /u:AZURE\my123storageaccount sskhgkghgkuytiytru...==

is failing with these messages.

When I login to that VM and run the command in PowerShell window it works without any error.

One thing that might help is the storage account name in the error is trimming the first letter the one I have. For instance, if it's called MyStorageAccount in the error it is saying yStorageAccount.file.core.windows.net

any help

Upvotes: 3

Views: 1765

Answers (4)

CivFan
CivFan

Reputation: 15112

For me, the issue was that, according to the Azure docs, "scripts run as System on Windows." So when you login as your normal user, that user doesn't have the credentials saved, and can't view the mounted drive contents.

To workaround this, you can use psexec (from the PSTools package) to run as your regular user. For example:

psexec.exe \\your-ip -u your-user -p your-pass cmdkey /add:...
psexec.exe \\your-ip -u your-user -p your-pass net use Z: \my123storageaccount.file.core.windows.net\databases /u:AZURE\my123storageaccount sskhgkghgkuytiytru...==

Note: Due to voodoo black magic, you have to use the form of psexec.exe \\your-ip rather than just psexec.exe as System user, or risk upsetting Billy Goates.

Upvotes: 1

Nancy Xiong
Nancy Xiong

Reputation: 28234

Update

On my side, I can download some files from Azure File Storage with Azure VM run command script.

The main steps are as follows:

  • Copy the script from my storage account-files-connect.

  • Paste the script to Azure virtual machine-run command-RunPowerShellScript-PowerShellScript.

enter image description here

According to this doc, Running a command requires the Microsoft.Compute/virtualMachines/runCommand/action permission, which the Contributor role and higher have. Please check this one your side.

Also, check the Azure VM Agent when logging into the Azure VM, look for a process name WindowsAzureGuestAgent.exe from Task Manager.

References: Azure Virtual Machine Agent overview

Upvotes: 0

Tim Tharratt
Tim Tharratt

Reputation: 1310

if you go to the storage account -> files you can copy the powershell commands you need to map the drive.

enter image description here

Upvotes: 0

Tim Tharratt
Tim Tharratt

Reputation: 1310

You can copy files like this. The powershell commands can be copied from Azure, using 'connect' from the context menu of the share in the Azure portal. If this doesn't work could be connectivity or may be SMB related

$buildSource = 'M:\build\'

$acctKey = ConvertTo-SecureString -String "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList 
"Azure\wserverBuild", $acctKey
New-PSDrive -Name M -PSProvider FileSystem -Root "\\wserverBuild.file.core.windows.net\build" -Credential $credential -Persist

Copy-Item  'M:\build\' -Destination 'C:build' -Recurse

Upvotes: 0

Related Questions