We use MDT in our environment to image computers. We are using a script in order to name computers based on IP location and the script then writes the data to a database. I need to modify the script to include a section of additional conditions to construct the computer name. I am having difficulty with the portion that uses the additional condition of Chassis type in the script below.
The portion I need help with is
Case (InStr(1, strIP, ".111.")>0),(strChassisType = 8,9 Or 10)
strSiteCode="UKL"
Case (InStr(1, strIP, ".112.")>0),(strChassisType = 8,9 Or 10)
strSiteCode="NYL"
Case (InStr(1, strIP, ".113.")>0),(strChassisType = 8,9 Or 10)
strSiteCode="HKL"
I would like to have these three conditions work and set the site code based on the condition of Site and then chassis type, but I am not sure how to use multiple conditions or how to combine the chassis type and would like guidance.
Following is the full script
Function UserExit(sType, sWhen, sDetail, bSkip)
oLogging.CreateEntry "entered UserExit ", LogTypeInfo
UserExit = Success
End Function
Function computerName()
'On Error Resume Next
Dim strSerial,strAsset, strManufacturer, strIP, strSiteCode
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WSHShell = CreateObject("WScript.Shell")
'----Establish SQL Connection----
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=sqloledb;Data Source=XXXXXXXX;Initial Catalog=NetMetrics;User Id=netmetrics;Password=*********;"
'----Determine local Service & Asset Tags----
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
For Each objSMBIOS In colSMBIOS
strManufacturer = objSMBIOS.Manufacturer
strSerial = objSMBIOS.SerialNumber
Next
'----Determine Site Code based upon IP address----
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
strIP = strIP + IPConfig.IPAddress(i)
Next
End If
Next
Set colChassis = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
For Each objChassis in colChassis
For Each strChassisType in objChassis.ChassisTypes
Select Case strChassisType
Select Case True
Case (InStr(1, strIP, ".111.")>0)
strSiteCode = "UK"
Case (InStr(1, strIP, ".112.")>0)
strSiteCode = "NY"
Case (InStr(1, strIP, ".113.")>0)
strSiteCode = "HK"
Case (InStr(1, strIP, ".111.")>0),(strChassisType = 8,9 Or 10)
strSiteCode = "UKL"
Case (InStr(1, strIP, ".112.")>0),(strChassisType = 8,9 Or 10)
strSiteCode = "NYL"
Case (InStr(1, strIP, ".113.")>0),(strChassisType = 8,9 Or 10)
strSiteCode = "HKL"
End Select
If (inStr(1,strManufacturer,"Dell")) Then
strSQLQuery = "select count(*) from AssetTags where ServiceTag='" & strSerial & "'"
priorEntry = objConnection.Execute(strSQLQuery)
If priorEntry(0) = 0 Then
strSQLQuery = "select right(concat('00',right(max(assettag),3)+1),3) from AssetTags where AssetTag like '" & strSiteCode & "[^S]%'"
Set arrNewTag = objConnection.Execute(strSQLQuery)
strSQLQuery = "INSERT INTO AssetTags Values ('" & strSerial & "','"& strSiteCode & arrNewTag(0) & "', 'New')"
objConnection.Execute(strSQLQuery)
computerName=(strSiteCode & arrNewTag(0))
Else
strSQLQuery = "select assettag from AssetTags where ServiceTag='" & strSerial & "'"
Set arrNewTag = objConnection.Execute(strSQLQuery)
computerName=(arrNewTag(0))
End If
Else
computerName = "Set Computer Name"
End If
objConnection.Close
End Function