我們在我們的環境中使用MDT對計算機進行映像。我們正在使用腳本來命名基於IP位置的計算機,然後腳本將數據寫入數據庫。我需要修改腳本以包含一部分附加條件來構造計算機名稱。我在下面的腳本中遇到了使用機箱類型附加條件的部分有問題。使用ChassisType選擇案例的多個條件
我需要幫助的部分是
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
歡迎來到StackOverflow。您似乎沒有指定代碼出了什麼問題,您得到了什麼錯誤,或者期望的結果是什麼。這將使其不太可能爲您的問題吸引高質量的答案。 –
上面的編輯。我認爲我很清楚,我在Chassis類型的多種條件下遇到困難。我不知道如何正確合併它們。該腳本沒有返回結果,並且它是「Expected」的錯誤)「 – MarliejoS5