How to schedule a Powershell script to run automatically in the Azure CLI each day?

Ed Summ 1 Reputation point
2022-09-20T02:16:20.427+00:00

I have written a Powershell script which removes firewall rules that match specific naming conditions from specific SQL databases in Azure. I have tested the Powershell script in Azure Cloud Shell, and it works as intended.

I want to schedule this to run automatically each day. I thought this is something that can be scheduled with 'Azure Automation', but it appears I am mistaken. It seems Automation is a tool for running scripts on resources, not in Azure CLI itself.

This seems like a simple task, but I am having trouble finding a solution. What would be the best approach to achieve this?

Thanks,

Ed

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,366 questions
{count} votes

3 answers

Sort by: Most helpful
  1. T. Kujala 8,761 Reputation points
    2022-09-20T03:45:32.013+00:00

  2. Maxim Sergeev 6,586 Reputation points Microsoft Employee
    2022-09-20T06:50:41.467+00:00

    Hi there,

    Just to clarify. Azure supports different options to deploy your scenario, including Azure PowerShell, Azure CLI, Azure ARM (or bicep) or direct RestAPI calls to ARM.
    If you have developed a Powershell based script, you can definitely use Azure Automation Account that supports PowerShell natively. If you have developed a CLI script, it requires to be triggered where CLI is installed (sadly, Azure Automation doesn't support this today).
    Can you clarify what type of script you are going to use?

    p.s. check the difference between Azure CLI and Powershell

    https://learn.microsoft.com/en-us/cli/azure/what-is-azure-cli
    https://learn.microsoft.com/en-us/azure/developer/azure-cli/choose-the-right-azure-command-line-tool


  3. AnuragSingh-MSFT 21,546 Reputation points Moderator
    2022-09-20T07:05:02.83+00:00

    Hi @Ed Summ ,

    Thank you for the question. The link provided by @T. Kujala above should help you get started with Azure Automation.

    In addition to the resource above, I would like to clarify the following points related to "..It seems Automation is a tool for running scripts on resources, not in Azure CLI itself."

    • Azure Automation performs script execution similar to how you would execute script in cloud shell OR locally on your machine using the same Az modules. Only in Azure Automation account, there is no manual intervention required. The script is stored as a runbook and executed in a sandbox in Azure environment or on Hybrid worker. The trigger for this execution could be schedule based, based on a web api call or even manually (if required).
    • The execution of these runbooks (stored script) does not happen in Azure Cloud Shell. It happens inside another sandbox. The cloud shell is provided as an end user tool to be able to execute scripts/cmds withoutt requiring local installation - and is available from everywhere.

    You may also refer to the link here to get a detailed walkthrough of similar scenario to get started - https://learn.microsoft.com/en-us/answers/questions/915711/index.html

    Please let us know if you have any questions.

    ---
    Please 'Accept as answer' if it helped so that it can help others in the community looking for help on similar topics.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.