Share via

I need to create an automated Powershell

Tyler Johnson 100 Reputation points
2026-02-12T14:52:43.84+00:00

Hello, I'm new to using Powershell and Azure Automation.

I have code that I can manually run in Powershell, but I need to create an automation process, which I think is done in Azure Automation.

Here is my code. The files are on my local drive.

It seems from my research I need to use "Hybrid Worker" due to my local files?

import-Csv -Path "C:\Users\OneDrive - Documents\Power Automate Lists\Test.csv" | foreach{Add-DistributionGroupMember -Identity "Test2" -Member $_.Email}

Azure Automation
Azure Automation

An Azure service that is used to automate, configure, and install updates across hybrid environments.

0 comments No comments
{count} votes

Answer accepted by question author
  1. Bharath Y P 5,720 Reputation points Microsoft External Staff Moderator
    2026-02-12T20:53:17.29+00:00

    Hello Tyler Johnson. It sounds like you’re on the right track with wanting to automate your PowerShell script using Azure Automation, especially since you’re working with local files. Here's how you can set this up using a Hybrid Worker:

    Steps to Create an Automated PowerShell Script with Azure Automation:

    1. Set up Azure Automation Account:
      • Log into the Azure portal.
      • Create an Azure Automation account by selecting Create a resource, then searching for Automation and following the prompts.
    2. Configure Hybrid Worker:
      • Since your script uses a CSV file on your local drive, you will need to configure a Hybrid Worker. This allows Azure Automation to run scripts on your local machine.
      • Follow the instructions in the Hybrid Runbook Worker.
    3. Create a Runbook:
      • In your Azure Automation account, go to the Runbooks section and click Create a runbook.
      • Choose a suitable name, set the type to "PowerShell", and click Create.
    4. Edit the Runbook:
      • Paste your existing PowerShell code into the editor. Since it's looking for a CSV file on your local machine, ensure it's available to the Hybrid Worker:
        
             import-Csv -Path "C:\Users\OneDrive - Documents\Power Automate Lists\Test.csv" | foreach{Add-DistributionGroupMember -Identity "Test2" -Member $_.Email}
        
        
    5. Test your Runbook:
      • After editing, you can test your runbook from the Azure portal.
    6. Publish your Runbook:
      • Once you are satisfied with the testing, publish the runbook to make it available for scheduling.
    7. Schedule the Runbook:
      • You can schedule the runbook to run at specific intervals if needed.

    Reference: Create a Hybrid Worker

    Hope this helps! Let me know if you have any more questions!

    If the provided answer was helpful, please click Accept the Answer and upvote if the above was helpful.

    Thanks

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-12T14:52:55.8833333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To automate your PowerShell script using Azure Automation, you will indeed need to set up a Hybrid Runbook Worker. This allows you to run scripts that access local resources, such as files on your local drive.

    Here are the general steps you should follow:

    1. Create a Hybrid Worker Group: You can create a Hybrid Worker Group in Azure Automation where your Hybrid Workers will reside. This can be done using the Azure Portal or PowerShell.
         New-AzAutomationHybridRunbookWorkerGroup -AutomationAccountName "YourAutomationAccount" -Name "YourHybridWorkerGroup" -ResourceGroupName "YourResourceGroup"
      
    2. Install the Hybrid Worker Extension: Once you have your VM set up as a Hybrid Worker, you need to install the Hybrid Worker Extension on it. This can be done using the Azure CLI:
         az vm extension set --name HybridWorkerExtension --publisher Microsoft.Azure.Automation.HybridWorker --version 1.1 --vm-name <vmname> -g <resourceGroupName> \
             --settings '{"AutomationAccountURL" = "<registration-url>";}' --enable-auto-upgrade true
      
    3. Create a Runbook: In Azure Automation, create a new Runbook where you can paste your PowerShell script. You will need to modify the script slightly to ensure it runs correctly in the Azure Automation context. For example, you may need to adjust the file path to point to the location accessible by the Hybrid Worker.
    4. Publish and Schedule the Runbook: After creating the Runbook, publish it and set up a schedule if you want it to run automatically at specific times.
    5. Test the Runbook: Finally, test your Runbook to ensure it works as expected. You can do this from the Azure Portal.

    By following these steps, you will be able to automate your PowerShell script using Azure Automation and Hybrid Workers, allowing you to access local files as needed.


    References:

    0 comments No comments

Your answer

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