During SCCM OS deployment, you need to add a computer association so you can deploy your OS to a targeted machine. The problem with this is that the computer resource is still left in the collection after deployment. Use this technique to delete the resource once a successful OS deployment is completed:
Copy the below code into a VBS file called remove_from_collection.vbs.
Modify the code so that the sCollectionID = “ABC00013″ has the collection ID of your collection from which the resource will be deleted:
On Error Resume Next
Dim oNetwork, oLocator, oSWbemServices, oCollection
Dim sComputerName, sSMSServer, sSMSSiteCode, sCollectionID, RuleSet
Set oNetwork = CreateObject("WScript.NetWork")
'CollectionID from which to remove the comouter
sCollectionID = "ABC00013"
'————————————————————
'Get Command Line arguments
Set args = WScript.Arguments
sComputername = args.Item(0)
If sComputerName = NULL then
wscript.quit
End if
'————————————————————
'Main script
Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")
swbemLocator.Security_.AuthenticationLevel = 6 'Packet Privacy.
Set swbemServices = swbemLocator.ConnectServer(".", "root\SMS")
Set oProviderLocation = swbemServices.InstancesOf("SMS_ProviderLocation")
For Each oLocation In oProviderLocation
If oLocation.ProviderForLocalSite = True Then
Set swbemServices = swbemLocator.ConnectServer(oLocation.Machine, "root\sms\site_" + oLocation.SiteCode)
End If
Next
Set oCollection = SWbemServices.Get("SMS_Collection='" & sCollectionID & "'")
RuleSet = oCollection.CollectionRules
For Each Rule In RuleSet
If Rule.Path_.Class = "SMS_CollectionRuleDirect" Then
If LCase(Trim(Rule.RuleName)) = LCase(Trim(sComputerName)) Then
oCollection.DeleteMembershipRule Rule
End If
End If
Next
WScript.Quit(0)
Create a Status Filter rule by going to Site Database – Site Management – Primary Site – Site Settings – Status Filter Rules.
On the general tab, use Component : Task Sequence Manager, Message ID: 11171 .
On the actions tab, tick Run a program and use something like ‘cscript.exe D:\SCRIPTS\remove_from_collection.vbs %msgsys’.
This will trigger the script each time a task sequence is reported to the SCCM primary site to be completed successfully and will use the computername (%msgsys) from the status message and remove it from the collection in the script.
Original posting and more discussion here –> http://social.technet.microsoft.com/Forums/en-US/configmgrsdk/thread/9205e49b-9d0e-462e-8998-87e6c31f9c41
Further samples and additional parameter information can be found here http://technet.microsoft.com/en-us/library/bb693758.aspx and http://technet.microsoft.com/en-us/library/cc181183.aspx
Possibly related posts (auto generated):
Related Articles
No user responded in this post
Leave A Reply