使用net use通过az vm运行命令调用中的脚本映射本地驱动器时,Azure VM挂起 [英] Azure VM hangs when using net use to map a local drive by a script in az vm run-command invoke
问题描述
我一直在努力将azure fire share映射到我已经创建的azure Windows vm.使用net use命令通过RDP远程登录到vm之后,可以手动将文件共享映射到vm.但是,我需要使流程自动化,并希望 使用脚本来映射文件共享.我发现"az vm运行命令调用--command-id RunPowerShellScript"将允许我编写一个本地powerShell脚本config_decky.ps来完成此任务.
在测试文件共享的映射之前,我在vm上测试了本地映射. config_decky.ps中的内容如下:
$ serverName =燕麦测试装扮"
cmd/c净使用K: \\ $ serverName \ C $ \ WindowsAzure myPassword/user:$ serverName \ myUserName/persistent:是
在从本地Windows笔记本电脑运行此命令之前,我在azure vm(运行Windows Server 2016数据中心)上打开了端口445、139和135.在运行config_decky.ps之前,我成功运行了其他两个命令.
az vm运行命令调用--command-id EnableRemotePS
az vm运行命令调用--command-id EnableAdminAccount
但是,一旦我在config_decky.ps中运行以下命令,虚拟机就会挂起,并且我需要等待90分钟,即使在尝试远程登录Azure虚拟机之后,也要从任务管理器中删除net和RunCommandWindows.我也尝试停止并重新启动 来自Azure门户的vm.重新启动虚拟机大约需要90分钟.
az vm运行命令调用--command-id RunPowerShellScript \
b nbsp; bsp -资源组xxxx \
nbsp; b ; b -名称xxxx \
b nbsp; bsp -脚本"@ config_decky.ps"
知道发生了什么吗?感谢您的帮助!
注意: -脚本
脚本行由空格分隔.采用 @ {file} 以从文件中加载.
对于 Azure CLI :
az vm运行命令调用-g MyResourceGroup -n MyVm --command-id RunShellScript-脚本@filename
对于 Azure PowerShell :
Invoke-AzureRmVMRunCommand -ResourceGroupName'< myResourceGroup>' -名称'< myVMName>' -CommandId'RunPowerShellScript'-ScriptPath'< pathToScript>'
--------------- -------------------------------------------------- ------------------------------
如果此答案有帮助,请单击标记为答案"或向上" -投票".要提供有关您的论坛体验的其他反馈,请单击 在这里 >>
Hi,
I have been struggling with mapping azure fire share to an azure windows vm that I already created. I can manually map the file share to vm after remote login to vm through RDP, using net use command. However, I need to automate the process and would like to use a script to map the file share. I found out "az vm run-command invoke --command-id RunPowerShellScript" would allow me to write a local powerShell script – config_decky.ps to complete this task.
Before I tested the mapping of file share, I tested the local mapping on vm. The content in config_decky.ps is as follows:
$serverName = "uat-test-decky"
cmd /c net use K: \\$serverName\C$\WindowsAzure myPassword /user:$serverName\myUserName /persistent:yes
Before I ran this command from my local windows laptop, I opened port 445, 139 and 135 on azure vm (running windows server 2016 datacenter). I ran the other two commands successfully before running config_decky.ps.
az vm run-command invoke --command-id EnableRemotePS
az vm run-command invoke --command-id EnableAdminAccount
However, as soon as I ran the below command in config_decky.ps, the vm hangs and I need to wait for 90 minutes, even after I tried to remote login the azure vm, deleted the net and RunCommandWindows from task manager. I also tried to stop and restart the vm from azure portal. Restarting the vm will take close to 90 minutes.
az vm run-command invoke --command-id RunPowerShellScript \
--resource-group xxxx \
--name xxxx \
--scripts "@config_decky.ps"
Any idea what happened? Appreciate your help!
解决方案You may follow the following methods for achieving your scenario:
Note: --scripts
Script lines separated by whites spaces. Use @{file} to load from a file.
For Azure CLI:
az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts @filename
For Azure PowerShell:
Invoke-AzureRmVMRunCommand -ResourceGroupName '<myResourceGroup>' -Name '<myVMName>' -CommandId 'RunPowerShellScript' -ScriptPath '<pathToScript>'
-----------------------------------------------------------------------------------------------
If this answer was helpful, click "Mark as Answer" or "Up-Vote". To provide additional feedback on your forum experience, click here
这篇关于使用net use通过az vm运行命令调用中的脚本映射本地驱动器时,Azure VM挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!