Example of Mapping to an Azure Drive Using PowerShell

Below is an example of a PowerShell script that maps to an Azure share. It first checks to see if it can see the server (IE: eu2windowshare.file.core.windows.net) then proceeds with storing credentials into credential manager before proceeding to map a drive to the Azure share.

$connectTestResult = Test-NetConnection -ComputerName eus2windowshare.file.core.windows.net -Port 445

if ($connectTestResult.TcpTestSucceeded) {
# Save the password so the drive will persist on reboot
cmd.exe /C “cmdkey /add:`”eus2windowshare.file.core.windows.net`” /user:`”localhost\eus2usernameforshare`” /pass:`”Z==eresheh3353yhfb5u2rthdfg62==`””

# Mount the drive
New-PSDrive -Name Z -PSProvider FileSystem -Root “\\eus2windowshare.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.”
}

Leave a Reply

Your email address will not be published. Required fields are marked *