Forum Discussion
Azure VM can't connect to FileShare
Hi guys,
I am trying to connect an Azure VM (other subscription) to an Azure Storage Account (FileShare). I am using the "Enabled from selected virtual networks and IP addresses" and already add the public IP of the VM but when I try to map the File Share on Azure VM, I receive this error:
CMDKEY: Credential added successfully.
New-PSDrive : Access is denied
At line:5 char:5
+ New-PSDrive -Name Q -PSProvider FileSystem -Root "\\xxxxxxxx...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Q:PSDriveInfo) [New-PSDrive], Win32Exception
+ FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
If I permit all public connections everything works fine and I am able to map the FS also in an other VM that is in the same subscription and is permitted with VNET is able to connect too.
2 Replies
If the share works when the storage account allows all networks, the storage key and share itself are probably fine. The problem is most likely the storage firewall path.
For an Azure VM, do not rely only on adding the VM public IP to the storage account firewall. Use one of these patterns instead:
1. Enable the Microsoft.Storage service endpoint on the VM subnet and add that subnet to the storage account network rules.
2. Or create a private endpoint for the file subresource and make sure private DNS resolves the storage file endpoint to the private IP.
3. If the VM is in another subscription or tenant, configure the VNet rule with CLI/PowerShell if the portal cannot select it, or use a private endpoint.
Also verify outbound TCP 445 from the VM, NSGs, local Windows firewall, and any corporate firewall/NVA. If open network access works but selected networks fails, focus on service endpoint/private endpoint/DNS rather than the access key.
Below the step by step on setup: