简体   繁体   中英

How execute a program in a Azure Virtual Machine using Azure Functions, Runbooks or Azure Powershell?

I need to start an application / file sometimes a day on a Windows Virtual Machine on Azure and I don't want to make an RDP connection to do this whenever I need to run it. So, I would like to know if it is possible to create an Azure Function, Runbook (Automation) or script in Powershell to open this application / file (and schedule, if possible).

I tried the following script on Automation Runbooks, but it didn't work:

$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
$VMs = Get-AzureRMVM | where {$_.Tags.Values -like '*TaggedMachine*'} 
$VMs | Start-Process -FilePath "notepad.exe"
Write-Output $VMs.Name

You can try to use Azure VMs Run Command functionality. If you are using Azure PowerShell just see this: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/run-command#powershell

If you are using AzureRM module, use this command instead: https://docs.microsoft.com/en-us/powershell/module/azurerm.compute/invoke-azurermvmruncommand?view=azurermps-6.13.0

if you need more help, just let me know:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM