將 Azure VM 上的磁碟機對應到 Azure 儲存體帳戶檔案共用

將 Azure VM 上的磁碟機對應到 Azure 儲存體帳戶檔案共用

我已經設定了 Azure 儲存帳戶檔案共用(具有專用端點),並嘗試按照以下步驟將網路位置對應到同一虛擬網路中的我的虛擬機器(未加入網域)女士文章

我試圖在使用者登入時透過在 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp 資料夾中放​​置包含下列程式碼的批次檔來指派此網路位置。

net use z: /delete
net use z: "\\{myaccount}.file.core.windows.net\{myfileshare}"

當以本機管理員帳戶登入時,它可以建立網路位置,但是當我嘗試在使用者帳戶下執行相同操作時,它會失敗並出現錯誤55:指定的網路資源或設備不再可用錯誤。

我假設這是本地權限問題,任何人都知道解決此問題的正確權限。

答案1

看起來很像權限問題,我首先使用以下專門用於對 Azure 檔案進行故障排除的腳本:https://github.com/Azure-Samples/azure-files-samples/tree/master/AzFileDiagnostics/Windows

它會自動執行本文提供的大部分故障排除步驟,這也非常有幫助 https://learn.microsoft.com/en-us/troubleshoot/azure/azure-storage/files-troubleshoot?tabs=powershell

答案2

因此,我採取了稍微不同的方向來實現這一目標。透過檔案共用連接按鈕使用 Azure 入口網站提供的腳本並不總是將共用建立為新PSDrive即使使用 -Persist 選項,函數似乎也不會建立持久映射。

我將 New-PSDrive 命令切換為 Net Use,並建立了 Windows 任務計劃,以便在登入和解鎖時為所有使用者運行該腳本,其工作效果非常好。

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

相關內容