5

Can I use my own/custom console application in Azure Runbook (PowerShell or any other)?

When I try to run my own console application (after retrieving it from Azure Storage), it fails.


When I try to execute it simply by:

.\myapp.exe

I get:

Program 'myapp.exe' failed to run: The operation was canceled by the user


When I use System.Diagnostics.Process:

$process = New-Object System.Diagnostics.Process
$process.StartInfo.FileName = $path
$process.StartInfo.UseShellExecute = $False
$process.Start()

I get a more meaningful error:

Exception calling "Start" with "0" argument(s): "This program is blocked by group policy. For more information, contact your system administrator"


Is there any settings in Azure Automation, I can toggle, to allow executing custom applications? Or is it simply not possible in the restricted Runbook environment?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

3 Answers3

4

Thanks for reaching out! Unfortunately your ask of running .exe inside an Azure Automation runbook is currently not supported. And yes, you can go with Azure Web Job(s). One other customer has recently reached out with similar ask and solved their issue by leveraging Azure Web Job(s). For clarification, you may refer this MSDN thread. Hope this helps you.

Cheers!

KrishnaG
  • 3,340
  • 2
  • 6
  • 16
  • Thanks for your answer. Yes I'm aware that I can use a WebJob. It's that the RunBook is more lightweight (and not need a Web site). – Martin Prikryl Aug 25 '19 at 06:49
2

Unfortunately , it is not supported by Azure Automation Runbook for now.Here is a feedback replied by Automation PG team , there is no update on it.

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
2

You can however

  1. Run console app as Azure WebJob on App Service and call it remotely via SCM endpoint or,
  2. Compile console application as PowerShell cmdlet

    using System.Management.Automation; 
    
    namespace MyApp
    {
      [Cmdlet(VerbsCommunications.Send, "RunApplication")]
      public class RunApplicationCommand : Cmdlet
      {
        protected override void ProcessRecord()
        {
          // App Code goes here
        }
      }
    }
    
    • Attach compiled DLL to PowerShell module
    • Deploy PowerShell modle to Automation account using Modules > Import
    • Call cmdlet from runbook
Adam Marczak
  • 2,257
  • 9
  • 20
  • What do you mean by *"Compile console application as PowerShell cmdlet"* – It actually looks like you suggest that I rewrite my console application in PowerShell, right? – Martin Prikryl Aug 25 '19 at 06:47
  • No I don't, I gave you sample of the code. Just copy paste your application code into this sample. Compile it in visual studio which will return .DLL files that can be attached as powershell module. This means you have the console app still written in C# that can be called directly from powershell on Azure Automation service. – Adam Marczak Aug 25 '19 at 08:00
  • Sorry, I didn't notice that it's a C# code. -- Anyway, my application is not in C#, not even .NET. -- It's a useful answer anyway (but not for me). – Martin Prikryl Aug 25 '19 at 08:10
  • Though note that you can use a regular .NET (C# or any other) assembly in PowerShell in Runbook. So actually, there's no need for turning a .NET code into cmdlet. – Martin Prikryl Aug 25 '19 at 08:23
  • This means you should go for option 1. So run this .exe as webjob. – Adam Marczak Aug 25 '19 at 09:38