首页 > 解决方案 > 使用 PowerShell 和应用程序环境变量从 Azure 批处理自定义活动调用 PowerShell 脚本

问题描述

我一直在慢慢研究如何使用 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 中工作的秘密语法糖是什么?

标签: azurepowershellazure-data-factory-2

解决方案


当然,你可以这样做:

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

推荐阅读