1

I'm executing a powershell script from cmd window. Within the powershell script I want to set a variable that later can be reached from cmd window, once the ps script has finsihed. How do I do that?

I have tried:
PS promt: Set-Variable -Name "MyParameter" -Value "MyParameter1234" -Scope Global -Visibility Public CMD promt: set MyParameter

Please help me figure this out.

2
  • probably easiest way is to write to disk and read it from there Commented Feb 26, 2018 at 7:41
  • You can't change the environment of your parent process. You could start PS with a batchfile that calls a batchfile generated by PS to set it. Commented Feb 26, 2018 at 8:00

1 Answer 1

1

Easiest way would be to write the variable to a file, close the Powershell window, read the file in the cmd window and put it in to a variable and then delete the file.

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

1 Comment

Yes I have thought about that and I have tried it but it seems a little bit like stone age, but then again it works:) Thanks for your reply!

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.