首页 > 解决方案 > 在 Windows VM 中使用 VM 自定义扩展安装 Azure 文件时出现问题

问题描述

我在使用 Powershell 预配 VM 时尝试挂载 Azure 文件共享。共享确实显示了,但由于用户名或密码不正确而“断开连接”。如果我 RDP 进入服务器并自己运行脚本,则文件共享安装没有问题。以下是我在 powershell 脚本和 ARM TEMPLATE 扩展资源中使用的内容。

{
   "type": "Microsoft.Compute/virtualMachines/extensions",
   "apiVersion": "2019-07-01",
   "name": "[concat(parameters('virtualMachines_azvmtest_name'), '/newCustomScriptExtension')]",
   "location": "westus",
   "dependsOn": [
       "[concat('Microsoft.Compute/virtualMachines/',parameters('virtualMachines_azvmtest_name'))]"
   ],
   "properties": {
       "publisher": "Microsoft.Compute",
       "type": "CustomScriptExtension",
       "typeHandlerVersion": "1.9",
       "autoUpgradeMinorVersion":true,
       "settings": {

"fileUris": [
          "https://xyz.blob.core.windows.net/fileshare/fileshare.ps1#key is masked"


       ],
       "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File fileshare.ps1"
                },
"protectedSettings": {}
   }
 }

Below is the power shell code:

Invoke-Expression -Command ("cmdkey /add:`"XYZ.file.core.windows.net`" /user:`"Azure\XYZ`" /pass:`"KEY MASKED`"")
$password = ConvertTo-SecureString -String "KEY MASKED" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList "AZURE\XYZ", $password
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\XYZ.file.core.windows.net\abc"  -Credential $credential -Persist

扩展已成功配置,但我无法打开它显示为断开连接的已安装文件共享。

标签: azureazure-storagearm-templateazure-storage-account

解决方案


推荐阅读