none
Computer Name from WMI, only when booting from USB? RRS feed

  • Question

  • If LiteTouch is started from litetouch.vbs within windows, it will populate the computer name from the existing host name.

    If LiteTouch is started from boot media, it will produce one of those MININT-XXXXXX computer names.

    If I add "OSDComputername=%SerialNumber%" to the CustomSettings.ini, it will produce a temporary computer name using the serial number.  This works when started from LiteTouch.vbs over UNC or USB.

    Is there a way to instruct MDT to build boot media with a custom install command on the boot ISO, where I can put something like ".\LiteTouch.vbs /OSDComputername=%SerialNumber%", or a way to have CustomSettings.ini override values provided only to the boot media?

    The end goal is to have %computername% used when it's not MININT-XXXXX, and %SerialNumber% used when it is.

    Thanks!

    -Matt


    There's no place like 127.0.0.1

    Tuesday, October 18, 2016 6:50 PM

Answers

  • You could do that with an external script specified in your customsettings.ini file.

    Customsettings.ini:
    OSDComputerName=#GetComputerName.vbs#

    Create GetComputerName.vbs script:

    If oEnvironment.Exists("OSDComputerName")  then
      If ((Left(oEnvironment.Item("OSDComputerName"),7) = "MININT-") Then
         return oEnvironment.Item("SerialNumber")
      Else
         return oEnvironment.Item("OSDComputerName")
      End if
    Else
      return oEnvironment.Item("SerialNumber")
    End If
    

    • Edited by Gaëtan Hermann Tuesday, October 18, 2016 8:20 PM
    • Proposed as answer by Gaëtan Hermann Tuesday, October 18, 2016 8:40 PM
    • Marked as answer by Matt5150 Thursday, October 20, 2016 6:06 PM
    Tuesday, October 18, 2016 7:58 PM
  • I think I figured it out.  I don't think it liked both the function and the script sharing the same name.  I replaced "GetComputerName" with "GetCN", and now it seems to be working.

    GetComputername.vbs

    Function UserExit(sType, sWhen, sDetail, bSkip) 
      UserExit = Success 
    End Function 
    Function GetCN(sComputerName,sSerialNumber)
      If (Left(sComputerName,7) = "MININT-") Then
        GetCN = "MDT-" & Right(sSerialNumber,7)
      Else
        GetCN = sComputerName
      End If
    End Function

    CustomSettings.ini

    UserExit=GetComputerName.vbs
    OSDComputerName=#GetCN("%ComputerName%","%SerialNumber%")#

    -Matt


    There's no place like 127.0.0.1

    • Marked as answer by Matt5150 Thursday, October 20, 2016 6:05 PM
    Thursday, October 20, 2016 5:50 PM
  • CustomSettings.ini
    OSDComputerName=#GetCN("%ComputerName%","%SerialNumber%","%Model%")#

    GetComputerName.vbs

    Function UserExit(sType, sWhen, sDetail, bSkip) 
      UserExit = Success 
    End Function 
    Function GetCN(sComputerName,sSerialNumber,sModel)
      If (InStr(1, sModel, "Surface", 1) > 0) Then
        GetCN = "MSTR-T" & Right(sSerialNumber,6)
      Elseif (Left(sComputerName,7) = "MININT-") Then
        GetCN = "MSTR-" & Right(sSerialNumber,7)
      Else
        GetCN = sComputerName
      End If
    End Function
    

    • Proposed as answer by Gaëtan Hermann Monday, October 24, 2016 6:06 PM
    • Marked as answer by Matt5150 Monday, October 24, 2016 6:42 PM
    Monday, October 24, 2016 6:06 PM

All replies

  • You could do that with an external script specified in your customsettings.ini file.

    Customsettings.ini:
    OSDComputerName=#GetComputerName.vbs#

    Create GetComputerName.vbs script:

    If oEnvironment.Exists("OSDComputerName")  then
      If ((Left(oEnvironment.Item("OSDComputerName"),7) = "MININT-") Then
         return oEnvironment.Item("SerialNumber")
      Else
         return oEnvironment.Item("OSDComputerName")
      End if
    Else
      return oEnvironment.Item("SerialNumber")
    End If
    

    • Edited by Gaëtan Hermann Tuesday, October 18, 2016 8:20 PM
    • Proposed as answer by Gaëtan Hermann Tuesday, October 18, 2016 8:40 PM
    • Marked as answer by Matt5150 Thursday, October 20, 2016 6:06 PM
    Tuesday, October 18, 2016 7:58 PM
  • Ah, awesome!  Thanks!

    I may have been overthinking it.  Didn't think of scripting a substitution.

    -Matt


    There's no place like 127.0.0.1

    Tuesday, October 18, 2016 8:35 PM
  • Hmm.  I saved your code above as ".\Scripts\GetComputerName.vbs"

    Then replaced my ";OSDComputername=MDT-#Right("%SerialNumber%",7)#"

    ...with "OSDComputerName=#GetComputerName.vbs#"

    When the computer name prompt comes up in Computer Details, it's showing #GetComputerName.vbs#" as the computer name.  Did I miss a step?


    There's no place like 127.0.0.1

    Tuesday, October 18, 2016 9:33 PM
  • UserExit=GetComputerName.vbs
    OSDComputerName=#GetComputerName("%OSDComputerName%")#
    Wednesday, October 19, 2016 6:57 PM
  • UserExit=GetComputerName.vbs
    OSDComputerName=#GetComputerName("%OSDComputerName%")#

    Now it's back to default behavior.

    I'm getting better at PowerShell but I'm still weak with VBscript. But it looks like OSDComputername= is now calling a function called "GetComputerName()".  Does the VBscript need to be modified to declare this as a function first?


    There's no place like 127.0.0.1

    Wednesday, October 19, 2016 7:22 PM
  • Yes of course. You need to change code. This was only an example. See https://technet.microsoft.com/en-us/library/dn744274%28v=ws.11%29.aspx?f=255&MSPPError=-2147217396
    Wednesday, October 19, 2016 7:36 PM
  • Function UserExit(sType, sWhen, sDetail, bSkip) 
      UserExit = Success 
    End Function 
    Function GetComputerName(sComputerName,sSerialNumber)
      If (Left(sComputerName,7) = "MININT-" Then
        GetComputerName = "MDT-" & Right(sSerialNumber,7)
      Else
        GetComputerName = sComputerName
      End If
    End Function
    

    Customsettings.ini:
    UserExit=GetComputerName.vbs
    OSDComputerName=#GetComputerName("%OSDComputerName%","%SerialNumber%")#

    Wednesday, October 19, 2016 7:46 PM
  • Ok that makes total sense now.  Sorry for misunderstanding.

    I saved your updated script "GetComputerName.vbs" to \\Server\DeploymentShare\Scripts\

    I added The UserExit and OSDComputerName lines to my CustomSettings.ini.

    I'm still getting default behavior though.  (USB show MINNT-, and LiteTouch.vbs shows %computername%)

    -Matt


    There's no place like 127.0.0.1

    Wednesday, October 19, 2016 9:31 PM
  • Sorry, missing ) after "MININT-".

    Function UserExit(sType, sWhen, sDetail, bSkip) 
      UserExit = Success 
    End Function 
    Function GetComputerName(sComputerName,sSerialNumber)
      If (Left(sComputerName,7) = "MININT-") Then
        GetComputerName = "MDT-" & Right(sSerialNumber,7)
      Else
        GetComputerName = sComputerName
      End If
    End Function

    And this:

    Customsettings.ini:
    UserExit=GetComputerName.vbs
    OSDComputerName=#GetComputerName("%ComputerName%","%SerialNumber%")#

    Thursday, October 20, 2016 1:11 PM
  • Sorry, missing ) after "MININT-".

    Function UserExit(sType, sWhen, sDetail, bSkip) 
      UserExit = Success 
    End Function 
    Function GetComputerName(sComputerName,sSerialNumber)
      If (Left(sComputerName,7) = "MININT-") Then
        GetComputerName = "MDT-" & Right(sSerialNumber,7)
      Else
        GetComputerName = sComputerName
      End If
    End Function

    And this:

    Customsettings.ini:
    UserExit=GetComputerName.vbs
    OSDComputerName=#GetComputerName("%ComputerName%","%SerialNumber%")#

    I just noticed your edit to the CS.ini lines.  Retrying that next.

    -Matt


    There's no place like 127.0.0.1

    Thursday, October 20, 2016 3:17 PM
  • Sorry, missing ) after "MININT-".

    Function UserExit(sType, sWhen, sDetail, bSkip) 
      UserExit = Success 
    End Function 
    Function GetComputerName(sComputerName,sSerialNumber)
      If (Left(sComputerName,7) = "MININT-") Then
        GetComputerName = "MDT-" & Right(sSerialNumber,7)
      Else
        GetComputerName = sComputerName
      End If
    End Function

    And this:

    Customsettings.ini:
    UserExit=GetComputerName.vbs
    OSDComputerName=#GetComputerName("%ComputerName%","%SerialNumber%")#

    I just noticed your edit to the CS.ini lines.  Retrying that next.

    -Matt


    There's no place like 127.0.0.1

    Now the Computer Name field is being populated with:

    #GetComputerName("%CurrentPCName%","%FullSerialNumber%")#


    There's no place like 127.0.0.1


    • Edited by Matt5150 Thursday, October 20, 2016 5:33 PM Typo
    Thursday, October 20, 2016 4:06 PM
  • I think I figured it out.  I don't think it liked both the function and the script sharing the same name.  I replaced "GetComputerName" with "GetCN", and now it seems to be working.

    GetComputername.vbs

    Function UserExit(sType, sWhen, sDetail, bSkip) 
      UserExit = Success 
    End Function 
    Function GetCN(sComputerName,sSerialNumber)
      If (Left(sComputerName,7) = "MININT-") Then
        GetCN = "MDT-" & Right(sSerialNumber,7)
      Else
        GetCN = sComputerName
      End If
    End Function

    CustomSettings.ini

    UserExit=GetComputerName.vbs
    OSDComputerName=#GetCN("%ComputerName%","%SerialNumber%")#

    -Matt


    There's no place like 127.0.0.1

    • Marked as answer by Matt5150 Thursday, October 20, 2016 6:05 PM
    Thursday, October 20, 2016 5:50 PM
  • Perfect! Sorry for the misunderstanding and code errors previously.
    Thursday, October 20, 2016 8:49 PM
  • No problem, thank you very much for your help!

    Works exactly as I had hoped. ;)

    LiteTouch from within Windows.

    LiteTouch from USB


    There's no place like 127.0.0.1

    Thursday, October 20, 2016 10:13 PM
  • Curious, if I wanted to add one more piece of functionality here how hard would it be?

    It would be super handy if I could have it check WMI to see if model name is LIKE "Surface", and if it is, add a "T" for tablet...

    I've tried a couple variations but unlike PowerShell I can't seem to stack / add IF statements to the function correctly.  Back to getting "#GetCN("%MININT-BLAH%","%SN12345%","Surface Pro 3")#"

    Any advise on what to tweak here?

    CustomSettings.ini

    OSDComputerName=#GetCN("%ComputerName%","%SerialNumber%",%Model%)#

    GetComputerName.vbs

    Function UserExit(sType, sWhen, sDetail, bSkip) 
      UserExit = Success 
    End Function 
    Function GetCN(sComputerName,sSerialNumber,sModel)
      If sModel like "Surface" Then
        GetCN = "MSTR-T" & Right(sSerialNumber,6)
      Elseif (Left(sComputerName,7) = "MININT-") Then
        GetCN = "MSTR-" & Right(sSerialNumber,7)
    
      Else
        GetCN = sComputerName
      End If
    End Function

    -Matt


    There's no place like 127.0.0.1

    Monday, October 24, 2016 4:18 PM
  • CustomSettings.ini
    OSDComputerName=#GetCN("%ComputerName%","%SerialNumber%","%Model%")#

    GetComputerName.vbs

    Function UserExit(sType, sWhen, sDetail, bSkip) 
      UserExit = Success 
    End Function 
    Function GetCN(sComputerName,sSerialNumber,sModel)
      If (InStr(1, sModel, "Surface", 1) > 0) Then
        GetCN = "MSTR-T" & Right(sSerialNumber,6)
      Elseif (Left(sComputerName,7) = "MININT-") Then
        GetCN = "MSTR-" & Right(sSerialNumber,7)
      Else
        GetCN = sComputerName
      End If
    End Function
    

    • Proposed as answer by Gaëtan Hermann Monday, October 24, 2016 6:06 PM
    • Marked as answer by Matt5150 Monday, October 24, 2016 6:42 PM
    Monday, October 24, 2016 6:06 PM
  • Ah, context (and typo) issue. :)

    Works perfect, thanks!

    -Matt


    There's no place like 127.0.0.1


    • Edited by Matt5150 Monday, October 24, 2016 6:44 PM Typo
    Monday, October 24, 2016 6:43 PM