【问题标题】:Calling a PowerShell script from Azure batch custom activity using PowerShell and application environment variable使用 PowerShell 和应用程序环境变量从 Azure 批处理自定义活动调用 PowerShell 脚本
【发布时间】:2020-02-26 02:03:20
【问题描述】:

我一直在慢慢研究如何使用 LogParser 2.2 调用 PowerShell 脚本来转换 IIS 日志。我已决定使用 Azure 数据工厂批处理服务自定义活动来运行 PowerShell 脚本。我已经能够弄清楚如何解决在 Azure 自定义批处理活动中运行 PowerShell 时出现的许多文件路径问题,但我无法解决这个问题。

目前我只是试图通过 Write-Host 打印环境变量 AZ_BATCH_APP_PACKAGE_powershellscripts#1.0 我已经能够打印其他环境变量,但我相信这个结尾的 #1.0 让我很伤心。顺便说一句,1.0 是加载到 Azure 批处理框架中的应用程序版本。

以下所有尝试均失败:

powershell powershell Write-Host "$AZ_BATCH_APP_PACKAGE_powershellscripts#1.0"
powershell Write-Host "$AZ_BATCH_APP_PACKAGE_powershellscripts#1.0"
powershell Write-Host "$env:AZ_BATCH_APP_PACKAGE_powershellscripts#1.0"
powershell powershell Write-Host "$env:AZ_BATCH_APP_PACKAGE_powershellscripts\#1.0"
powershell powershell Write-Host "$env:AZ_BATCH_APP_PACKAGE_powershellscripts/#1.0"
powershell powershell Write-Host "$env:AZ_BATCH_APP_PACKAGE_powershellscripts"
powershell powershell Write-Host "$env:AZ_BATCH_APP_PACKAGE_powershellscripts`#1.0"
powershell powershell Write-Host "$env:AZ_BATCH_APP_PACKAGE_powershellscripts`#1`.0"
powershell powershell Write-Host "$env:AZ_BATCH_APP_PACKAGE_powershellscripts\`#1.0"
powershell powershell Write-Host "$AZ_BATCH_APP_PACKAGE_powershellscripts`#1.0"

这些有效,但要么是 cmd 窗口,要么不是我想要的变量:

powershell powershell Write-Host "$env:AZ_BATCH_TASK_DIR"
powershell powershell Write-Host "$env:AZ_BATCH_ACCOUNT_URL"
cmd /c echo %AZ_BATCH_APP_PACKAGE_powershellscripts#1.0%

那么,让它在 Azure 中运行的秘密语法糖是什么?

【问题讨论】:

  • 好头韵:)
  • 我必须玩得开心,否则我会因为所有失败的尝试而发疯!很高兴有人欣赏我的文字。

标签: azure powershell azure-data-factory-2


【解决方案1】:

当然,你可以这样做:

powershell powershell Write-Host "$((Get-Variable -Name 'AZ_BATCH_APP_PACKAGE_powershellscripts#1.0').Value)"

或者这个:

powershell powershell Write-Host (Get-Variable -Name "AZ_BATCH_APP_PACKAGE_powershellscripts#1.0").Value

【讨论】:

  • 你又一次让我走上了正轨,但这些选项都没有奏效。
【解决方案2】:

我经历了近 50 次尝试,才让它像这样工作:

powershell powershell Write-Host (Get-ChildItem Env:AZ_BATCH_TASK_DIR).Value
powershell powershell Write-Host (Get-ChildItem Env:AZ_BATCH_APP_PACKAGE_powershellscripts#1.0).Value

现在,这只是运行存储在 Azure Batch 模块的附加应用程序中的 PowerShell 脚本的垫脚石。我希望微软会添加一个 Databrick 或更好的方法来在 Azure 数据工厂中运行 PowerShell 脚本,但在此之前,这是我发现运行 powershell 脚本的唯一方法:

powershell powershell -command ("(Get-ChildItem Env:AZ_BATCH_APP_PACKAGE_powershellscripts#1.0).Value" + '\Powershell\processWebLogsFromAzure.ps1')

这应该适用于任何试图从批处理任务目录运行的人:

powershell powershell -command ("$env:AZ_BATCH_TASK_DIR" + '\wd\processWebLogsFromAzure.ps1')

希望对某人有所帮助!

【讨论】:

    猜你喜欢
    • 2020-02-24
    • 2018-08-08
    • 2017-09-28
    • 1970-01-01
    • 2014-10-14
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    相关资源
    最近更新 更多