The following command line does not work in a Windows batch file:
Powershell.exe -Command Get-Date -Format 'yyyy-MM-dd HH:mm:ss' echo "Hello World"
The expected result is: 2021-05-09 12:00:00 Hello World
But PowerShell outputs the error message:
Get-Date : Cannot bind parameter 'Date'. Cannot convert value "echo" to type "System.DateTime".
Error: "The string was not recognized as a valid DateTime. There is a unknown word starting at index 0."
At line:1 char:9
+ Get-Date <<<< -Format 'yyyy-MM-dd HH:mm:ss' echo Hello World
+ CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
How to get output of the PowerShell command to get date and time in format yyyy-MM-dd HH:mm:ss
and of the command ECHO in Windows batch file output on one line?