MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.
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
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.