So I've been searching for the better half of my work shift now, and I cannot seem to find the answers I need. I'm writing a VBScript that searches the Active Directory for a computer object. If the object does not exist or exists and is in the correct OU, then it should run a separate script that creates/joins the computer to the AD.
ObjExist_CorrectOU_7 = Null
ObjExist_CorrectOU_10 = Null
If compare = True Then
Win7_OU = "OU=DisallowRDP,OU=64Bit,OU=Win8"
Win10_OU = "OU=DisallowRDP,OU=64Bit,OU=Win10"
For x = 16 to 46
If Asc(Mid(objRS.Fields("distinguishedName"), x, 1)) = Asc(Mid(Win7_OU, (x - 15), 1)) Then
ObjExist_CorrectOU_7 = True
Else ObjExist_CorrectOU_7 = False
End If
Next
For y = 16 to 46
If Asc(Mid(objRS.Fields("distinguishedName"), y, 1)) = Asc(Mid(Win10_OU, (y - 15), 1)) Then
ObjExist_CorrectOU_10 = True
Else ObjExist_CorrectOU_10 = False
End If
Next
End If
If ObjExist_CorrectOU_7 = True Then
Wscript.Echo "TRUE"
End If
Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")
filename = "C:\programdata\dell\kace\k2000_deployment_info.conf"
Win7_Deployment = "deployment_name=Windows 7 x64 with SP1, join AD"
Win10_Deployment = "deployment_name=Development Windows 10 (x64), join AD"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename)
Do While Not f.AtEndOfStream
If ((f.ReadLine = Win7_Deployment) Or ((f.ReadLine = Win7_Deployment) And (ObjExist_CorrectOU_7 = True))) Then
Wscript.Echo "IT WORKED!"
'objShell.Run "JoinAD_Win7.vbs"
Exit Do
End If
On Error Resume Next
Loop
f.Close
Set g = fso.OpenTextFile(filename)
Do While Not f.AtEndOfStream
If ((g.ReadLine = Win10_Deployment) Or ((g.ReadLine = Win10_Deployment) And (ObjExist_CorrectOU_10 = True))) Then
'objShell.Run "JoinAD_Win10.vbs"
Wscript.Echo "IT WORKED AGAIN!"
Exit Do
End If
On Error Resume Next
Loop
g.Close
Set objShell = Nothing
The problem I'm running into (as I am trying to learn VBS as I go) is that I most likely have a logic error that I do not know. The two If, Then statements execute every time when I know the conditions are absolutely NOT being met.
Does it have to do with my use of "Or" and "And"?
Please, any help would be great. Thanks!
Aucun commentaire:
Enregistrer un commentaire