[英]How to run a script on Azure VM from a remote machine
I'm looking for a way to run a script, on a single instance of a cloud service (which has several instances) from a remote machine. 我正在寻找一种从远程计算机在云服务的单个实例(具有多个实例)上运行脚本的方法。
I've tried DSC but that doesn't seem to support running the script only on one machine, as it would run it on all machines of the cloud service. 我已经尝试过DSC,但似乎不支持仅在一台计算机上运行脚本,因为它将在云服务的所有计算机上运行。
Note I'm using classic Azure cloud services. 注意我正在使用经典的Azure云服务。
Update: I specifically have an issue with Get-AzureVM which is part of the script example. 更新:我特别遇到了Get-AzureVM的问题,这是脚本示例的一部分。 How do I get the instance VM which is part of my cloud service. 我如何获得实例VM,它是我的云服务的一部分。 For instance I tried: 例如,我尝试过:
Get-AzureVM -ServiceName myCloudServiceName -Name instanceVMName
And that didn't return anything (I made sure to Add-AzureAccount first). 而且那没有返回任何东西(我确保首先添加Add-AzureAccount)。
I'm assuming it returns nothing because Get-AzureVM cannot be used for cloud services, and only for VMs. 我假设它什么也不返回,因为Get-AzureVM不能用于云服务,而只能用于VM。 I'm able to get the instance by running $dep = Get-AzureDeployment -ServiceName myCloudServiceName -Slot Production $dep.RoleInstanceList[0] Which returns role instance type which is different from the expected VM type. 我可以通过运行$ dep = Get-AzureDeployment -ServiceName myCloudServiceName -Slot Production $ dep.RoleInstanceList [0]来获取实例,该实例返回的角色实例类型与预期的VM类型不同。
Any ideas? 有任何想法吗?
Powershell Remoting in Azure Cloud Services Azure云服务中的Powershell远程处理
As you are using a single instance the above should do the trick, you will need to create the user as part of a startup script, otherwise it will disappear each time it recreates the VM. 当您使用单个实例时,上述方法可以解决问题,您需要将用户创建为启动脚本的一部分,否则,每次重新创建VM时,该用户都会消失。 It will not work if you every scale out to more than one instance of a cloud service. 如果您每个人都扩展到一个以上的云服务实例,它将无法正常工作。
You could use Custom Script extension for Windows virtual machines . 您可以对Windows虚拟机使用“ 自定义脚本”扩展 。 It supports run on a single VM. 它支持在单个VM上运行。
With the Custom Script extension for Windows, you can run PowerShell scripts on a remote VM without signing in to it. 使用Windows的“自定义脚本”扩展,您无需登录即可在远程VM上运行PowerShell脚本。 You can run the scripts after provisioning the VM, or at any time during the lifecycle of the VM without opening any additional ports. 您可以在配置VM之后或在VM生命周期内的任何时间运行脚本,而无需打开任何其他端口。 The most common use cases for running Custom Script extension include running, installing, and configuring additional software on the VM after it's provisioned. 运行自定义脚本扩展的最常见用例包括在配置VM后在VM上运行,安装和配置其他软件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.