我正在使用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)每次重新启动系统时自动修复此问题的最简单方法是什么?
答案 0 :(得分:1)
请参考文档here,以在Windows中保留Azure文件共享凭据:
通过cmdkey实用程序,您可以在Windows中存储存储帐户凭据。这意味着,当您尝试通过其UNC路径访问Azure文件共享或挂载Azure文件共享时,无需指定凭据。要保存存储帐户的凭据,请运行以下PowerShell命令,并在适当的地方替换
<your-storage-account-name>
和<your-resource-group-name>
。
$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)")
您可以使用list参数来验证cmdkey实用程序是否已存储存储帐户的凭据:
cmdkey /list
如果成功存储了Azure文件共享的凭据,则预期输出如下(列表中可能存储了其他密钥):
Currently stored credentials:
Target: Domain:target=<storage-account-host-name>
Type: Domain Password
User: AZURE\<your-storage-account-name>
您现在应该能够挂载或访问共享,而不必提供其他凭据。