johnnyjonathan
asked on
SCCM 2012 Users to Computer collection import vbs
Hi,
i have used the attached VBS to do a very simple task, i created an empty computer collection in SCCM, added a text file of users from active directory, ran the script and it would check the last computer login of each user in the last and add it to the collection.
This script ran well in a completely different domain environment and with SCCM 2007, now i have a new domain with SCCM2012, and when i ran it i always get "User not found".
anyone have any idea on what i need to do to modify the script\my environment so it will work?
Thanks in advance.
i have used the attached VBS to do a very simple task, i created an empty computer collection in SCCM, added a text file of users from active directory, ran the script and it would check the last computer login of each user in the last and add it to the collection.
This script ran well in a completely different domain environment and with SCCM 2007, now i have a new domain with SCCM2012, and when i ran it i always get "User not found".
anyone have any idea on what i need to do to modify the script\my environment so it will work?
on error resume next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("Test.txt", ForReading, True, TristateUseDefault)
Do While file.AtEndOfStream <> True
newname= "Test"
comname = file.readline
Dim lLocator
Set lLocator = CreateObject("WbemScripting.SWbemLocator")
Dim gService
Set gService = lLocator.ConnectServer(, "root\sms\SERVER_CODE")
ResID = 0
Set Computers = gService.ExecQuery("Select * From SMS_R_system WHERE LastLogonUserName LIKE ""%" + comname + "%""")
For Each Comp In Computers
If UCase(comp.LastLogonUserName) = UCase(comname) Then ResID = comp.ResourceID
Next
If ResID = 0 Then WScript.echo "not found:" + comname
Dim CollectionRule
Set CollectionRule = gService.Get("SMS_CollectionRuleDirect").SpawnInstance_()
CollectionRule.ResourceClassName = "SMS_R_System"
CollectionRule.RuleName = "ResourceID=" & ResID
CollectionRule.ResourceID = ResID
Dim oCollectionSet
Dim oCollection
Set oCollectionSet = gService.ExecQuery("Select * From SMS_Collection")
For Each oCollection In oCollectionSet
' WScript.Echo oCollection.Name
If oCollection.Name = newname Then
oCollection.AddMembershipRule CollectionRule
If Err.Number = 0 Then
Wscript.Echo comname + " were added to the " + oCollection.Name + " collection!"
End If
End If
Next
Loop
file.close
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER