简体   繁体   English

Powershell 无法访问运行时环境变量

[英]Powershell can't access runtime environment variables

I want to create a task which calls a Powershell script to do some processing.我想创建一个调用 Powershell 脚本来进行一些处理的任务。 However I can't access Azure Batch runtime environment variables from my Powershell script.但是我无法从我的 Powershell 脚本中访问 Azure 批处理运行时环境变量。

I can access via cmd, command below correctly outputs我可以通过 cmd 访问,下面的命令正确输出

D:\batch\tasks\applications\test12020-05-04-17-32': D:\batch\tasks\applications\test12020-05-04-17-32':

cmd /c echo %AZ_BATCH_APP_PACKAGE_Test#1%

However equivalent Powershell command below shows incorrect output但是下面的等效 Powershell 命令显示不正确的 output

%AZ_BATCH_APP_PACKAGE_Test#1%': %AZ_BATCH_APP_PACKAGE_Test#1%':

powershell -Command echo %AZ_BATCH_APP_PACKAGE_Test#1%

Of course there is a hacky way around this which is to create a.bat script to call my.ps1 script.当然,有一种解决方法是创建一个 .bat 脚本来调用 my.ps1 脚本。 But I was looking for a better solution.但我一直在寻找更好的解决方案。

Is it possible to access Azure Batch runtime environment variables from Powershell?是否可以从 Powershell 访问 Azure 批处理运行时环境变量?

As iRon said, echo is not really a PowerShell command, try the code as below:正如 iRon 所说, echo并不是真正的 PowerShell 命令,请尝试以下代码:

powershell -Command $Env:ComSpec

The environment variables in my local is as below:我本地的环境变量如下:

在此处输入图像描述

And here is the PowerShell running snapshot:这是 PowerShell 运行快照:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ubuntu Agent-无法在Powershell任务中访问管道变量 - Ubuntu Agent - Can't access pipeline variables in powershell task 如何使用Powershell编写的Azure函数应用程序中访问环境变量? - How do you access environment variables in an Azure function app written in powershell? 在运行时逻辑应用程序中设置环境变量 - Set environment variables in runtime logic app 为什么ASM powershell模块无法访问某些订阅? - Why can't the ASM powershell module access some subscriptions? dockerize create-react-app如何在docker环境下访问azure发布管道变量 - How dockerize create-react-app can access to azure release pipeline variables in docker environment 如何访问 Azure 管道中的环境变量? - How to access environment variables in Azure pipeline? 用于 UAT 和 Live 的 React 中的运行时环境变量,用于单个构建 devops - Runtime Environment Variables in React for UAT and Live for a single build devops Azure Pipelines Environment变量不适用于目标计算机上的PowerShell - Azure Pipelines Environment variables not working for PowerShell on Target Machines 如何在Azure上的自定义脚本扩展脚本中访问环境变量 - How to access environment variables in custom script extension script on Azure 从nodejs访问azure app设置环境变量 - Access to azure app setting environment variables from nodejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM