How To Add Device To Collection Using Task Sequence- Troubleshooting

Close Menu Facebook X (Twitter) Instagram Thursday, February 19 X (Twitter) LinkedIn Reddit RSS All about Endpoint Management All about Endpoint Management Home»configmgr»How to Add device to collection using task sequence- troubleshooting How to Add device to collection using task sequence- troubleshootingEswar KonetiBy Eswar KonetiJanuary 13, 9:34 am2 Mins Read configmgr 7,106 Views Share Facebook Twitter LinkedIn Reddit

I was recently looking for a solution to add a device to SCCM Collection using the Task sequence. During the search, I have found Trevor has a blog post on this.

So before I use the code in the task sequence, I plan to test it on a client device.

The full code is given below. You will have to change the parameters where needed.

cmd /c powershell.exe -Command "&{$Me = $Env:COMPUTERNAME; Invoke-command -Computername "SCCMSERVERFQDN" -ArgumentList $Me -scriptblock {param($Me)Import-Module ConfigurationManager; cd SITECODE:; $Computer = Get-CMDevice -Name $Me; if ($Computer){Add-CMDeviceCollectionDirectMembershipRule -CollectionID 'COLLECTIONID' -ResourceId $computer.resourceid}}}"

Query to add device to collection

Login to client computer that doesn't have any configuration manager module installed, open the cmd (run as an account that has RBAC permissions to collect to SCCM server)

Running the query, returned an error code.

The specified module 'ConfigurationManager' was not loaded because no valid module file was found in any module directory.

Cannot find drive. A drive with the name 'CB1' does not exist.

Since I am running the code on a client device, i would like to see if this works on SCCM server (local) , I experienced the same error code. Even though the server has configuration manager module loaded but for some reason, it is not picking up or identifying correctly.

During the troubleshooting, I have found that, the configuration manager module path is missing in the system variable.

The fix is given below.

On your SCCM server, go to system properties or you can run sysdm.cpl from run command.

Open system properties

Click on advance, Environment Variables

Copy the variable value for variable name SMS_ADMIN_UI_PATH.

Now, select PSModulePath and click on edit

Click on new and copy the variable value that you have copied earlier (remove i386).

G:\Program Files\Microsoft Configuration Manager\AdminConsole\bin

Click on Ok, Ok, Ok

Changes are now saved.

lets go back to the client PC and run the query again.

This time it executed successfully. I can now use this query in my task sequence to add the device to specific collection.

Hope you find this article useful!

add device to colleciton configmgr Query SCCM sccm collection Task Sequence Share. Twitter LinkedIn Email Facebook Reddit

Related Posts

Export the List of Products from the Software Update Point (SUP) in SCCM Using SQL Query

November 08, 10:39 am

SCCM SQL Report – Compare Installed Apps on TWO Different Computers

July 13, 10:35 am

Optimize Your Intune Workflow with a Powerful Browser Extension

March 22, 10:39 am

Leave a ReplyCancel reply

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

Sign Up

Get email notifications for new posts.

Email Address

Subscribe

Author

I’m Eswar Koneti ,a tech enthusiast, security advocate, and your guide to Microsoft Intune and Modern Device Management. My goal? To turn complex tech into actionable insights for a streamlined management experience. Let’s navigate this journey together!

Support

Awards

Archives
Archives Select Month November 2025 (1) August 2025 (1) July 2025 (2) June 2025 (1) March 2025 (2) February 2025 (1) January 2025 (1) November 2024 (2) October 2024 (4) September 2024 (1) August 2024 (4) July 2024 (2) May 2024 (1) April 2024 (1) February 2024 (1) January 2024 (4) December 2023 (2) November 2023 (1) October 2023 (5) September 2023 (2) July 2023 (3) May 2023 (1) April 2023 (1) January 2023 (3) December 2022 (1) November 2022 (3) October 2022 (3) August 2022 (1) July 2022 (3) May 2022 (3) April 2022 (1) March 2022 (2) February 2022 (2) January 2022 (4) December 2021 (2) September 2021 (3) August 2021 (4) July 2021 (2) May 2021 (4) March 2021 (2) February 2021 (2) January 2021 (5) December 2020 (5) November 2020 (7) October 2020 (4) September 2020 (5) August 2020 (2) July 2020 (6) June 2020 (4) May 2020 (11) April 2020 (5) March 2020 (2) February 2020 (3) January 2020 (5) December 2019 (5) November 2019 (7) October 2019 (6) September 2019 (4) August 2019 (1) July 2019 (6) June 2019 (2) May 2019 (6) April 2019 (7) March 2019 (4) February 2019 (1) January 2019 (6) November 2018 (3) October 2018 (3) September 2018 (2) August 2018 (5) July 2018 (4) June 2018 (5) April 2018 (2) March 2018 (10) February 2018 (4) January 2018 (6) December 2017 (3) November 2017 (3) October 2017 (5) September 2017 (10) August 2017 (4) July 2017 (5) June 2017 (1) May 2017 (1) April 2017 (3) March 2017 (4) February 2017 (4) January 2017 (4) December 2016 (1) November 2016 (7) October 2016 (9) September 2016 (6) August 2016 (2) July 2016 (3) June 2016 (1) May 2016 (2) April 2016 (6) March 2016 (4) February 2016 (6) December 2015 (4) November 2015 (9) October 2015 (5) September 2015 (7) July 2015 (4) June 2015 (1) May 2015 (8) April 2015 (2) March 2015 (2) January 2015 (5) December 2014 (3) November 2014 (3) October 2014 (3) September 2014 (3) August 2014 (2) July 2014 (4) June 2014 (7) May 2014 (2) April 2014 (3) March 2014 (10) February 2014 (4) January 2014 (3) December 2013 (6) November 2013 (5) October 2013 (3) September 2013 (13) August 2013 (4) July 2013 (4) June 2013 (2) May 2013 (2) April 2013 (5) March 2013 (1) February 2013 (1) January 2013 (23) December 2012 (17) November 2012 (12) October 2012 (17) September 2012 (26) August 2012 (15) July 2012 (6) June 2012 (14) May 2012 (15) April 2012 (14) March 2012 (6) February 2012 (7) January 2012 (27) December 2011 (4) November 2011 (5) October 2011 (4) September 2011 (2) August 2011 (1) May 2011 (4) April 2011 (2) March 2011 (5) February 2011 (4) January 2011 (2) December 2010 (9) November 2010 (10) October 2010 (1) September 2010 (3) August 2010 (2) July 2010 (4) June 2010 (4) May 2010 (7) April 2010 (2) March 2010 (9) February 2010 (6) January 2010 (15) December 2009 (4) November 2009 (4) October 2009 (1) September 2009 (4) August 2009 (2) July 2009 (10) June 2009 (3) May 2009 (2) March 2009 (1) Submit

Type above and press Enter to search. Press Esc to cancel.

Loading Comments... Write a Comment... Email (Required) Name (Required) Website

Tag » Add Computer To Collection Sccm Powershell Script