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://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command#powershell
If you are using
AzureRM
module, use this command instead: https://learn.microsoft.com/en-us/powershell/module/azurerm.compute/invoke-azurermvmruncommand?view=azurermps-6.13.0if you need more help, just let me know:)