简体   繁体   English

如何从远程计算机在Azure VM上运行脚本

[英]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上运行,安装和配置其他软件。

More information please refer to this link . 更多信息请参考此链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何连接到Azure Windows VM并使用PowerShell运行远程脚本? - How Connect to a Azure Windows VM and run a remote script with PowerShell? 从订阅中的其他VM定期在Azure虚拟机上定期运行Power-Shell脚本的最佳方法 - Best way to periodically run power-shell script on Azure Virtual Machine from other VM inside subscription 如何使用 Powershell 从我的本地计算机在 Azure Windows 虚拟机 (VM) 中运行“sysprep /generalize”? - How to run "sysprep /generalize” in Azure Windows Virtual Machine (VM) from my local machine using Powershell? 如何使用 C# 运行空间从本地计算机读取 Azure VM 中存在的远程 yaml 文件 - How to read remote yaml file present in Azure VM from local machine using C# Runspace 如何从 C# 中的 PowerShell 脚本运行 Azure 虚拟机 - How to run Azure virtual machine from PowerShell script in C# 如何在Azure VM上同时运行2个VM自定义脚本扩展 - How to run a 2 VM custom script extensions on Azure VM at the same time 从VM内部如何识别是AWS机器还是Azure机器? - From within a VM how to idenitfy whether it is an AWS machine or an Azure machine? 如何在远程Azure Win VM上复制文件并运行命令? - How to copy files & run commands on remote Azure Win VM? 如何提升在 Azure VM 上运行的远程命令的权限 - How to elevate the permissions of remote commands run on an Azure VM 如何在 Azure 的 VM 上运行 .NET? - How run .NET on a VM from Azure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM