当我使用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
扩展名已成功配置,但无法打开显示为断开连接的已挂载文件共享。