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

Remove from collection and clear PXE flag vbscript using Status Filter Rule

Posted on July 13, 2012 by Jörgen Nilsson

I wrote a post a long while ago which started as question in on Technet Forum on how to remove a computer from a collection using a status filter rule once the OS deployment Task sequence is successful, I posted the script here: https://ccmexec.com/2010/03/remove-a-computer-from-a-collections-when-osd-task-sequence-is-completed/.
I still use it in almost all of my implementations of Configuration Manager. In one customer scenario I had to clear the PXE flag as well so I added that to the script so now you can select if you want the script to clear the PXE flag as well on the client when it is removed from the OS deployment collection.

The script works fine both in Configuration Manager 2007 and Configuration Manager 2012.

Why using a Status Filter Rule instead of a script in the TS run from the client side? Well you don’t have to open any firewall ports in the server for WMI e.t.c. You could also implement Webservices which do the same task for you, i like the simpleness in the status filter rule though.

The script can be downloaded here: Vbscript remove from Collection

To implement it:

1. Download the script and save it as “remove.vbs” in for instance E:\sccmtools or another folder on the Primary Site server.

2. Edit the following line with the collection/collections you want the computer removed from

sCollectionIDs = “00100053:0010004A:00100069″

You can now also configure if you want the script to clear the pxeflag by changing this value.

ClearLastPxe = “1”

You can also have the script to write to the eventlog on the Primary Site Server which Computername will be removed from which collections if you need to troubleshoot.

sEventlog = “1”

When that is done, save the file

3. Create a status filer rule, this screenshots are from Configuration Manager 2012 not that much differs.

4. Create a new status filter rule under Site Configuration\Sites choosing Status Filter rules.

5. Select Create

Remove_2012_05

6. Configure it to use the following settings:

Name: Remove From Collection

Component : Task Sequence Manager

Message Id: 11171

Note: You have to type in “Task Sequence Manager” it is not available in the drop-down list as it is not a server component.

Remove_2012_1

7.  Run a Program: C:\windows\System32\cscript.exe e:\sccmtools\remove.vbs %msgsys

Remove_2012_2

8. The next screen confirms that you are finished.

Remove_2012_3

Now you have successfully implemented the Status Filter rule and can start testing.

  • Configuration Manager
  • Status Filter rule
  • Vbscript
  • 29 thoughts on “Remove from collection and clear PXE flag vbscript using Status Filter Rule”

    1. Philip says:
      September 11, 2012 at 5:52 am

      Excellent site! I must be one of the few who can get this to run successfully. It seems quite straight forward. I modified the script to designate two collections. I created the filter on SCCM 2007 SP2 R3, and I pointed the remove.vbs to temporary folder on the C: drive. I must be missing something for it to run. I have tested the script on Windows XP deployment and USMT Migration from XP to Win7 with no success.

      It should not matter if the collection is a sub-collection of another? I am specifying the collection id in where the computer is a direct member. Well back to testing

      Reply
    2. Robin Harris says:
      September 28, 2012 at 5:52 pm

      Good job on the script. Exactly what I was looking for.

      Reply
    3. Tim Hinchey says:
      December 13, 2012 at 4:17 pm

      Hi,
      I cannot seem to get the vbs script to remove the machine from the collection manually.
      vbs location – C:\StatusFilters\remove.vbs
      Collections – sCollectionIDs = “C0100020:C010001F”

      CMD line – cscript.exe \\servername\c$\StatusFilters\remove.vbs %msgsys

      The script looks like it is running successfully in CMD but the machine remains in both Collections. The user I am logged on to server with has full SCCM admin rights.
      Regards,
      Tim

      Reply
      1. Jörgen Nilsson says:
        December 13, 2012 at 9:16 pm

        Hi,
        Do you run it manually using the “cscript.exe \\servername\c$\StatusFilters\remove.vbs %msgsys”? in order to test it that way you need to replace %msgsys with the computername to remove.

        /Jörgen

        Reply
    4. Tim Hinchey says:
      December 14, 2012 at 11:02 am

      I got it working, was a group policy setting blocking communications between my machines and SCCM server!
      Thank you for the response though.

      Regards,
      Tim

      Reply
    5. Jeff Du-Shane says:
      December 18, 2012 at 1:01 am

      Hi Jörgen

      Great solution, however I am seeing an interesting situation under CM2012. If more than one TS completes within the script sleep time (5 mins), it seems that only the first completion status is actioned. No adittional TS completion status messages (11171) can run the script until the first completes. So if five machines complete their build within a 5 minute window, only the first will be successfully removed from the identified collections.

      Cheers

      Jeff

      Reply
    6. Willy Kroll says:
      January 17, 2013 at 2:57 pm

      I think I’m running into the same issue that Tim Hinchey did. I can run the script manually and the PC is removed from the collection. I double checked my Status Filter Rule many times and I know I have it setup correctly, but it’s not kicking off the script. Tim, what GPO settings were blocking communication between your machines and the SCCM server? Think I’m having the same issue.

      Reply
    7. Mathew says:
      March 19, 2013 at 1:50 pm

      Hi Jörgen
      I have also the same issue like Jeff Du-Shane. Is there a solution?

      Reply
    8. Leo says:
      April 11, 2013 at 12:35 pm

      Great solution but I experience one little problem:

      The desktop is removed from the collection ….. but after the client rebooted and picked up the policy again. This is causing the client to install for a second time.

      Anyone else with this problem (and hopefully a solution)?

      Reply
    9. Mathew says:
      April 19, 2013 at 1:16 pm

      Hi Jörgen
      I have also the same issue like Jeff Du-Shane. Is there a solution?

      Reply
    10. Pingback: SCCM 2012 SP1 – Remove Client from Collection after OSD | SCCMfaq.ch
    11. Pingback: Remove computer from collection after OSD – Powershell - CCMEXEC.COM – System Center blog
    12. Steve Whitcher says:
      June 28, 2013 at 7:35 pm

      Thanks for sharing the great script! One question — Is it possible to set this script to only trigger after specific task sequences? I guess even if it runs after every TS, it will only affect the designated collections, but I’d prefer for the script not to even trigger unless it was a certain TS that completed.

      Reply
    13. Dan says:
      August 5, 2013 at 5:15 am

      I really like this idea, but as with Steve I would prefer it to only run after a specific task sequence.
      I’ve tried similar scripts that run from the task sequence itself but with little success.

      Reply
    14. Dan says:
      August 9, 2013 at 1:58 am

      You can use the filter rules to filter package or advertisement id. You just need to choose the Source first (being the Mgr server).

      Reply
    15. Johan says:
      September 18, 2013 at 2:17 pm

      Hello and thank you for the script!

      I can not get it to work on my CM 07 or on my CM 2012.

      I have copyed the script to the server and everything seems to be working when i run the script form the command prompt.

      How can i se what is not working? is there any loggin function i can use?

      thx again

      Reply
    16. kl says:
      October 30, 2013 at 11:42 pm

      hi, please confirm if the value 0 or 1 to clear the pxe flag. thanks.

      Reply
      1. Jörgen Nilsson says:
        October 31, 2013 at 11:54 am

        Hi,
        The value should be 1
        /Jörgen

        Reply
    17. Mike Franuziak says:
      November 7, 2013 at 7:45 pm

      I am having the very same issue as the first person who posted here. Will this script work with a direct membership in a sub-collection? I cannot get the script to work locally on the server, So I imagine its something to do with this?

      Reply
    18. Samy says:
      July 15, 2014 at 12:05 am

      Hello,

      I’m using SCCM 2012 R2 to perform the deployment of Windows (OSD to unknown computers).

      Everything is configured and working correctly.

      Important: I use SCCM to just make the deployment of Windows (I do not I manage servers via SCCM).

      The problem I have is: If a user attempts to rerun the OSD (Reinstalling Windows), I need to manually enter the SCCM and delete the computer in the collections (For the unknown computer became known after the task sequence) .

      Do you have any suggestions?

      I do not necessarily need the agent in SCCM servers (though it is necessary for the procedure OSD). So I get a service running unnecessarily.
      Furthermore, this problem have to remove the computers, so that a procedure can be re OSD executed.

      Reply
    19. Pingback: Creating a simple “OS Reset Tool” for support personellDeploymentstuff.com | Deploymentstuff.com
    20. Joe says:
      October 10, 2014 at 8:44 pm

      Good Afternoon,

      We have multiple collections that deploy our task sequence but when I run this script if I put in more than one collection it will only run on the first collection listed in the script, not sure what is up with that.

      Thank You

      Reply
    21. Pingback: Creating a simple “OS Reset Tool” for support personell | fborch.com
    22. Pingback: SCCM 2012 SP1 – Remove Client from Collection after OSD | blog.hosebei.ch
    23. Hamnawa says:
      January 1, 2016 at 12:56 pm

      I am trying this to work with SCCM 1511 on Server 2012 R2 but it is not working.
      I have a command as C:\windows\System32\cscript.exe \\Share\Scripts\remove.vbs %msgsys but it is not working.

      When I run it manually C:\windows\System32\cscript.exe Share\Scripts\remove.vbs ComputerName it works.

      Monitoring Reports: 11171 Success The task seqence manager successfully completed execution of the task sequence.

      I have followed the instructions exactly as described here.

      Reply
    24. Rscode says:
      March 30, 2017 at 2:03 pm

      This script does not work all the time on our SCCM 1606 infra. The ID 11171 always appears, but on some clients the ID 30016 modify collection message appears and some not.

      We cannot pinpoint the cause of the different behavior. Are there others with this issue?

      Reply
    25. G man says:
      January 11, 2018 at 10:50 am

      I belive this is causing a delay in ou status message queues. We are currently in a large migration 200K devices. When this is running we are seeing delays of between 10 – 50 seconds in the statsmgr.log file. This is causing a large backlog of messages in out statmgr.box\statmsgs folder.
      has anyone else seen this issue before

      Reply
    26. Richard says:
      October 25, 2018 at 5:58 pm

      Hi,

      I can run this script manually from my site server and it works but it doesn’t work as a filter I run it from the server it self so just use C:\windows\System32\cscript.exe c:\scripts\ColRem.vbs %msgsys I’ve changed the script name to ColRem.vbs.

      Reply
      1. Richard says:
        October 31, 2018 at 4:45 pm

        Found out it was only not working for newly imported devices and i’ve fixed it by changing the below line by adding or Obsolete is null.
        Set arrComputers = SWbemServices.ExecQuery(“select * from SMS_R_System where Name='” & strComputerName & “‘ and (Obsolete = 0 or Obsolete is null)”)

        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

    • Logging the Co-management and Defender onboarding process during OSD
    • Show DP information during OSD using TSBackground
    • Using Install-language during AutoPilot Windows 11 insider
    • Co-Management and the importance of device token enrollment.
    • Windows 11 Insider Start Menu layout registry customizations

    ©2022 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