Replace shared network drive with Azure Fileshare
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