Unable to run the command Remove-CMDevice

dylanand2-7592 420 Reputation points
2025-02-11T15:14:35.9+00:00

I'm trying to use the Powershell command to remove some old devices in SCCM.

Remove-CMDevice -DeviceName "WIN11-086"

But failed with the error: This command cannot be run from the current drive. To run this command you must first connect to a Configuration Manager drive.

At line:1 char:1

  • Remove-CMDevice -DeviceName "WIN11-086"

Am I missing anything? Can you help guide me in the right direction?

PowerShell (1)

Microsoft Configuration Manager Deployment
Microsoft Configuration Manager Deployment
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Deployment: The process of delivering, assembling, and maintaining a particular version of a software system at a site.
1,038 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jan Vinterberg 155 Reputation points
    2025-02-11T20:23:17.6366667+00:00

    Hi dylanand2-7592

    You need to connect to the CM drive first, then you should be able to delete the device object.

    1. Open Configuration Manager PowerShell If you haven’t already, open PowerShell as Administrator
         Import-Module ($env:SMS_ADMIN_UI_PATH + '\..\ConfigurationManager.psd1')
      
    2. Connect to the CM Site Identify your site code (e.g., XYZ), then change the drive to the Configuration
         cd XYZ:
      
      (Replace XYZ with your actual site code, e.g., CDM)
    3. Run the Remove-CMDevice Command Now, execute the command:
         Remove-CMDevice -DeviceName "WIN11-086"
      

    I sincerely hope that this will solve your challenge :)
    Best regards

    Jan

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Simon Ren-MSFT 38,901 Reputation points Microsoft Vendor
    2025-02-12T02:22:36.78+00:00

    Hi dylanand2-7592,

    I hope you are doing well. Agree with Jan Vinterberg.

    We need to start PowerShell prompt from the SCCM console and import the Configuration Manager PowerShell module firstly.

    Please see the official article Get started with Configuration Manager cmdlets

    https://learn.microsoft.com/en-us/powershell/sccm/overview?view=sccm-ps

    Similar thread for your reference:

    The term 'Remove-CMContentDistribution' is not recognized as the name of a cmdlet, function, script file, or operable program

    Hope my answer could help you. Should you have any questions or concerns, please do feel free to contact me.

    Best regards,

    Simon


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.