sunnyd24
asked on
Comparing two Arrays
Short and sweet, I need to know what computers are in my AD list that aren't in my SCCM list. Everything is returning true whether it is in the list or not.
' ------ SET INPUT FILE ------
strfile="AD_Computer_Names_2.txt"
set iFSO=createobject("scripting.filesystemobject")
set objTS=iFSO.opentextfile(strfile)
strfile2="SCCM_Client_Names_2.txt"
set iFSO2=createobject("scripting.filesystemobject")
set objTS2=iFSO2.opentextfile(strfile)
' ------ SET OUTPUT FILES ------
OutputFile="AD_SCCM.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(OutputFile, True)
x=0
Do While objTS.atendofstream<>true
strADComputer=objts.readline
ReDim Preserve arrADComputers(x)
arrADComputers(x) = UCase(strADComputer)
x=x+1
Loop
y=0
Do While objTS2.atendofstream<>true
strSCCMComputer=objts2.readline
ReDim Preserve arrSCCMComputers(y)
arrSCCMComputers(y) = UCase(strSCCMComputer)
y=y+1
Loop
Set objListSCCM = CreateObject("Scripting.Dictionary")
'objListSCCM.CompareMode = vbTextCompare
For s = 0 To UBound(arrSCCMComputers)
If objListSCCM.Exists(arrSCCMComputers(s)) Then
Else
objListSCCM.add (arrSCCMComputers(s)), (arrSCCMComputers(s))
End If
Next
Set objListAD = CreateObject("Scripting.Dictionary")
'objListAD.CompareMode = vbTextCompare
For t = 0 To UBound(arrADComputers)
If objListAD.Exists(arrADComputers(t)) Then
Else
objListAD.add (arrADComputers(t)), (arrADComputers(t))
End If
Next
For n = 0 To UBound(arrADComputers)
If objListSCCM.Exists(arrADComputers(n)) Then
wscript.echo arrADComputers(n)
Else
Wscript.Echo arrADComputers(n) & " is in AD but not SCCM"
End If
Next
wscript.echo "Done"
Would you be willing to post the files you are comparing or at list a few lines of each?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I just tested it. That appears to be the only thing you missed. Add that 2 in line 8 and you should be fine. I cant tell you how many times I have done something similar.
I also noticed that you output file is not being used. Im not sure what exactly you want it to say in there, but you can add this line inbetween lines 64 and 65.
oFile.write arrADComputers(n)&VbCrLf
oFile.write arrADComputers(n)&VbCrLf
ASKER
TakedaT you were exactly right. I tried running that same code past two other people and no one noticed. I just hadn't gotten around to putting the results to the output file yet because I couldn't get past the compare, but thanks again!