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

Remove from Collection using Maik Kosters Webservice

Posted on June 18, 2015 by Jörgen Nilsson

There are many examples out there on how to remove a computer from a collection after OS Deployment is finished. I have used different scripts in different scenarios but at a customer lately we had a requirement to open as few ports as possible in the firewall. If you run a script from the Task Sequence on the client side that remove the device from a collection you will need to for example open RPC High Ports which could be avoided.

That is why I wrote this little Powershell script that will remove the computer from a collection and clear the PXE flag as well using Maik Koster’s excellent webservice instead and a Powershell script to use it. Maik Koster’s webservice can be downloaded here http://mdtcustomizations.codeplex.com/releases , don’t forget to secure it using request filtering in IIS.

The Powershell script

The following script is used to call the webservice, in this example we use Maik Koster’s webservice and call it using UUID as the identifier on the command line. The following lines need to be configured in the script below.
[string]$UsrName = “Contoso\wbssvc”

[string]$UsrPW = “Pa@ssw0rd”

[string]$SiteCode = “123”
[string]$URI = “http://sccm02/webservice/sccm.asmx?WSDL”

Copy the script and place it in a folder that can be used as a package source for a package so we can call the script from a package in the Task Seqeunce.

The script:

Param(

[string]$computerName,

[string]$UUID,

[String]$CollectionID

)

[string]$UsrName = "Contoso\wbssvc"

[string]$UsrPW = "Pa@ssw0rd"

[string]$SiteCode = "123"

[string]$Macaddress = ""

[string]$URI = "http://sccm02/webservice/sccm.asmx?WSDL"

$secpasswd = ConvertTo-SecureString "$UsrPW" -AsPlainText -Force

$mycreds = New-Object System.Management.Automation.PSCredential ("$UsrName", $secpasswd)

$zip = New-WebServiceProxy -uri $URI -Credential $mycreds

# Invoke Web Service

$method = "ClearLastPXEAdvertisementForComputer"

$zip."$method".Invoke("$Macaddress","$UUID","$SiteCode")

try

{

$method = "RemoveComputerFromCollection"

$zip."$method".Invoke("$Macaddress","$UUID","$CollectionID","$ComputerName")

}

catch

{

Write-Output "$_.Exception.Message"

exit 1

}

exit 0

The Task Sequence step

Before we create a package we need to edit the information in the script above. Then create a package from which we can call the script.

I prefer to use a run command line step to run the powerhsell script and call the webservice. Use the package we created before to run the command from.

The following command line can be used, where the last part is the collection the device should be removed from, you need to change that to reflect your environment: “Powershell.exe -NoProfile -ExecutionPolicy ByPass -File RemoveFromOSDCollection1.ps1 %OSDcomputername% %UUID% 06000062”

RemoveCollection1

That should do it, deploy the task sequence and test it out.

Note:

  • The script will return an error if the computer cannot be removed from the Collection, you can solve it with continue on error.
  • If you import a computer with MAC address you need to change the script to use MAC address instead of UUID to remove it

7 thoughts on “Remove from Collection using Maik Kosters Webservice”

  1. Adrian W says:
    July 1, 2015 at 3:38 pm

    Works great!!! Flawlessly!! Thanks for the note about the MAC address!! We import machines by mac address so that helped.

    Reply
    1. Jörgen Nilsson says:
      July 2, 2015 at 9:38 pm

      Glad to hear it worked, I am planning on posting more scenarios where using a webservice is a great option!
      /Jörgen

      Reply
  2. Adrian W says:
    July 1, 2015 at 3:44 pm

    Is there a way to setup more than one CollectionID? We deploy our OS to about 15 different collections.

    Reply
    1. Jörgen Nilsson says:
      July 2, 2015 at 9:37 pm

      Hi,
      I will post an example this weekend.
      /Jörgen

      Reply
  3. Adrian W says:
    July 10, 2015 at 3:01 pm

    Cool! I just subscribed to the feed to alert me. Thanks!

    Reply
  4. adriano says:
    June 19, 2016 at 8:25 pm

    Thank you for sharing! Works fine!

    Reply
  5. Stefan Schuh says:
    June 26, 2017 at 3:47 pm

    Is there a way to not define $UsrPW in the script. I’ve tried with Run commandline and “Run this step as following account” but without success.

    The TaskSequence works withoud OSD but in an OSD TaskSequence the WebService fails.

    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.

Recent Posts

  • MMUGSE – Meetup October 24 2026
  • Windows 365 Link – a week and some
  • Prevent software installations disguised as drivers
  • Tip when troubleshooting unexpected reboots during Autopilot – event ID 2800
  • New settings in Intune Security Baseline Windows 11 24H2 -2504
©2025 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