【问题标题】:How to execute a PowerShell Command from within Azure Data Factory custom activity?如何从 Azure 数据工厂自定义活动中执行 PowerShell 命令?
【发布时间】:2019-09-03 05:28:08
【问题描述】:

我在 Azure 数据工厂中有一个自定义活动,它尝试执行以下命令:

PowerShell.exe -Command "Write-Host 'Hello, world!'"

但是,当我从 Azure 数据工厂中调试(运行)此命令时,它运行了很长时间,最后失败了。

我猜它失败了,因为它可能找不到“PowerShell.exe”。如何确保 ADF 自定义活动可以访问 PowerShell.exe?

一些网站说要指定一个包(.zip 文件),其中包含执行 exe 所需的所有内容。但是,由于 PowerShell 来自 Microsoft,我认为将 PowerShell 目录 ZIP 并将其指定为自定义 Activity 的包是不合适的。

请建议我如何从 Azure 数据工厂的自定义活动中执行 PowerShell 命令。谢谢!

每当我搜索“从 Azure 数据工厂中的自定义活动执行 PowerShell”时,搜索结果都会更多地讨论用于触发启动 ADF 管道的 Az PowerShell 命令。

我在 Stackoverflow.com 中看到了两个线程,其中答案只是指定使用自定义 Activity,而答案并非特定于来自 ADF 的 PowerShell 命令调用

这是任务的 JSON:

{ "name": "ExecutePs1CustomActivity", "properties": { "activities": [ { "name": "ExecutePSScriptCustomActivity", "type": "Custom", "dependsOn": [], "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "command": "PowerShell.exe -Command \"Write-Host 'Hello, world!'\"", "referenceObjects": { "linkedServices": [], "datasets": [] } }, "linkedServiceName": { "referenceName": "Ps1CustomActivityAzureBatch", "type": "LinkedServiceReference" } } ], "annotations": [] } }

我看到“进行中”持续 3 分钟(180 秒),然后显示为“失败”。

【问题讨论】:

    标签: powershell azure-data-factory custom-activity


    【解决方案1】:

    我建议您将所有脚本任务移动到一个 powershell 文件中,并将其复制到与您的自定义活动相关联的存储帐户。 .完成后尝试如下调用它:

    powershell .\script.ps1
    

    您还可以在 json 中提供脚本的路径,如下所示:

    {
      "name": "MyCustomActivityPipeline",
      "properties": {
        "description": "Custom activity sample",
        "activities": [{
          "type": "Custom",
          "name": "MyCustomActivity",
          "linkedServiceName": {
            "referenceName": "AzureBatchLinkedService",
            "type": "LinkedServiceReference"
          },
          "typeProperties": {
            "command": "helloworld.exe",
            "folderPath": "customactv2/helloworld",
            "resourceLinkedService": {
              "referenceName": "StorageLinkedService",
              "type": "LinkedServiceReference"
            }
          }
        }]
      }
    }
    

    请尝试一下,看看是否有帮助。另外我建议您对管道步骤进行故障排除以查找详细错误。

    关于您的第二点“一些网站说要指定一个包(.zip 文件),其中包含执行 exe 所需的所有内容。” 当您使用构建自定义活动时,这是必需的dot net 那么它必须复制所有的 Dll 和 Exe 才能执行。

    希望对你有帮助。

    【讨论】:

    • 我明天会试试这个并分享我的观察。我怀疑的一件事是公司政策不允许在数据湖的文件系统中保留 PS1 文件。如果我克服了这个障碍,我会尝试你的建议。谢谢!
    猜你喜欢
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    相关资源
    最近更新 更多