azure - 使用 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 中工作的秘密语法糖是什么?
解决方案
当然,你可以这样做:
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
推荐阅读
- c# - .net 核心文件传输到网络位置
- android - 在recyclerview android中使用setImageBitmap时应用程序缓慢
- android - Recyclerview 不显示 Firebase 数据
- javascript - 如何将这个带有字符串的复杂 json 转换为普通的 json 对象,如输出
- java - swagger-ui 中的 OPTIONS、HEAD、PATCH 方法,但在 RestController 中没有
- c# - 如何在 0 - 1 随机数生成器 c# 中保持最高连胜
- go - Go 例程未执行
- sql - SQL查询耗时比预期长,如何优化?
- file - Gnuplot re 在重新启动计数后绘制线条
- java - 为什么迭代 Empty Map 不会在 Java 中抛出任何异常