none
Batch Script using System Varriable for Hostname and FQDN results in large space between RRS feed

  • Question

  • I have a batch script running on Windows 7 that I've created to help a physical computer, connect to his virtual cousin.  Problem is when I try to make it use the FQDN (required by the View Client) it puts a large space between the hostname and the domain.

    Result

    ECHO Connecting View Client to PREFIX-SERIAL .domain.com

    OR

    "C:\Program Files\VmWare\View.exe" -Args -serverURL PREFIX-SERIAL       .domain.com


    Our computers are named a combination of a prefix and the serial number.  Our virtual computer names are the same, but with a different prefix.  So my attempt was to make a connection script, using the computer serial number.  My Process:

    Setting %serial% variable.

    for /F "skip=1 tokens=*" %%b in ('wmic bios get serialnumber') do if not defined serial set serial=%%b

    Set %hostname% variable.

    set hostname=PREFIX-%serial%

    Installation command line

    "C:\Program Files\VmWare\View.exe" -Args -serverURL %hostname%.domain.com

    That results in the output at the beginning of my post.

    I've also tried

    %hostname%.%userdomain%.com
    
    PREFIX-%serial%.%userdomain%.com
    
    PREFIX-%serial%.domain.com
    
    SET FQDN=.domain.com
    PREFIX-%serial%%FQDN%
    
    %hostname%%FQDN%

    I also tried carets and quotes on set commands without any improvement.

    I'm sure I'm missing something simple here.  Any advise?


    There's no place like 127.0.0.1



    • Edited by Matt5150 Wednesday, March 19, 2014 10:20 PM
    Wednesday, March 19, 2014 10:12 PM

Answers

  • Will something like this get you what you are looking for?

    (gwmi win32_bios).SerialNumber+(gwmi WIN32_ComputerSystem).Domain
    Or 
    $hostname=(gwmi win32_bios).SerialNumber+"."+(gwmi WIN32_ComputerSystem).Domain

    Sorry just realized your looking to do this in a Batch file...so maybe something like this

    @echo off
    for /F "skip=1 delims=" %%j in ('powershell "[System.Net.Dns]::GetHostByName((hostname)).HostName"') do (
      set Host=%%j
      goto :DONE
    )
    :DONE
    echo  %HOST%

    


    • Edited by John-Barrett Thursday, March 20, 2014 12:48 AM
    • Marked as answer by Matt5150 Thursday, March 20, 2014 1:23 AM
    Wednesday, March 19, 2014 11:41 PM

All replies

  • Will something like this get you what you are looking for?

    (gwmi win32_bios).SerialNumber+(gwmi WIN32_ComputerSystem).Domain
    Or 
    $hostname=(gwmi win32_bios).SerialNumber+"."+(gwmi WIN32_ComputerSystem).Domain

    Sorry just realized your looking to do this in a Batch file...so maybe something like this

    @echo off
    for /F "skip=1 delims=" %%j in ('powershell "[System.Net.Dns]::GetHostByName((hostname)).HostName"') do (
      set Host=%%j
      goto :DONE
    )
    :DONE
    echo  %HOST%

    


    • Edited by John-Barrett Thursday, March 20, 2014 12:48 AM
    • Marked as answer by Matt5150 Thursday, March 20, 2014 1:23 AM
    Wednesday, March 19, 2014 11:41 PM
  • Adding the prefix, this set the proper hostname variable for me in Powershell.

    $hostname="PRE-FX-"+(gwmi win32_bios).SerialNumber+"."+(gwmi WIN32_ComputerSystem).Domain

    Thanks!


    There's no place like 127.0.0.1

    Thursday, March 20, 2014 1:23 AM