使用PowerShell和应用程序环境变量从Azure批处理自定义活动中调用PowerShell脚本 [英] Calling a PowerShell script from Azure batch custom activity using PowerShell and application environment variable

查看:69
本文介绍了使用PowerShell和应用程序环境变量从Azure批处理自定义活动中调用PowerShell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been slowly working out how to call a PowerShell script to transform IIS logs using LogParser 2.2. I've settled on using Azure Data Factory Batch Service Custom Activity to run the PowerShell script. I've been able to figure out how to address many of the file path issues that arise in running PowerShell from within Azure Custom Batch Activity, but I can't figure this one out.

当前,我只是试图通过Write-Host打印环境变量AZ_BATCH_APP_PACKAGE_powershellscripts#1.0我已经能够打印其他环境变量,但是我相信此末尾的#1.0引起了我的所有悲伤.BTW 1.0是在Azure中加载到批处理框架中的应用程序的版本.

Currently I'm just trying to print via Write-Host the environment variable AZ_BATCH_APP_PACKAGE_powershellscripts#1.0 I've been able to print other environment variables, but I believe the #1.0 at the end of this one is causing all my grief. BTW the 1.0 is the version of the application loaded into the batch framework in 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窗口,也不是我想要的变量:

These works, but are either cmd window or not the variable I want:

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

So what is the secret syntax sugar to getting this to work in Azure?

推荐答案

在使它像这样工作之前,我经历了近50次尝试:

I went through close to 50 tries before getting this to work like so:

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脚本的唯一方法:

Now this was just a stepping stone to running a PowerShell script stored in an attached application to the Azure Batch module. I'm hopeful Microsoft will add a Databrick or better way to run a PowerShell script in Azure Data Factory, but until then this is the only method I found to run a powershell script:

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

这应该对尝试从批处理任务目录运行的任何人都有效:

This should work for anyone just trying to run from the Batch Task Dir:

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

希望它对某人有帮助!

这篇关于使用PowerShell和应用程序环境变量从Azure批处理自定义活动中调用PowerShell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆