首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PowerShell和应用程序环境变量从Azure batch自定义活动中调用PowerShell脚本

使用PowerShell和应用程序环境变量从Azure batch自定义活动中调用PowerShell脚本
EN

Stack Overflow用户
提问于 2019-10-31 01:43:19
回答 2查看 377关注 0票数 0

我一直在慢慢研究如何使用LogParser 2.2调用PowerShell脚本来转换IIS。我已经决定使用Azure Data Factory Batch Service Custom Activity来运行PowerShell脚本。我已经能够解决在Azure自定义批处理活动中运行PowerShell时出现的许多文件路径问题,但我不能解决这个问题。

目前我只是尝试通过写主机打印环境变量AZ_BATCH_APP_PACKAGE_powershellscripts#1.0,我已经能够打印其他环境变量了,但我相信这个变量末尾的#1.0引起了我所有的悲哀。顺便说一句,1.0是加载到Azure批处理框架中的应用程序版本。

以下所有尝试均已失败:

代码语言:javascript
复制
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窗口,要么不是我想要的变量:

代码语言:javascript
复制
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中工作的秘密语法糖是什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-11-01 22:20:29

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

代码语言:javascript
复制
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批处理模块的附加应用程序中的PowerShell脚本的垫脚石。我希望微软会在Azure Data Factory中添加一个Databrick或更好的方法来运行PowerShell脚本,但在那之前,这是我发现的唯一运行powershell脚本的方法:

代码语言:javascript
复制
powershell powershell -command ("(Get-ChildItem Env:AZ_BATCH_APP_PACKAGE_powershellscripts#1.0).Value" + '\Powershell\processWebLogsFromAzure.ps1')

这对于试图从Batch Task Dir运行的任何人来说都应该是有效的:

代码语言:javascript
复制
powershell powershell -command ("$env:AZ_BATCH_TASK_DIR" + '\wd\processWebLogsFromAzure.ps1')

希望它能帮助一些人!

票数 1
EN

Stack Overflow用户

发布于 2019-10-31 02:09:20

当然,你可以这样做:

代码语言:javascript
复制
powershell powershell Write-Host "$((Get-Variable -Name 'AZ_BATCH_APP_PACKAGE_powershellscripts#1.0').Value)"

或者这样:

代码语言:javascript
复制
powershell powershell Write-Host (Get-Variable -Name "AZ_BATCH_APP_PACKAGE_powershellscripts#1.0").Value
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58631018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档