Replace shared network drive with Azure Fileshare

Raj D 581 Reputation points
2022-04-21T16:25:30.18+00:00

Greetings!!!

We are planning to replace the on-premise shared network drive with an Azure Fileshare. For instance if we have a file on on-premise shared network drive and the UNC path is "\onpremshare\datashare\path\test.txt", Now, We would like to replace this path to an Azure Fileshare and the UNC path would be "\azurefileshare.file.core.windows.net\datalakeshare\path\test.txt".

I run the below Powershell script using the SMB protocol

$connectTestResult = Test-NetConnection -ComputerName azurefileshare.file.core.windows.net -Port 445
if ($connectTestResult.TcpTestSucceeded) {
    # Save the password so the drive will persist on reboot
    cmd.exe /C "cmdkey /add:"azurefileshare.file.core.windows.net" /user:"localhost\azurefileshare" /pass:"jshdahdfhhdhcuhkey""
    # Mount the drive
    New-PSDrive -Name Z -PSProvider FileSystem -Root "\\azurefileshare.file.core.windows.net\datalakeshare" -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."
}

This approach works on my machine but when I try to replace the file path in my application code I run into error saying the specified path does not exist. I'm not sure on how to make this change global as long as the users or the application has access control to the Azure Fileshare. Is there a way for applications or others to connect to it without having to key in user name and password. Similar to how we access the on-premise shared network drive as long as one has rights.

Also, Is there a way to write this code in C#?

Could you please point me in the right direction.

Thank you

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,160 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,223 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,359 questions
{count} votes