简体   繁体   English

如何使用 powershell 从我的办公室桌面远程重启 Azure VM 上的 windows 服务?

[英]How do I restart a windows service on an Azure VM remotely from my office desktop using powershell?

I have a few Windows Server 2019 Core VMs in Azure all running the same windows service.我在 Azure 中有几个 Windows Server 2019 Core VM,它们都运行相同的 windows 服务。

I would like to run a powershell script from my computer that loops through all the VMs and restarts the service on each.我想从我的计算机上运行一个 powershell 脚本,该脚本循环遍历所有虚拟机并在每个虚拟机上重新启动服务。

I have a PS script on each VM which does this so how do I invoke them remotely?我在每个 VM 上都有一个 PS 脚本来执行此操作,那么如何远程调用它们? Is this possible without using Cloud Shell or Automation, with just a few lines of code?如果不使用 Cloud Shell 或自动化,只需几行代码,这是否可行? I have Azure powershell tools installed on my computer too.我的电脑上也安装了 Azure powershell 工具。

Please provide answers with a working example.请提供一个工作示例的答案。

Thank you谢谢

For your requirement, I think the simplest way is to use the Azure PowerShell command to execute the PowerShell script inside the VM, the example command here:对于您的要求,我认为最简单的方法是使用 Azure PowerShell 命令在 VM 中执行 PowerShell 脚本,示例命令如下:

Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -VMName 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'sample.ps1' -Parameter @{param1 = "var1"; param2 = "var2"}

To execute the script in each VM, you need to make a loop with PowerShell yourself.要在每个 VM 中执行脚本,您需要自己使用 PowerShell 进行循环。 By the way, you can also use the Custom Extension for Windows .顺便说一句,您还可以使用Windows 的自定义扩展

暂无
暂无

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

相关问题 如何使用 Powershell 从我的本地计算机在 Azure Windows 虚拟机 (VM) 中运行“sysprep /generalize”? - How to run "sysprep /generalize” in Azure Windows Virtual Machine (VM) from my local machine using Powershell? 无法使用Powershell远程连接到Azure VM - Unable to connect to Azure VM remotely using powershell 我希望能够使用Powershell在Azure上安排虚拟机的关闭和重新启动 - I want to be able to schedule a shutdown and restart of a VM on azure using Powershell 如何使用WAR文件将Java应用程序部署到Azure云服务(不是VM或App Service)? - How do I deploy my Java Application to Azure Cloud Service(not VM or App Service) using a WAR file? 如何在Powershell中从Azure获取VM映像? - How do I get a VM Image from Azure in Powershell? 使用Powershell在Azure VM上启动和停止Windows服务 - Start and stop windows service on a Azure VM using powershell 如何在使用 Terraform (Azure) 创建 Windows VM 资源时运行 Powershell7 脚本 - How do I run a Powershell7 Script upon creation of a Windows VM Resource with Terraform (Azure) 如何在Powershell脚本中将MS Web Deploy安装到Azure Windows Server 2012 R2 VM? - How do I install MS Web Deploy to an Azure Windows Server 2012 R2 VM in a powershell script? 如果代理没有响应,我们可以使用 powershell 执行自动化脚本来自动重启 azure vm 代理吗? - Using powershell can we do automation script to auto restart the azure vm agent if the agent is not responding? 如何使用powershell找出Azure VM使用的Windows版本? - How to find out what version of windows is Azure VM using, with powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM