使用 PowerShell 和应用程序环境变量从 Azure 批处理自定义 activity 调用 PowerShell 脚本

Calling a PowerShell script from Azure batch custom activity using PowerShell and application environment variable

我一直在慢慢研究如何使用 LogParser 2.2 调用 PowerShell 脚本来转换 IIS 日志。我已经决定使用 Azure Data Factory Batch Service Custom Activity 到 运行 PowerShell 脚本。我已经能够弄清楚如何从 Azure Custom Batch Activity 中解决 运行ning 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 window,要么不是我想要的变量:

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 中运行的秘密语法糖是什么?

当然,你可以这样做:

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

我试了将近 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

现在这只是 运行将存储在附加应用程序中的 PowerShell 脚本连接到 Azure Batch 模块的垫脚石。我希望 Microsoft 将向 运行 Azure 数据工厂中的 PowerShell 脚本添加 Databrick 或更好的方法,但在那之前,这是我发现 运行 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')

希望对大家有所帮助!