When using a mandatory OSD advertisement to install a Operating system it is a great benefit to remove the computer from the Collection to where the OS deployment is advertised. The OSD task sequence advertisement can then be set to always rerun and all problems related to reinstalling an existing computer is solved.
This can be achieved by using a status filter rule together with a VBscript which removes the computer from the collection once the Task Sequence completes successfully.
UPDATE!!
I have updated the script to search for active computer records in SCCM using the name and then removing the computer from the collection using the ResourceID instead of using the name for matching. I have seen at customers that some third party applications created direct memberships with a different naming convention than the SCCM Admin Console does, this updated script will solve this problem.
Update 2
The script have been updated with the possibility to enter more than one collection to remove the computer from, it can also write an event to the event-log on the SCCM server with the name of the computer and the collection/collections it will be removed from.
I have removed the script code from this blog and made it available as a file instead, to avoid problems when cut/pasting the text.
You can download it here: https://ccmexec.com/wp-content/uploads/2010/12/Remove.vbs.txt
Download the script and save it as “remove.vbs” edit the following line with the collection/collections you want the computer removed from
sCollectionIDs = “00100053:0010004A:00100069”
when that is done, complete the steps below to configure the status filter rule.
Configuring the status filter rule:
- Under site settings create a new status filter rule
- Configure it to use the following settings:
Component : Task Sequence Manager
Message Id: 11171
Run a Program: cscript.exe e:\sccmtools\remove.vbs %msgsys
This looks like a great workaround and automation piece for OSD with SCCM 2007. However I am finding that i do not have the Task Sequence Manager in my component drop down. Anyone know why this would be?
Thanks,
Eric
I also have the same problem as Eric. I had to type in “Task Sequence Manager” into the component field, as it wasn’t in the drop down.
After testing, I can see it logged in the eventviewer but the pc is still in the collection. I have updated the sCollectionIDs = “PER0000F” Collection where the PC is associated.
Any Ideas?
Regards,
Jon
I have used your tool…its really very helpful.
Excellent script, worked like a charm.
Like others here I had to type in “Task Sequence Manager” in the component field, apart from that no issues.
Tim.
I’m using this script on some software deployment collections and it works great. I’m having some issues getting it to work for OSD collections though. If a computer is renamed during the OSD task sequence it doesn’t seem to work. If it keeps the name it works fine. The comments above suggest this should work based on how it does the look up, at least that is how I interpreted it, but doesn’t seem to be the case for me. Pretty much we pull a computer from the box, it gets imported with a simple name and then the task sequence is run which renames the computer. Anyone have any idea what the problem might be? I know the obvious answer is to import with the final name but the goal is to automate as much as possible and remove as many chances for human error as we can.
Thanks for sharing the script. I installed it and changed the collection ID, it appears not removal. Any possibile reason? Thanks!
Hi Neil,
You can use the event-log option to make sure that the event i generated.
Make sure you typed the component correctly
make sure that you run cscript and then the full path to the script
Jared,
I haven’t tried the script in an environment where you actually rename the computer during the TS. The script still uses the computername to remove it “='” & strComputerName & “”, as this is what is passed to the script from the Status Message. I then use the resourceID for the removal from the collection to make sure that the correct computer is removed, not obsolete e.tc.
So this scenario would be hard as the computername is what is passed from the client.
Nice script and it does work.
However i do have one issue – if i import a system, it than boots through PXE, TS walks throug etc. untill it is finished. I do see the correct event in TS log, but don’t see this script fired up, and there is no event beeing created in system log.. A few minutes later SCCM client on the freshly installed system pick’s up the advertisment and runs the TS again. After the second run the system is removed from collection and the corresponding event entry is created in system log.
I’m kind of curious if it is my SCCM or something else?
after some research i’ve discovered that a different script, which removes a system by name, does the job and removes a system after the first run. so, it looks like the script is showing some unexpected behavior.
Thanks for the script, it’s just what I needed to easily create “permanent” OSD collections where computers can be rejoined if needed to reinstall.
Just one thing.. The script seems to work only randomly. Most of the time it works, but sometimes it just leaves the computer in the collection. Status filter rule creates an event log event like this:
“On 16.9.2011 14:44:26, component Task Sequence Manager on computer reported: The task sequence manager successfully completed execution of the task sequence.”
So, the status filter seems to work like supposed, but the next event logged by the script only appears randomly, even for the same computer in the same collection. Either it just doesn’t run the script at all (unlikely) or the script does not complete successfully.
That seems to occur at least if you just add the computer into the OSD collection by MAC address using “Import computer, single computer” task, do not refresh any collection memberships in the console or the console views and just PXE boot the computer up.
Any ideas why?
I’ve changed the folloing line from original:
Set arrComputers = SWbemServices.ExecQuery(“select * from SMS_R_System where Name='” & strComputerName & “‘ and not Obsolete = 0”)
Into:
Set arrComputers = SWbemServices.ExecQuery(“select * from SMS_R_System where Name='” & strComputerName & “‘”)
sins the freshly imported systems have got Obsolete not set, the original query doesn’t work on them.
Thanks for such a useful script.
It works for me but for the collection that I added the PC to it for Deploy OS. After Installation script remove the pc so far it sounds good, but now I have 2 pc’s with same name in original collection (i.e “All Windows 7 Systems”).
I added the “All Windows 7 Systems” collection ID to the script to delete the old name, but the script still remove the pc just from the deployment collection not original collection!
Has anyone any idea ?
Thanks,
Bab
Is it the built in “All Windows 7 Systems” you are refeering to? in that case it is not a direct memberhsip but a query based membership and the computer cannot be removed from it because of it.
Regards,
Jörgen
Hej Jörgen,
Yes. it is built in collection. Thanks for this point.
Do you have any solution that what should I do with this issue (duplicate name built in collection) ?!
Because as you know after deployment, in the built in collection the previous name gets detective and the new one created with the same name but in active mode. so I’m looking for a solution to remove the deactivated one after deployment automatically not manually every time !
Tack,
Bab
Hey Jorgen, your script works great but for some reason it’s removing the computer even if the collection id is not in the script. I believe its only suppose to remove it if the collection id is in the script. Is this correct or does it search all the collections and remove it from any collection that the machine may be in?
Hi,
Thanos, it should only remove it from the collection you specify in the script, nothing else.
Regards,
/Jörgen
I am using this script but I am looking for one that would ADD a computer to a collection using a status filter rule. I have a dynamic collection base on files of a particular application that I want to removed and when the status flag is succesful add that same computer to another collection to have a new application installed on it.
Anyone?
I can’t get this to work. I’ve tested it using both the PC ID and the GUID on the command line, but neither works.
My command line looks like this:
remove.vbs [name_of_PC]
or
remove.vbs [GUID_of_PC]
I created a test collection in SCCM, added my PC to it, then added the collection ID to the script, but running the script doesn’t remove my PC from the collection.
I debugged the script with my vbscript editor and noticed that the RemoveCollectionMembership subroutine never runs.
Also, objComputer, in the line “For Each objComputer In arrComputers”, is always Empty.
Any ideas what could be wrong?
It works when i run it manually but does not seam to work as a filter.
Couple of questions
1) Do i have to have this filter set up on every Site Server or just the Central?
2) Could this script be added as a package in the OSD task sequence instead of the filter rule?
I also have the issue if not having the “Task Sequence Manager” as a component.
thanks
@Rod.
1) I have mine set up only on my Primary (Central).
2) I think it can, as this script has evolved from the original which was executed from a TS.
You have to type it into the Component field. It is not a server component and therefore not listed in the drop down box.
The original code from the TechNET forum:
http://social.technet.microsoft.com/Forums/en-US/configmgrsdk/thread/9205e49b-9d0e-462e-8998-87e6c31f9c41/
Hi all,
Hi configure everything with the last update of the script but it doesn’t work when it run at a status filter
When i run manually and specify computer name et remove it from collection, does i need to change some rigth to specify wich user run this filter rules ?
I don’t understand why it doesn’t work in filter rules
please help me
I had an issue with it not removing the membership rule due to it looking of the obsolete value. In my case the value was a NULL on the resource record in the DB and not 0. I think it was more of a timing issue with the resource record not being updated before the script ran. I edited line 50 of the script to eliminate the obsolete check.
This:
Set arrComputers = SWbemServices.ExecQuery(“select * from SMS_R_System where Name='” & strComputerName & “‘ and Obsolete = 0”)
Changed to:
Set arrComputers = SWbemServices.ExecQuery(“select * from SMS_R_System where Name='” & strComputerName & “‘”)
Thks Jim, sorry for the delay of my respons, i have been on vacation 🙂
I will test it right now and give you a feedback
so this script removes the pc from the Collection.
But why not move the pc from AD OU to another OU (lets say an “OSD Task OU” and the normal OU for workstations). The collection will update it self (in 5min with R3) and you dont need a script like this.
@Patrick, this script is to remove the machine from SCCM collection not from AD OU. give your service account permission to right OU to move them to different OU
Was working great for a couple months and just randomly stopped working. Hmmm.
Hi Guys,
This was working with SCCM 2007 but not with 2012, has anyone else have success with 2012?
Thanks
Hi,
It works just fine with ConfigMgr2012 no problem, I have had to specify the full path to cscript.exe, you could try that. I posted an updated version as well here that can clear the PXE flag aswell.. https://ccmexec.com/2012/07/remove-from-collection-and-clear-pxe-flag-vbscript-using-status-filter-rule/
/Jörgen
Hi,
must I add this status filter to every primary site or can I just do it on the CAS?
Thank you Jim Bezdan, that fix (removing the obsolete check) worked for both of my environments (sccm 2007 & 2012).
For now it seems to work in our environment. I also checked the box to Report to the event log. But there’s a thing; my devices are being removed from the specified collection but when I log onto a client, I don’t see the action of remove.vbs in the event log (Windows Logs > Application). So I don’t know if my devices are remove from the collection by the Status Filter Rule or there is another reason that they are remove from the collection. Can you show me in which (event)log I should see the message?
this vbscript not working for me
Let me tell me my scenario first.I am using sccm 2007 R3
I have hundreds of machine records with SCCM client agent as “NO Status” (AD discover Object)
My manger told me dont show up that machine in SCCM only client =yes machine should me there in SCCM.
So I have created a collection to pull all inactive AD discovered object and decided to delete those machine from sccm databe using your script
I have kept the script in F drive in sccmtool folder and changed the collection ID like below
sEventlog = “1”
sCollectionIDs = “WGP0031F”
The I called the script in command prompt with the command
“cscript.exe e:\sccmtools\remove.vbs %msgsys”
But cscript is just running and nothing is happening
Event viwer shows “%msgsys will be removed from the following collection ID’s WGP0031F”
Please help me.it is very urgent for me
Your commenthis vbscript not working for me
Let me tell me my scenario first.I am using sccm 2007 R3
I have hundreds of machine records with SCCM client agent as “NO Status” (AD discover Object)
My manger told me dont show up that machine in SCCM only client =yes machine should me there in SCCM.
So I have created a collection to pull all inactive AD discovered object and decided to delete those machine from sccm databe using your script
I have kept the script in F drive in sccmtool folder and changed the collection ID like below
sEventlog = “1”
sCollectionIDs = “WGP0031F”
The I called the script in command prompt with the command
“cscript.exe e:\sccmtools\remove.vbs %msgsys”
But cscript is just running and nothing is happening
Event viwer shows “%msgsys will be removed from the following collection ID’s WGP0031F”
Please help me.it is very urgent for me
Hoping someone still looks at this post. I’m running 2007 R2 and I can get the script to work fine by its self with the computer name in place of the %msgsys. I have it setup exactly as shown above but there are no event logs and it isn’t removing the machines. Is there something that needs to be done for it to capture the %msgsys? Any suggestions would be helpful. Maybe I don’t have the correctly logging turned on or something.
Jörgen, I’m trying to get this to work on a SCCM 2012 R2 SP1. the computer does not get removed from any collection but it is logged on the application log. Do you need to add permission for the SCCM primary server to be able to run the script because it is being run under system context?
Hi,
If you run the script on the SCCM server itself it should have permissions through the System permissions.
/Jörgen
I did try this receipy and experienced all the same trouble as other devoted admins like you had. Untill I modify the path for cscript. I used this command to succesfully run the script: “C:\Windows\System32\cscript.exe” D:\Scripts\Remove.vbs %msgsys
The important part is to put the quotes for “C:\Windows\System32\cscript.exe”
YEP! The System run the command, but has no idea where to find csript.
Deuh!
Use this instead: “C:\Windows\System32\cscript.exe” D:\Scripts\Remove.vbs %msgsys
I have tried all of the above proposed solutions and the script appeared to be working, but never realy work, because it was missing the “C:\Windows\System32\cscript.exe” .
Yep! Juste a ” ” make a big difference!
Happy SCCM!
Hi there,
When I select component in the “Create a new Status Filter Rule” Wizard, I cannot select the “Task Manager Manager”. I am able to select CONFIGURATION_MANAGER_UPDATE, SMS_AD_FOREST_DISCOVERY_MANAGER and so forth. Did they change this? Which one should I select?
Kind regards,
Hasan
does this script remove computers from collection? because i need remove servers but when i try aske me a confirmation if the deletion will apply the database deletion
i don want delete de computer from database i just want remove the computers from collection
how to achieve this?
thanks in advance
Hi,
Yes it removes it as a member of one or more collections. In the console you should not delete a client from a collection but select properties on the collection, if the client is a direct member the you can remove the membership if it is query based you need to change the query. A collection is like a Group
Direct Membership = Static group membership
Query based = Dynamic Groups (to compare to AzureAD)
I hope that helps
Regards,
Jörgen