我们在我们的环境中使用 MDT 来对计算机进行映像。我们使用脚本来根据 IP 位置命名计算机,然后脚本将数据写入数据库。我需要修改脚本以包含一部分附加条件来构造计算机名称。我在下面的脚本中使用机箱类型的附加条件的部分有困难。
我需要帮助的部分是
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"
我想让这三个条件起作用并根据站点条件然后底盘类型设置站点代码,但我不确定如何使用多个条件或如何组合底盘类型并希望指导。
以下是完整的脚本
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