Menu
CCMEXEC.COM – Enterprise Mobility
  • Home
  • General
  • Configuration Manager
  • Windows 10
  • Intune
  • GitHub
  • Windows 11
  • About the author
CCMEXEC.COM – Enterprise Mobility

Updated: Remove a computer from a Collection when OSD Task Sequence is completed

Posted on March 6, 2010December 12, 2010 by admin

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:

  1. Under site settings create a new status filter rule
  2. Configure it to use the following settings:

Component : Task Sequence Manager
Message Id: 11171

Run a Program: cscript.exe e:\sccmtools\remove.vbs %msgsys

Status1 status filter rule 2

  • Configuration Manager
  • 43 thoughts on “Updated: Remove a computer from a Collection when OSD Task Sequence is completed”

    1. Eric says:
      July 29, 2010 at 4:27 pm

      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

      Reply
    2. Jon says:
      January 13, 2011 at 8:27 am

      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

      Reply
    3. Umesh says:
      January 27, 2011 at 11:45 am

      I have used your tool…its really very helpful.

      Reply
    4. Tim says:
      February 18, 2011 at 5:03 am

      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.

      Reply
    5. Jared says:
      March 22, 2011 at 2:54 pm

      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.

      Reply
    6. Neil says:
      April 22, 2011 at 1:12 am

      Thanks for sharing the script. I installed it and changed the collection ID, it appears not removal. Any possibile reason? Thanks!

      Reply
    7. Jörgen Nilsson says:
      April 26, 2011 at 8:15 am

      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

      Reply
    8. Jörgen Nilsson says:
      April 26, 2011 at 8:21 am

      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.

      Reply
    9. Mikhail says:
      September 13, 2011 at 2:12 pm

      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?

      Reply
    10. Mikhail says:
      September 14, 2011 at 5:01 pm

      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.

      Reply
    11. Eerik says:
      September 16, 2011 at 2:10 pm

      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?

      Reply
    12. Mikhail says:
      September 19, 2011 at 11:04 am

      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.

      Reply
    13. Bab says:
      September 28, 2011 at 9:36 am

      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

      Reply
      1. Jörgen Nilsson says:
        September 28, 2011 at 9:56 am

        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

        Reply
    14. Bab says:
      September 28, 2011 at 10:52 am

      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

      Reply
    15. Thanos says:
      October 13, 2011 at 7:52 pm

      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?

      Reply
    16. Jörgen Nilsson says:
      October 13, 2011 at 7:55 pm

      Hi,
      Thanos, it should only remove it from the collection you specify in the script, nothing else.
      Regards,
      /Jörgen

      Reply
    17. Keiller says:
      November 19, 2011 at 9:55 pm

      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?

      Reply
    18. Sparky says:
      January 27, 2012 at 10:32 pm

      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?

      Reply
    19. Rod says:
      February 3, 2012 at 7:30 pm

      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

      Reply
    20. Jez says:
      February 14, 2012 at 1:27 am

      @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.

      Reply
    21. Jez says:
      February 14, 2012 at 1:29 am

      The original code from the TechNET forum:

      http://social.technet.microsoft.com/Forums/en-US/configmgrsdk/thread/9205e49b-9d0e-462e-8998-87e6c31f9c41/

      Reply
    22. JP says:
      February 21, 2012 at 6:51 pm

      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

      Reply
    23. Jim Bezdan says:
      February 27, 2012 at 5:58 pm

      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 & “‘”)

      Reply
    24. JP says:
      March 3, 2012 at 10:45 pm

      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

      Reply
    25. Patrick says:
      March 28, 2012 at 12:52 pm

      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.

      Reply
    26. Kalam says:
      June 19, 2012 at 6:40 am

      @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

      Reply
    27. Mike says:
      August 22, 2012 at 9:35 pm

      Was working great for a couple months and just randomly stopped working. Hmmm.

      Reply
    28. John says:
      September 26, 2012 at 12:08 am

      Hi Guys,

      This was working with SCCM 2007 but not with 2012, has anyone else have success with 2012?

      Thanks

      Reply
      1. Jörgen Nilsson says:
        September 26, 2012 at 6:54 am

        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

        Reply
    29. Jaco says:
      June 18, 2013 at 10:58 am

      Hi,

      must I add this status filter to every primary site or can I just do it on the CAS?

      Reply
    30. AJ says:
      June 27, 2013 at 4:34 pm

      Thank you Jim Bezdan, that fix (removing the obsolete check) worked for both of my environments (sccm 2007 & 2012).

      Reply
    31. Robert says:
      May 14, 2014 at 11:24 am

      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?

      Reply
    32. shinu says:
      February 12, 2015 at 1:23 pm

      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

      Reply
    33. shinu says:
      February 12, 2015 at 1:24 pm

      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

      Reply
    34. Michael says:
      May 2, 2015 at 1:38 am

      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.

      Reply
    35. baatch says:
      March 16, 2016 at 10:41 am

      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?

      Reply
      1. Jörgen Nilsson says:
        March 21, 2016 at 2:25 pm

        Hi,
        If you run the script on the SCCM server itself it should have permissions through the System permissions.
        /Jörgen

        Reply
    36. Pierre Boily says:
      December 12, 2018 at 8:44 pm

      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!

      Reply
    37. Pierre Boily says:
      December 12, 2018 at 10:13 pm

      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!

      Reply
    38. Hasan Ördek says:
      October 2, 2019 at 11:04 am

      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

      Reply
    39. FRANCO says:
      May 25, 2020 at 5:21 pm

      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

      Reply
      1. Jörgen Nilsson says:
        May 26, 2020 at 10:43 pm

        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

        Reply

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    My name is Jörgen Nilsson and I work as a Senior Consultant at Onevinn in Malmö, Sweden. This is my blog where I will share tips and stuff for my own and everyone elses use on Enterprise Mobility and Windows related topics.
    All code is provided "AS-IS" with no warranties.

    Tweets by ccmexec

    Recent Posts

    • Configuring MS Edge Security Baseline v107 using Settings Catalog
    • Configuring Desktop App Installer using CSP and script?!
    • Customizing Taskbar and Start in Windows 11 22h2 with PowerShell
    • MMUGSE – physical event 2022-10-19 @Microsoft Reactor Stockholm.
    • Switch to Private Firewall profile on AAD joined when connected to specific network.

    ©2023 CCMEXEC.COM – Enterprise Mobility | WordPress Theme by Superb Themes
    This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.Accept Reject Read More
    Privacy & Cookies Policy

    Privacy Overview

    This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
    Necessary
    Always Enabled
    Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
    Non-necessary
    Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
    SAVE & ACCEPT