From LedHed's Wiki
How to set the hostname environment variable from a batch file.
for /f %%x in ('hostname.exe') do set hostname=%%x
Note: when running from the command line you only need 1 percent sign in front of the x.
for /f %x in ('hostname.exe') do set hostname=%x
Usage:
echo %hostname%
or
xcopy \\%hostname%\c$\temp \\computer2\c$\temp