Overview
Power Automate can trigger PowerShell scripts to automate system administration, file operations, user management, and more. This integration is useful for:
Automating administrative tasks (e.g., creating users in Active Directory)
Managing files and servers (e.g., automating backups or log cleanups)
Running system diagnostics
Interacting with local or cloud-based infrastructure
Ways to Run PowerShell from Power Automate
1️⃣ Using Power Automate Desktop (for local PowerShell execution)
2️⃣ Using Azure Automation (for cloud-based, serverless execution)
3️⃣ Using an HTTP-triggered PowerShell script (via Azure Functions or APIs)
4️⃣ Using the Runbook feature in Microsoft Endpoint Manager (Intune)
1️⃣ Running PowerShell Scripts with Power Automate Desktop
Power Automate Desktop allows you to execute local PowerShell scripts on a Windows machine.
Steps to Execute a Local PowerShell Script
1️⃣ Open Power Automate Desktop
2️⃣ Create a new flow
3️⃣ Add the “Run PowerShell script” action
4️⃣ Insert your PowerShell script
🔹 Example PowerShell Script (Restart a Windows Service)
Restart-Service -Name "Spooler" -Force
5️⃣ Run the flow and verify execution
Use Case: Restart the Print Spooler service every time a printer error is logged in a monitoring system.
2️⃣ Running PowerShell Scripts with Azure Automation
Azure Automation provides a cloud-based solution for running PowerShell scripts remotely.
Steps to Execute a PowerShell Script in Azure Automation
1️⃣ Go to Azure Portal → Search for Automation Accounts
2️⃣ Create an Automation Account
3️⃣ Go to “Runbooks” → Click Create a Runbook
4️⃣ Select PowerShell Runbook and enter the script
5️⃣ Publish and Test the Runbook
🔹 Example PowerShell Script (Create an Azure AD User)
Connect-AzureAD
New-AzureADUser -DisplayName "John Doe" -UserPrincipalName "johndoe@company.com" -AccountEnabled $true -PasswordProfile (New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile)
6️⃣ Trigger the Runbook from Power Automate:
- Add the “Azure Automation – Create Job” action in Power Automate
- Select your Automation Account and Runbook Name
- Pass parameters if required
Use Case: Automatically create new user accounts in Azure AD when a new hire is added to a SharePoint list.
3️⃣ Running PowerShell Scripts via an HTTP Trigger (Azure Functions)
You can expose a PowerShell script as an HTTP endpoint using Azure Functions.
Steps to Create an HTTP-Triggered PowerShell Function
1️⃣ Go to Azure Portal → Create an Azure Function App
2️⃣ Select PowerShell as the runtime
3️⃣ Create a new HTTP-triggered function
4️⃣ Write a PowerShell script that executes based on HTTP input
🔹 Example PowerShell Script (Retrieve System Info on Request)
param($Request)
$hostname = hostname
$os = Get-ComputerInfo | Select-Object OsName, OsArchitecture
$response = @{
Hostname = $hostname
OS = $os.OsName
Architecture = $os.OsArchitecture
} | ConvertTo-Json
$response
5️⃣ Deploy the function and get the HTTP URL
6️⃣ Trigger it from Power Automate using the “HTTP” action
Use Case: A remote server monitoring system that checks system status by calling the PowerShell function from Power Automate.
4️⃣ Running PowerShell Scripts Using Microsoft Endpoint Manager (Intune)
For managing Windows devices in an enterprise, Power Automate can trigger PowerShell scripts using Microsoft Intune (Endpoint Manager).
Steps to Deploy a PowerShell Script via Intune
1️⃣ Go to Microsoft Endpoint Manager
2️⃣ Create a new PowerShell script under Devices > Scripts
3️⃣ Assign the script to Windows 10/11 devices
4️⃣ Use Power Automate to trigger the deployment via the Graph API
Use Case: Automatically apply a security patch to all Windows devices when a critical update is detected in Microsoft Defender.