Get PowerShell command output as a variable in bat (cmd) script
You need to escape parenthesis inside the subject when using FOR \F
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell.exe -noninteractive -command [System.Net.Dns]::GetHostByName^(^($env:computerName^)^).HostName`) DO (
SET var=%%F
)
ECHO %var%