2

I'm trying to add a network drive (azure file share) to an azure windows vm right after its creation. I want to automate it, so I use the Custom script extension but I'm getting some issues. The network drive is created for Azure FileShare. The below is the code that allows me to add the drive File Share:

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

Net Use

This script works fine when it is executed manually from the terminal and executing the script.ps1 file that contains this code. But it doesn't work when using Custom script extension, the drive appears as disconnected network drive (Z:)

Any idea?

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
Elias Arellano
  • 433
  • 5
  • 16

0 Answers0