Question: I am using `PowerShell "(Get-Date).AddDays(-7).ToString('ddMMyyyy')"` in batch script.

I want to use a variable instead of **Get-Date** function. Is it possible?

`ADate` is the variable name!

**Edited:**

As suggested, my script is:

```
For /F UseBackQ %%A In (
    `PowerShell "(Get-Date).AddDays(-7).ToString('ddMMyyyy')"`
) Do Set "Freq=%%A"

```

`Adate` is simple string which comes from the file name, and has a value like `16112016`.

Answer: 
You need to use a [`for`](https://technet.microsoft.com/en-us/library/cc754900.aspx) loop to get the output of an external command in a batch variable:

```batch
@echo off
for /f "usebackq tokens=*" %%d in (`powershell "..."`) do set "adate=%%d"
echo %adate%

```

The `usebackq` and backticks are just so you don't need to escape the nested single quotes in your command string.
You can store the output of the powerShell command into a file and then read that file after that delete that temporary file.

```
    PowerShell "(Get-Date).AddDays(-7).ToString('ddMMyyyy')" >temp.txt
    set /p myVarDate= < date_Shell.txt
    echo Date from Shell %myVarDate%
    del temp.txt 

```