0
votes

I want to create a task which calls a Powershell script to do some processing. However I can't access Azure Batch runtime environment variables from my Powershell script.

I can access via cmd, command below correctly outputs

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

%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. But I was looking for a better solution.

Is it possible to access Azure Batch runtime environment variables from Powershell?

1
exho is not really a PowerShell command, try:powershell -Command $Env:AZ_BATCH_APP_PACKAGE_Test#1? - iRon
as iRon implied, you are using %name% in powershell ... and that will not work for accessing environment variables. you should use $env:Name instead. - Lee_Dailey
stackoverflow.com/questions/58631018/… (see the last bit of the accepted post) has your clue to the answer. - Tats_innit

1 Answers

0
votes

As iRon said, echo is not really a PowerShell command, try the code as below:

powershell -Command $Env:ComSpec

The environment variables in my local is as below:

enter image description here

And here is the PowerShell running snapshot:

enter image description here