I was trying to get this OUT of a VBScript and into cs.ini. :-)

(not my script but this is it...)



On Error Resume Next
DIM Gateway(7)
strComputer = "."

set objTSEnvironment=CreateObject("Microsoft.SMS.TSEnvironment")
Set objWMIService=GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" 
& strComputer & "\root\cimv2")
Set colAdapters=objWMIService.ExecQuery ("SELECT * FROM 
Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Set colSerial=objWMIService.ExecQuery ("SELECT * FROM Win32_BIOS")
Set colBat=objWMIService.ExecQuery( "Select * from Win32_Battery")
Set colItems=objWMIService.ExecQuery("Select * From Win32_computersystem where 
Model='VirtualBox' or Model='VMware Virtual Platform' or Model='Xen' or 
Model='Virtual Machine'")
Set colUUIDItems=objWMIService.ExecQuery("Select * from 
Win32_ComputerSystemProduct")
Set WshShell = CreateObject("WScript.Shell")

'Arrays
Gateway(1)="BHM,10.99.1.1,10.102.1.1,10.103.1.1,10.104.1.1,10.105.1.1,10.106.1.1,10.107.1.1,10.108.1.1,10.200.1.1,10.210.1.1,10.255.0.1"
Gateway(2)="CHR,10.64.1.1"
Gateway(3)="HSV,10.60.1.1"
Gateway(4)="MTG,10.61.1.1"
Gateway(5)="NSV,10.10.100.1,172,17.0.1,172.18.0.1,10.10.100.1,172.17.0.1,172.18.0.1,172.19.0.1"
Gateway(6)="WDC,10.65.1.1"
Gateway(7)="JKS,10.62.1.1"

Set ProgressUI = CreateObject("Microsoft.SMS.TsProgressUI")
ProgressUI.CloseProgressDialog

'Getting Default Gateway
For Each objAdapter in colAdapters
   If Not IsNull(objAdapter.DefaultIPGateway) Then
      For i = 0 To UBound(objAdapter.DefaultIPGateway)
        strGateway=objAdapter.DefaultIPGateway(i)
        For a=1 to UBound(Gateway)
            If instr(Gateway(a),strGateway)<>0 Then
                strLoc=Left(Gateway(a),3)
                GetAltLocation
            End If
        Next
      Next
   End If
Next

'Getting Serial Number
For Each objSerial in colSerial
    strSerial=objserial.serialnumber
Next

'Checking for HW Type
strType="D"
strOSType="Windows7"
For Each objItem in colBat
    For Each objVMItem in colItems
        If objVMItem.model <> "VirtualBox" Then
            strType="L"
        End If
    Next
Next

'VM Specific Settings
For Each objItem in colItems
    If objitem.model="VMware Virtual Platform" Then
        strIsVMWare="yes"
    End If
    For Each UUIDItem in colUUIDItems
        strSerial=Right(UUIDitem.UUID,7)
        strType="V"
        strOSType="Windows7"
        ServerBuildCheck
    Next
Next

If strType <> "V" Then
    If strType <> "S" Then
        ThinClientCheck
    End If
End If

'Setting OU Path
If strType="L" Then strOUPath="OU=Laptops,OU=Computers,OU=" & strLoc & 
",OU=FrontEnd,DC=MYDOMAIN,DC=com"
If strType="D" Then strOUPath="OU=Desktops,OU=Computers,OU=" & strLoc & 
",OU=FrontEnd,DC=MYDOMAIN,DC=com"
If strType="V" Then strOUPath="OU=Virtual,OU=Computers,OU=" & strLoc & 
",OU=FrontEnd,DC=MYDOMAIN,DC=com"
If strType="S" Then strOUPath="OU=Deployment Testing,OU=Servers,OU=" & strLoc & 
",OU=BackEnd,DC=MYDOMAIN,DC=com"
If strType="T" Then strOUPath="OU=Desktops,OU=Computers,OU=" & strLoc & 
",OU=FrontEnd,DC=MYDOMAIN,DC=com"
If strType="SD" Then 
strOUPath="OU=SharedDesktops,OU=XenApp,OU=Citrix,OU=FrontEnd,DC=MYDOMAIN,DC=com"

'Setting TS Variables
objTSEnvironment("Location")=strLoc
objTSEnvironment("SN")=strSerial
objTSEnvironment("HWType")=strType
If strType="SD" Then
    objTSEnvironment("CompName")=strServerName
Else
    objTSEnvironment("CompName")=strLoc & "-" & strType & "-" & strSerial
End If

objTSEnvironment("OUPath")=strOUPath
objTSEnvironment("OSType")=strOSType
objTSEnvironment("VMWARE")=strIsVMWare
objTSEnvironment("SharedDesktop")=strIsSharedDesktop
sub GetAltLocation
Set WshShell = CreateObject("WScript.Shell")
strTimeOut=WshShell.Popup("Will this machine be used at different location?" & 
vbCrLf & "(This Message Will Close in 10 Seconds)", 10, "Location Check", 4 + 
32)
    If strTimeOut=6 Then
        strInput=InputBox("If this machine is NOT being built for " & strLoc & 
vbCrLf & "Please enter the number from the list below" & vbCrLf & "1. BHM" & 
vbCrLf & "2. CHR" & vbCrLf & "3. HSV" & vbCrLf & "4. JKS" & vbCrLf & "5. MTG" & 
vbCrLf & "6. NSV" & vbCrLf & "7. WDC", "Alternate Location Selction")
        If IsNumeric(strInput)=0 Then
            ErrorRoutine
        ElseIf strInput <> "" Then
            If strInput < 8 Then
                If strInput=1 Then strLoc="BHM"
                If strInput=2 Then strLoc="CHR"
                If strInput=3 Then strLoc="HSV"
                If strInput=4 Then strLoc="JKS"
                If strInput=5 Then strLoc="MTG"
                If strInput=6 Then strLoc="NSV"
                If strInput=7 Then strLoc="WDC"
            Else
                ErrorRoutine
            End If
        End If
    End If
End Sub

Sub ErrorRoutine
Set WshShell = CreateObject("WScript.Shell")
strError=WshShell.Popup("You have not enetered a incorrect answer" & vbCrLf & " 
Do you want to select again?" & vbCrLf & "(This Message Will Close in 10 
Seconds)", 10, "Incorrect Selection Made", 4 + 32)
If strError=6 Then
    strInput=""
    strError=""
    GetAltLocation
End If
End Sub

Sub ServerBuildCheck
Set WshShell = CreateObject("WScript.Shell")
    strServerTimeOut=WshShell.Popup("Virtual hardware has been detected." & 
vbCrLf & "The default OS is Windows 7, would you like to change it to Windows 
Server 2008 R2?" & vbCrLf & "(This Message Will Close in 15 Seconds)", 15, 
"Virtual Hardware Detected", 4 + 32)
    If strServerTimeOut=6 Then
        strType="S"
        strOSType="Server"
        strServerName=InputBox("Please enter a name for the new Server:", 
"Server Name Prompt")
        strIsSharedDesktop="no"
        strSharedDesktopOU=msgbox("Will this machine be used as Citrix Shared 
Desktop?",4,"Citrix Shared Desktop Prompt")
        If strSharedDesktopOU=6 Then
            strIsSharedDesktop="yes"
            strType="SD"
        End If
    End If
End Sub

Sub ThinClientCheck
Set WshShell = CreateObject("WScript.Shell")
    strServerTimeOut=WshShell.inputbox("Physical hardware has been detected." & 
vbCrLf & "The default OS is Windows 7, would you like to change it to Windows 
Thin PC?" & vbCrLf & "(Windows Thin PC is used for a thin client host system" & 
vbCrLf & "(This Message Will Close in 15 Seconds)", 15, "Physical Hardware 
Detected", 4 + 32)
    If strServerTimeOut=6 Then
        strType="T"
        strOSType="Thin"
    End If
End Sub

________________________________
John Marcum
Sr. Desktop Architect
Bradley Arant Boult Cummings LLP
________________________________

From: [email protected] [mailto:[email protected]] On 
Behalf Of Radamis, Andrew
Sent: Thursday, July 25, 2013 8:29 AM
To: [email protected]
Subject: [mssms] RE: Complex Computer Naming

I used a VBS script to accomplish something far less complex than this. Put 
your logics in, but here's the meat.

Set oTaskSequence = CreateObject ("Microsoft.SMS.TSEnvironment")
'Code to define the value of sCompName
oTaskSequence("OSDComputername") = sCompName

As you may have guessed, the above script will set the Task Sequence variable 
OSDComputerName to whatever you need when you call it from your Task Sequence. 
You can also accomplish this in PowerShell as well, see below.

$TS_Env = New-Object -COMObject Microsoft.SMS.TSEnvironment
#Code to define $sCompName
$TS_Env.Value("OSDComputername") = $sCompName

Hope that helps,

Andrew

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]]<mailto:[mailto:[email protected]]>
 On Behalf Of Marcum, John
Sent: Thursday, July 25, 2013 9:12 AM
To: SMS List ([email protected]<mailto:[email protected]>)
Subject: [mssms] Complex Computer Naming

In customsettings.ini is it possible to use more than one condition to set 
OSDComputerName? Has anyone done something like this?


Here's what I am trying to accomplish.

1. Default gateway?
2. Physical or Virtual?
3. If physical is laptop or is desktop?
4. serial number if physical UUID if virtual

And I want to end up with a name like this;

First 4 character:
default gateway = 10.10.10.10 or 10.10.10.20 - first 4 letters of computer name 
are "BHM-"

Next two characters:
Virtual is YES - next two letters of computer name are "V-"
Laptop is Yes - - next two letters of computer name are "L-"
Desktop is Yes - - next two letters of computer name are "D-"

Last characters of computer name:

If physical then "serial number"
if virtual then VM#Right(replace("%UUID%"," ",""),8)#

End result would be something like this:

BHM-D-12345678
JKS-L-12345678
NSV-V-12345678






________________________________
John Marcum
Sr. Desktop Architect
Bradley Arant Boult Cummings LLP
________________________________


________________________________

Confidentiality Notice: This e-mail is from a law firm and may be protected by 
the attorney-client or work product privileges. If you have received this 
message in error, please notify the sender by replying to this e-mail and then 
delete it from your computer.


________________________________

Confidentiality Notice: This e-mail is from a law firm and may be protected by 
the attorney-client or work product privileges. If you have received this 
message in error, please notify the sender by replying to this e-mail and then 
delete it from your computer.

________________________________

Confidentiality Notice: This e-mail is from a law firm and may be protected by 
the attorney-client or work product privileges. If you have received this 
message in error, please notify the sender by replying to this e-mail and then 
delete it from your computer.


Reply via email to