I want to execute powershell command and put it in batch variable
The command:
for /f "delims=" %%i in ('powershell ^(Get-ChildItem ""\dir\"" -Name | sort-object {\[regex\]::Replace^($_,^'\d+^',{$args\[0\].Value.PadLeft^(20^)}^)} | select -last 1^) ') do set output=%%i
It can't be executed due special character. In addition, I can't pause the window so it closes before I can see what is the problem.
I think the problem is with the pipe "|", because the following command does work(the part before the pipe)
for /f "delims=" %%i in ('powershell ^(Get-ChildItem ""\dir\"" -Name^) ') do set output=%%i
I tried to add ^
, ^^^
and ""
before pipe, doesn't work. Can you spot the problem?