Azure 文件存储映射到 Win10,因为网络驱动器在重启后请求登录

Azure file storage mapped to Win10 as network drive requests login after reboot

我正在使用 Azure 文件存储,并已将该存储映射为物理 Windows 10 PC 上的网络驱动器 U。我使用 PowerShell 安装它:

net use U: \exampleaccount.file.core.windows.net\filesharename /u:AZURE\exampleaccount AzureAccessKey /persistent:Yes

但是,每次我重新启动 PC 时,网络驱动器都会要求我输入与存储帐户关联的凭据。

1) Windows 不存储最初用于映射驱动器的 AzureAccessKey 密钥吗?

2) 每次系统重新启动时自动修复此问题的最简单方法是什么?

请参阅文档 here 以在 Windows 中保留 Azure 文件共享凭据:

The cmdkey utility allows you to store your storage account credentials within Windows. This means that when you try to access an Azure file share via its UNC path or mount the Azure file share, you will not need to specify credentials. To save your storage account's credentials, run the following PowerShell commands, replacing <your-storage-account-name> and <your-resource-group-name> where appropriate.

$resourceGroupName = "<your-resource-group-name>"
$storageAccountName = "<your-storage-account-name>"

# These commands require you to be logged into your Azure account, run Login-AzAccount if you haven't
# already logged in.
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$storageAccountKeys = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName

# The cmdkey utility is a command-line (rather than PowerShell) tool. We use Invoke-Expression to allow us to 
# consume the appropriate values from the storage account variables. The value given to the add parameter of the
# cmdkey utility is the host address for the storage account, <storage-account>.file.core.windows.net for Azure 
# Public Regions. $storageAccount.Context.FileEndpoint is used because non-Public Azure regions, such as sovereign 
# clouds or Azure Stack deployments, will have different hosts for Azure file shares (and other storage resources).
Invoke-Expression -Command ("cmdkey /add:$([System.Uri]::new($storageAccount.Context.FileEndPoint).Host) " + `
"/user:AZURE$($storageAccount.StorageAccountName) /pass:$($storageAccountKeys[0].Value)")

You can verify the cmdkey utility has stored the credential for the storage account by using the list parameter:

cmdkey /list

If the credentials for your Azure file share are stored successfully, the expected output is as follows (there may be additional keys stored in the list):

Currently stored credentials:

Target: Domain:target=<storage-account-host-name>
Type: Domain Password
User: AZURE\<your-storage-account-name>

You should now be able to mount or access the share without having to supply additional credentials.