For a long time, administrative task automation relied on a relatively simple architecture: a Windows server, a few PowerShell scripts, and the Task Scheduler. This approach has proven itself well. It continues to provide valuable services in many IT infrastructures.
Today, a large part of administrative operations involves services fully hosted in the cloud. Microsoft 365, Exchange Online, Microsoft Entra ID, and Microsoft Graph have become essential components of administrators’ daily lives.
Therefore, a question deserves to be asked: Why continue to maintain an on-premises server only to run PowerShell scripts that only interact with cloud services?
This is precisely the issue Azure Automation addresses.
This solution allows hosting, scheduling, and running PowerShell scripts directly in Microsoft Azure without having to manage a dedicated Windows server. It also introduces a particularly interesting security approach: managed identity authentication, which eliminates passwords and application certificates.
Let’s see how Azure Automation works, how to deploy a first PowerShell script there, and why this approach deserves a place in a modern Microsoft 365 administration strategy.
Azure Automation: what exactly is it?
Azure Automation is a Microsoft Azure service designed to automate recurring IT operations. Its principle is relatively simple. Rather than outsourcing script execution to a physical or virtual machine that the organization must maintain, this responsibility is delegated to a cloud service managed by Microsoft.
Scripts run by Azure Automation have a specific name: Runbooks.
A Runbook is an automation program that can be run manually, according to a schedule, or following an event. It can notably be used to control Microsoft Entra ID accounts, audit Exchange Online configurations, produce Microsoft 365 reports, or enforce governance rules.
The administrator retains control over the code and the operations performed. Azure supports the infrastructure necessary to run it.
This distinction is fundamental: Azure Automation does not replace PowerShell. It simply provides it with a runtime environment suited to cloud architectures.
Why move your PowerShell scripts to Azure?
Imagine an organization with a Windows server running several Microsoft 365 administration scripts daily. Every night, Task Scheduler runs different processes. Some query Microsoft Graph to identify inactive accounts. Others check Exchange Online configurations or generate security reports.
These scripts do not query any local files, query any domain controller, and use no internal infrastructure resources. Yet, their operation still depends on an on-premise server.
This architecture requires maintaining the operating system, monitoring its availability, managing updates, and protecting the authentication information used by scripts. With Azure Automation, a significant part of these constraints disappears.
Scripts are hosted in Azure and run in Microsoft-managed environments. Their scheduling becomes independent of Windows Task Scheduler, while execution logs are accessible from the Azure portal. The change is therefore not just about the script’s location. It is gradually transforming the way automations are designed and leveraged.
Understanding Azure Automation architecture
Before creating our first script, it is helpful to understand the main components of the service.
The Azure Automation account
The Automation account is the central point of the architecture. It brings together runbooks, runtime configurations, schedules, and various resources used by automations. The same account can host multiple PowerShell scripts.
For security and governance reasons, it may nevertheless be preferable to separate automations according to their environment or sensitivity level.
Les Runbooks
Each Runbook contains the code corresponding to an automation operation. A PowerShell Runbook can be created directly from the Azure portal or imported from a .ps1 file. It is also possible to keep its development in Visual Studio Code, then publish the script to Azure Automation.
Runtime environments
A PowerShell script generally depends on a PowerShell engine version and multiple modules. Azure Automation allows you to define these elements using Runtime Environments, or runtime environments. You can notably use PowerShell 7.4 and associate the necessary modules for script operation.
This approach allows better control of dependencies and limits compatibility issues during updates.
Managed identities
A managed identity, or Managed Identity, is a Microsoft Entra ID associated with an Azure resource. It allows this resource to authenticate to supported services without storing a password, application secret, or certificate in the script. I will return to this feature because it represents one of the main benefits of Azure Automation for Microsoft 365 administration.
What are the prerequisites for using Azure Automation?
Setting up Azure Automation does not require a particularly complex infrastructure. You first need to have an active Microsoft Azure subscription and the necessary permissions to create resources.
An Azure resource group will group the items associated with the service.
Creating the Automation account also requires Azure permissions Role-Based Access Control (RBAC), in other words, role-based access control. Finally, scripts will need to be able to access the services they manage.
For a script exclusively intended for Microsoft 365, no connection to the on-premises infrastructure is normally required, subject to organization-specific network and security restrictions.
One last point deserves to be highlighted: Azure Automation is an Azure service subject to specific pricing. Its use must therefore be integrated into cloud cost management.
The different implementation steps

Step 1: Create an Azure Automation account
Let’s start by signing in to the Microsoft Azure portal. In the search bar, let’s enter: Automation Accounts
Next, select the corresponding service, then Create. The creation wizard asks for several pieces of information. You need to choose the Azure subscription, select a resource group, and set a name for the Automation account.
For our example, we will use: aa-m365-automation
The choice of Azure region should take into account the organization’s data location requirements and policies. In the section dedicated to identities, let’s verify that the managed identity assigned by the system is enabled. This identity will be used later to authenticate our scripts.
Once the settings are verified, simply start creating the resource. Our Azure Automation environment is now available.
Step 2: Prepare the PowerShell environment
Creating the Automation account does not mean that all PowerShell modules are immediately available. A Microsoft 365 admin script may require several specific modules.
For example:
- Microsoft.Graph.Authentication for Microsoft Graph authentication.
- Microsoft.Graph.Users to administer users.
- ExchangeOnlineManagement for Exchange Online.
- Az.Accounts for certain Azure authentication and administration operations.
In the Automation account, open the Runtime Environments section. Create a PowerShell 7.4 environment, then add the necessary packages to our scripts. It is better to import only the modules actually used.
The Microsoft Graph software development kit, called the Software Development Kit (SDK), includes many modules. Importing the entire SDK is not necessary when a script uses only a few commands. This precaution helps control dependencies and simplifies maintenance operations.
Special attention must be paid to module versions. A fully functional script on a Windows server may encounter difficulties if Azure Automation uses a different version of PowerShell or its dependencies.
Step 3: Create your first PowerShell Runbook
We will now create a first script. For this example, our goal will be deliberately simple: query Microsoft Graph and retrieve information from a few Microsoft Entra ID users. From the Azure Automation account, let’s open:
Runbooks > Create a runbook

Provide the following information:
- Name: Get-M365Users
- Runbook type: PowerShell
- Runtime Environment: our PowerShell 7.4 environment
Once the Runbook is created, the editor allows you to enter PowerShell code directly.
Here is an example:
$ErrorActionPreference = “Stop”
try {
Connect-MgGraph -Identity -NoWelcome
$Users = Get-MgUser -Top 10 -Property ‘
“DisplayName,UserPrincipalName,AccountEnabled”
foreach ($User in $Users) {
write-output “Name: $($User.DisplayName)”
Write-Output “UPN : $($User.UserPrincipalName)”
Write-Output “Active: $($User.AccountEnabled)”
Write-Output “—————————–“
}
}
catch {
Write-Error “Error: $($_. Exception.Message)”
throw
}
finally {
Disconnect-MgGraph -ErrorAction SilentlyContinue
}
This script uses Microsoft Graph to retrieve information from ten users. The term UPN stands for User Principal Name. It corresponds to a user’s primary ID in Microsoft Entra ID. Unlike a traditional script running from an administration workstation, our example does not require any interactive authentication. The sign-in relies on the managed identity of the Azure Automation account.
However, be careful: the script will only be able to run if this identity has the necessary Microsoft Graph permissions. For this example, the application permission User.Read.All is a permission suitable for reading users. It must be assigned to the managed identity with the appropriate administrative consent. Activating a managed identity does not automatically grant these permissions.
Step 4: Understanding Managed Identity Authentication
This is probably the most interesting development when considering migrating PowerShell scripts to Azure Automation. Traditionally, automated execution of a Microsoft 365 script requires a non-interactive authentication mechanism. A common approach is to create a Microsoft Entra ID application and associate it with a certificate.
The Microsoft Graph connection might then look like this:
Connect-MgGraph -TenantId $TenantId
-ClientId $ClientId ‘
-CertificateThumbprint $CertificateThumbprint
This method offers real security advantages. However, it involves managing the certificate lifecycle: creation, storage, protection, monitoring of its expiration, and renewal. A forgotten certificate can interrupt an automation that is otherwise fully functional.
With a managed identity, the process becomes much simpler.
- For Microsoft Graph: Connect-MgGraph -Identity
- For Exchange Online: Connect-ExchangeOnline -ManagedIdentity -Organization “contoso.onmicrosoft.com”
These commands are executed directly from an Azure environment that supports managed identities. Azure and Microsoft Entra ID support managing the necessary authentication information. Therefore, it is no longer necessary to store a certificate in the script. However, this simplification should not obscure an essential distinction.
Authentication identifies the script. Authorization determines what it is allowed to do.
A managed identity does not automatically have the necessary permissions to administer Microsoft 365. Microsoft Graph permissions must be explicitly assigned. Exchange Online also requires appropriate configuration of its permissions, notably through RBAC. The principle of least privilege therefore remains fully applicable.
Step 5: Test your Runbook
Before any production, a Runbook must be tested. Azure Automation offers a test environment accessible from the script editor. After saving our code, let’s open the Test pane.

We can then start its execution and observe the results. In our example, the script must display the information of users returned by Microsoft Graph. If an authentication error appears, the managed identity and the assigned application permissions must be checked.
An error related to a command not found will rather indicate a PowerShell module or runtime environment issue. Testing thus distinguishes code, authentication, and configuration issues. It is also recommended to test scripts with a limited scope before allowing them to modify production resources.
Once the operation is validated, we can publish the Runbook.
Step 6: Automatically schedule the script execution
An administration script becomes especially useful when it can run without human intervention. Azure Automation natively integrates a scheduling mechanism. From our Runbook, we open the Schedules section, then associate a new schedule. We can choose a daily, weekly, or monthly run.

Let’s imagine a script responsible for checking Microsoft Entra ID accounts with certain characteristics every morning. It would be enough to schedule its daily execution at 7 a.m.
At the scheduled time, Azure Automation will automatically start the Runbook. No user session will be required. The script will use its managed identity to access Microsoft 365 services and perform the planned operations.
For sensitive automations, it remains preferable to provide mechanisms that prevent simultaneous executions when they could cause conflicts.
Step 7: monitor executions and errors
One recurring problem with scripts running from a Windows server concerns their monitoring. A scheduled task can run for several months before encountering an error. Without the right monitoring mechanism, this incident risks going unnoticed. Azure Automation facilitates this monitoring through its execution history.

Each launch of a Runbook generates a job, called a Job. From the Azure portal, we can check its status, its execution time, and the information produced by the script.
The following PowerShell commands then become particularly useful:
Write-Output “Start processing”
Write-Warning “An anomaly has been detected”
Write-Error “The processing encountered an error”
To go further, Azure Automation can be paired with Azure Monitor and a Log Analytics workspace. This integration allows logs to be centralized and alert mechanisms to be built. However, it is important to distinguish between service technical logs and business reports generated by scripts.
A CSV report (Comma-Separated Values) should not be considered sustainably retained simply because it was created during runtime of the Runbook. For reports that need to be archived, persistent storage such as Azure Blob Storage is generally preferable.
A concrete example: automating Microsoft Bookings governance
Let’s now take a case more representative of Microsoft 365 administration needs. In some organizations, Microsoft Bookings allows users to create booking pages to organize appointments or events.
Over time, some of these resources become unused. A governance approach can then involve identifying inactive Bookings, checking for no future appointments, notifying managers, and deleting resources that become obsolete after a defined period.
A PowerShell script can automate all these controls. Historically, this type of processing can be run from a Windows server with application certificate authentication. However, if the script uses only Microsoft Graph and Exchange Online, no technical dependency necessarily requires it to be executed from the on-premises infrastructure.
Azure Automation then constitutes a particularly relevant alternative. The script can be hosted in a Runbook, run on schedule and authenticated with a managed identity.
Audit reports can be kept in Azure storage, while the execution results remain accessible from the portal. However, migration requires careful validation of permissions.
Microsoft Graph permissions must be tailored to the operations performed, and Exchange Online permissions must maintain as restrictive a scope as possible. In the case of automation that could delete resources, a pre-audit mode remains essential.
The goal is not simply to automate more. It is to automate without losing control of operations.
Can Azure Automation replace all script servers?
The answer deserves some nuance. Azure Automation is particularly well suited for scripts that manage cloud resources through remotely accessible programming interfaces.
These interfaces, called Application Programming Interfaces (APIs), allow a program to communicate with a service without human intervention. Microsoft Graph is an excellent example. However, some scripts still depend directly on the local infrastructure.
This includes processes that query an Active Directory domain controller, handle files on an internal network share, or execute commands requiring access to on-premises servers. In these situations, Azure Automation offers a feature called Hybrid Runbook Worker.
It allows you to maintain the management and scheduling of Runbooks in Azure while running their code on a machine with the necessary access to internal resources. This hybrid approach offers a promising transition for organizations that cannot immediately move all their automations to the cloud.
Limitations to know before migrating
Azure Automation offers many advantages, but one should not assume that a script running on a Windows server can always be transferred without modification. The first difficulty concerns dependencies.
Some PowerShell modules require system components or features unavailable in cloud runtime environments.
Runtime is another constraint. Runbooks running in cloud environments are subject to resource and runtime limits. Particularly lengthy processing may require adapting its architecture.
File storage must also be rethought. Files created temporarily during runtime do not constitute a reliable archiving mechanism. Finally, network restrictions, Azure costs, and security policies must be reviewed before any deployment. These constraints do not affect the value of the service. They simply remind that a successful migration relies on a prior analysis of existing scripts.
Toward a new way to administer Microsoft 365
The appeal of Azure Automation far outweighs the ability to move a few PowerShell scripts to the cloud. It invites a rethink of the organization of automations. Rather than multiplying scheduled tasks across different servers, an organization can gradually centralize its Microsoft 365 processes on a dedicated platform. Scripts become easier to identify, plan, and monitor.
Their authentication can be simplified through managed identities, while permissions remain controlled through Microsoft Entra ID and Exchange Online security mechanisms.
However, this centralization must be accompanied by true governance. It is especially essential to determine who can create a Runbook, modify its code, grant permissions, or trigger its execution. A managed identity with elevated privileges should never become a way to bypass usual security controls.
Environment separation, change control, and operation traceability must be an integral part of the architecture.
Conclusion: Should you migrate your PowerShell scripts to Azure Automation?
For years, Windows servers have been the natural foundation of PowerShell automations. This architecture remains relevant when a script needs to interact directly with local resources.
However, for processing exclusively intended for Microsoft 365, Microsoft Entra ID, or Exchange Online, its value now deserves to be reassessed. Azure Automation provides a consistent response to this evolution.
By combining Runbooks, PowerShell environments, and managed identities, Microsoft offers a platform capable of simplifying script execution while reducing certain maintenance and authentication constraints. The real benefit does not lie only in the disappearance of a server. It lies in the ability to build automations that are easier to operate, better monitored, and integrated into a cloud governance approach.
Azure Automation undoubtedly deserves to be studied from this perspective.

Documentation Microsoft
- Introduction to and creation of an Azure Automation account
- Create a PowerShell Runbook with a managed identity
- Create and manage Azure Automation Runbooks
- Configure PowerShell runtime environments
- Manage Azure Automation schedules
- Use a managed identity with Exchange Online PowerShell
Related articles on WorkingTogether.fun