ADF How to Exec PowerShell and Save Output to Variable

CB Weiner 65 Reputation points
2023-07-16T20:42:03.09+00:00

How do you execute a PowerShell script in ADF and save the output to a variable to use in the pipeline? The output will be the folder name needed to import a file.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,224 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AnnuKumari-MSFT 34,011 Reputation points Microsoft Employee
    2023-07-17T10:10:20.4266667+00:00

    Hi CB Weiner ,

    Thankyou for using Microsoft Q&A platform and thanks for posting your question here.

    As I understand your query, you want to know if there is any way to execute powershell scripts using ADF and save the output into a variable that can be utilized in the pipeline. Please let me know if that is not the ask.

    You can use custom activity to execute your powershell through Azure Data Factory.
    Here is the documentation about how to use Custom activity : Custom Activity in ADF

    However, the output will not be directly accessible via the pipeline. The output is saved in stdout.txt file created in the ADLS/Blob storage account automatically. Once the file is created, you can point a dataset to the file and use the 'lookup activity' to fetch the output and load the same to the variable using 'set variable activity'.

    Kindly check the below resources for your reference:

    Azure Data Factory - Use Powershell script to read BLOB metadata and change the tier to ARCHIVE

    How To Run PowerShell Script in Azure Data Factory

    Other option is to use WebHook activity to run the powershell script stored in an Azure Automation Account.

    For more details on this, kindly visit the following resources:

    Run PowerShell in Azure Data Factory via Webhook activity

    Azure Data Factory with Powershell Runbooks, Webhooks and Logic apps using service principle

    Hope it helps. Please accept the answer by clicking on Accept answer button. Thankyou.


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.