Unable to connect Azure file share from powershell

Amit Mohanty 60 Reputation points
2024-04-27T14:05:06.7933333+00:00

Hi Team,

I have created a file share named as share inside a storage account and uploaded a file .

When i am trying to connect from windows using windows connect script in powershell its giving below error

PS C:\WINDOWS\system32> $connectTestResult = Test-NetConnection -ComputerName app27apramitv1.file.core.windows.net -Port 445 PS C:\WINDOWS\system32> if ($connectTestResult.TcpTestSucceeded) {

# Save the password so the drive will persist on reboot
cmd.exe /C "cmdkey /add:`"app27apramitv1.file.core.windows.net`" /user:`"localhost\app27apramitv1`" /pass:`"UOlKyeSgvIFGdoVEHCPJfx782SR1CtCidJjR/mlZZFfZ+nglcMWdM3+O4obR2GRDUq/2gJRnQ99a+ASthTwEuw==`""
# Mount the drive
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\app27apramitv1.file.core.windows.net\share" -Persist

} else {

Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to make sure your organization or ISP is not blocking port 445, or use Azure P2S VPN, Azure S2S VPN, or Express Route to tunnel SMB traffic over a different port."

}

CMDKEY: Credential added successfully.

New-PSDrive : The network resource type is not correct

At line:5 char:5

  • New-PSDrive -Name Z -PSProvider FileSystem -Root "\\app27apramitv ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (Z:PSDriveInfo) [New-PSDrive], Win32Exception
    • FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand

PS C:\WINDOWS\system32>

Please help to fix this issue .

Thanks & Regards,

Amit Mohanty

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,170 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,723 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Patchfox 3,786 Reputation points
    2024-04-27T17:33:34.7766667+00:00

    Hi Amit Mohanty, I want to help you with this question.

    As the PowerShell error says, you can't reach the File Share via port 445.

    Many ISPs don't allow this port to be used by default.

    Please test with the Cmdlet

    Test-NetConnection -Port 445

    if your IPS blocks the Port. If the response is "FALSE", your ISP may blocks the port.

    Please verify that your client OS supports SMB 3.0. Make sure this SMB Direct option is enabled in your Windows system.

    Another way to troubleshoot "File share" access, check out this repo:

    https://github.com/Azure-Samples/azure-files-samples/tree/master/AzFileDiagnostics/Windows

    I hope this will help you to solve your problem.


    If the reply was helpful, please don’t forget to upvote or accept it as an answer, thank you!

    0 comments No comments

  2. Anand Prakash Yadav 6,150 Reputation points Microsoft Vendor
    2024-04-29T05:48:03.3133333+00:00

    Hello Amit Mohanty,

    Thank you for posting your query here!

    Please check if your firewall or ISP is blocking port 445, use the AzFileDiagnostics tool or Test-NetConnection cmdlet.

    Azure Files only allows connections using SMB 3.0 (with encryption support) from outside the region or datacenter. SMB 3.0 protocol has introduced many security features including channel encryption which is very secure to use over internet. However, it's possible that port 445 has been blocked due to historical reasons of vulnerabilities found in lower SMB versions. In ideal case, the port should be blocked for only for SMB 1.0 traffic and SMB 1.0 should be turned off on all clients.

    If you have ever been blocked using Azure Files due to your ISP's port 445, you can setup a Point to Site VPN to your Azure Files. Refer to the suggestions mentioned in the GitHub article

    You can mount the file share on your local machine by using the SMB 3.0 protocol, or you can use tools like Storage Explorer to access files in your file share. From your application, you can use storage client libraries, REST APIs, PowerShell, or Azure CLI to access your files in the Azure file share.

    You can use Azure File Sync to access your Azure file share. https://learn.microsoft.com/en-us/azure/storage/file-sync/file-sync-deployment-guide?tabs=azure-portal%2Cproactive-portal

    Also, please make sure that the storage account key is not incorrect or expired.

    You can also use AzFileDiagnostics and SmbClientLogs scripts for Windows to detect common issues. 

    Please let us know if you have any further queries. I’m happy to assist you further.


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments