다음 사용 가능한 컴퓨터 이름에 대해 AD를 쿼리해야하는이 VBScript를 온라인에서 찾았습니다. 실행하려고 할 때 다음 오류가 발생합니다.
51 행 문자 1
Do없는 루프
문제의 스크립트는 다음과 같습니다.
StrAvailableName = FindAvailableName("TestWS")
Function FindAvailableName(StrPrefix)
'*****************************************
'* Search for an available computer name *
'*****************************************
Const ADS_SCOPE_SUBTREE = 2
Dim nCount, PCName,PCExist
Dim objConnection, objCommand,objRecordSet,PCVar
nCount = 1
PCName = StrPrefix & "0" & nCount
PCExist = False
Do Until PCExist
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
'Enter your LDAP search root for your domain here 'LDAP://dc=corp,dc=com'
objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://dc=test-dc,dc=test,dc=local' WHERE objectCategory='computer' " & "AND name=' " & PCName & "'"
Set objRecordSet = objCommand.Execute
PCVar = ""
if not (objRecordSet.EOF And objRecordSet.BOF) Then
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
WScript.Echo objRecordSet.Fields("ADsPath").Value
PCVar = objRecordSet.Fields("ADsPath").Value
objRecordSet.MoveNext
Loop
nCount = nCount + 1
if nCount < 10 then
PCName = StrPrefix & "0" & nCount
else
PCName = StrPrefix & nCount
End If
IF PCVar = "" Then
PCExist = True
END IF
Loop
AvailablePCName = PCName
End Function
누구든지이 코드의 문제점을 식별 할 수 있습니까?
결과 할당 직전 인 End If
최종 Loop
문 바로 앞에 추가해야 합니다. 그것이으로,이 Loop
오프 닫으려고한다 If
하여 오류의 원인이되는 블록.
...
if PCVar = "" Then
PCExist=True
END IF
End If 'Add this
Loop
AvailablePCName = PCName
End Function
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다