0

I have a powershell script as part of Azure DevOps pipeline. I also want to run it from windows command line. How can I set them before calling them in windows? Perhaps in a cmd file? Note - these are temporary for a single execution and don't want to set windows environment variables.

I am accessing the environment variables like this in the powershell script:

$tfsAccessToken = If ($serverMode) {$env:SYSTEM_ACCESSTOKEN} else {"somethingelse"}
$tfsBuildDefinitionId = If ($serverMode) {$env:SYSTEM_DEFINITIONID} else {2}
2
  • Do you want to set in PowerShell a variable that will be available in the next CMD task (in azure devops)? Commented Jul 28, 2019 at 12:33
  • no, answer below is what i want to do. thanks for your response. Commented Jul 28, 2019 at 17:35

1 Answer 1

1

SET command:

Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.

Example.

Supposedly, the _foo environment variable isn't defined in a newly opened CMD prompt:

set _foo
Environment variable _foo not defined
powershell -nologo -noprofile -command "& {$env:_foo ; $null -eq $env:_foo}"
True

However, if defined, the _foo environment variable is visible in the child process powershell:

set "_foo=bar"
powershell -nologo -noprofile -command "& {$env:_foo ; $null -eq $env:_foo}"
bar
False

Another example (asynchronous child process powershell):

set "_foo=bar"
start "SO_57237835" powershell -noexit -nologo -noprofile -command "& {$env:_foo;$null -eq $env:_foo}"

SO_57237835

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.