Powershell – Windows command prompt: how to get the output of a command into a environment variable

batchpowershellwindows-command-prompt

I want to have an environment variable that contains the day of week in cmd.exe.

When I run this command I get the result I want.

C:\Users\tisc> powershell (get-date).dayofweek
Friday

Here I'm trying to store the result in an environment variable.

C:\Users\tisc> set dow = powershell (get-date).dayofweek

But when I try to get it I don't get the string as I wanted.

C:\Users\tisc> set dow
DoW=0
dow = powershell (get-date).dayofweek

My goal is to use the variable in a batch file for some backup scripts.

Best Answer

You can use something like:

$env:DOW = "foo"