How to schedule on Azure to run a powershell script on different VMs in specific hours.

Marcus Assis 0 Reputation points
2024-12-27T22:19:26.7933333+00:00

Hi.

I need to run a PowerShell script in different servers and different hours for each VMs. For exemple, Server A must run at 3pm, Server B must run at 5pm and Server C must run at 11am. I can run the PowerShell script successfully on "Run Command", but I couldn't schedule the automation to run it.

Can you please give me a suggestion on how to do it?

Thanks in advance!

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,177 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,280 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,486 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,588 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,708 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anthony LAVABRE 960 Reputation points
    2024-12-27T23:03:05.03+00:00

    Bonjour,

    Vous pouvez utiliser le planificateur de taches sur chaque serveur pour exécuter votre script Powershell : https://zcusa.951200.xyz/fr-fr/windows/win32/taskschd/using-the-task-scheduler

    Sinon vous pouvez utiliser Azure Automation : https://zcusa.951200.xyz/fr-fr/azure/automation/overview

    Bien à vous,

    0 comments No comments

  2. Prrudram-MSFT 27,251 Reputation points
    2024-12-28T11:02:04.2733333+00:00

    Hello @Marcus Assis

    You can use Azure Automation to schedule and run PowerShell scripts on different Azure VMs at specific times. Here's a step-by-step guide to help you set this up:

    Steps to Schedule PowerShell Script Using Azure Automation:

    Create an Azure Automation Account:

    • Go to the Azure portal and create a new Automation account.
    • Configure the managed identity option for your new Automation account.

    Grant Permissions:

    • Assign the necessary permissions to the managed identity using Azure role-based access control (RBAC).
    • Ensure the managed identity has permissions to access the VMs.

    Create a PowerShell Runbook:

    • In your Automation account, create a new PowerShell runbook.
    • Add your PowerShell script to the runbook.

    Create a Schedule:

    • Go to the "Schedules" section under Shared Resources in your Automation account.
    • Create a new schedule for each VM.
    • Set the schedule to run at the specific times you want (e.g., 3 PM for Server A, 5 PM for Server B, 11 AM for Server C).

    Link the Runbook to the Schedule:

    • Link the PowerShell runbook to the schedules you created.
    • Ensure the runbook is associated with the correct schedule for each VM.

    Test the Setup:

    • Test the setup to ensure that the scripts run at the scheduled times.
    • Monitor the execution logs to verify that everything is working as expected.

    Ref: https://zcusa.951200.xyz/en-us/azure/automation/automation-runbook-types

    By following these steps, you can automate the execution of your PowerShell script on different Azure VMs at specific times. If you encounter any issues or need further assistance, feel free to ask!

    If I have answered your question, please accept this as answer as a token of appreciation and don't forget to thumbs up for "Was it helpful"!

    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.