I have a connection string to an Azure Storage Share which looks like this:
DefaultEndpointsProtocol=https;
AccountName=myaccount;
AccountKey=xxx_LongEncryptedString_xxx;
EndpointSuffix=core.windows.net
Also, I have a Sharename like "MyShare
". In C#, I connect like this:
ShareClient share = new ShareClient(connectionString, "MyShare");
Question: I would like to connect this share to a Drive in Windows (10 / 11 Pro) with Powershell or cmd. How can I do this?
EDIT: I cannot login to the Azure portal. I have only the information as shown above.
How to connect an Azure Share to a Windows Drive Letter
You can use the below script to connect the Azure File Share to your windows with connection string using Powershell.
Script:
$connectionString = "DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxxxx;EndpointSuffix=core.windows.net"
$shareName = "share1" # Replace with your Azure File Share name
$driveLetter = "Z" # Desired drive letter
$connectionStringDict = @{}
$connectionString.Split(';') | ForEach-Object {
$key, $value = $_ -split '=', 2
$connectionStringDict[$key] = $value
}
$accountName = $connectionStringDict["AccountName"]
$accountKey = $connectionStringDict["AccountKey"]
$endpointSuffix = $connectionStringDict["EndpointSuffix"]
$fileSharePath = "\\$accountName.file.$endpointSuffix\$shareName"
# Test connectivity to port 445
Write-Host "Testing connectivity to $accountName.file.$endpointSuffix on port 445..."
$connectTestResult = Test-NetConnection -ComputerName "$accountName.file.$endpointSuffix" -Port 445
if ($connectTestResult.TcpTestSucceeded) {
Write-Host "Connection successful! Proceeding with drive mapping..."
# Save credentials for persistence
Write-Host "Saving credentials..."
cmd.exe /C "cmdkey /add:`"$accountName.file.$endpointSuffix`" /user:`"localhost\$accountName`" /pass:`"$accountKey`""
# Map the drive
Write-Host "Mapping drive $driveLetter to $fileSharePath..."
New-PSDrive -Name $driveLetter -PSProvider FileSystem -Root $fileSharePath -Persist
Write-Host "Drive mapped successfully! You can access it as ${driveLetter}:"
} else {
Write-Error -Message "Unable to reach $accountName.file.$endpointSuffix via port 445. Check your network configuration or consider using VPN or other tunneling options."
}
Output:
Testing connectivity to venkat326123.file.core.windows.net on port 445...
Connection successful! Proceeding with drive mapping...
Saving credentials...
CMDKEY: Credential added successfully.
Mapping drive Z to \\accountname.file.core.windows.net\share1...
Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
Z 1.05 102398.95 FileSystem \\accountname.file.core.windows...
Drive mapped successfully! You can access it as Z:
Reference: Mount Azure file share on Windows | Microsoft Learn