Quick one for you (and there’s probably easier ways of doing this)…only took ten minutes to work it out tho.
I needed to get the Fully Qualified Domain Name of a computer on the network into an environment variable in a batch script.
Here’s the code snippet:
@ECHO OFF FOR /f "tokens=2,* delims= " %%a in ('IPCONFIG ^/ALL ^| FINDSTR "Primary Dns"') do set tempsuffix=%%b FOR /f "tokens=1,2 delims=:" %%a in ('echo %tempsuffix%') do set dnssuffix=%%b SET FQDN=%COMPUTERNAME%.%DNSSUFFIX:~1% ECHO Server FQDN: %FQDN%