I'm trying to get FQDN of a host in some .cmd file. We have disjointed AD domain so "@echo %COMPUTERNAME%.%USERDNSDOMAIN%"
does not work. I mean it works, but returns wrong value.
The solution I ended up with is
powershell.exe -noninteractive -command[System.Net.Dns]::GetHostByName(($env:computerName)).HostName
It works fine in the command line. I'm trying to get it in a variable in my cmd file:
FOR /F "tokens=* USEBACKQ" %%F IN (\`powershell.exe -noninteractive -command
[System.Net.Dns]::GetHostByName(($env:computerName)).HostName\`) DO (
SET var=%%F
)
ECHO %var%
But getting the following error: ).HostName`) was unexpected at this time.
I understand that something should be screened since both cmd and powershell are parsing this line, but do not know what to screen and how. How to make this get to work?