Close Menu
    Facebook X (Twitter) Instagram
    Sunday, October 12
    X (Twitter) LinkedIn Reddit RSS
    All about Endpoint Management
    • Home
    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- troubleshooting

    Eswar KonetiBy Eswar KonetiJanuary 13, 9:34 am2 Mins Read configmgr 6,952 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

    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

    Migrate Microsoft 365 Updates from SCCM/MECM to Intune for Co-Managed Devices

    February 11, 9:50 pm

    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.

    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

    © Copyright 2009-2025 Eswar Koneti, All rights reserved.

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

     

    Loading Comments...