Need Help deleting all local user account through powershell


I am trying to delete all local user accounts on machine through Get-wmiobject but getting error as below.

First: I retrieve all users with account type code -- 512 means local account and stored in avariable.

Second: After this I put say $a | remove-wmiobject.

Error:  This provider is not capable of doing this operation.

  • That is because this cmdlet is not for user objects. You can see this by looking at the properties an parameters available from the cmdlet.

    Remember, PoSH is looking for by property or by value when it takes a action on X or Y.

        # Get parameters, examples, full and Online help for a cmdlet or function

        # Get a list of all functions
        Get-Command -CommandType Function

        # Get a list of all commandlets
        Get-Command -CommandType Cmdlet

        # Get a list of all functions for the specified name
        Get-Command -Name '*-WmiObject*' -CommandType Function

        # Get a list of all commandlets for the specified name
        Get-Command -Name '*-WmiObject**'  -CommandType Cmdlet

        # get function / cmdlet details
        (Get-Command -Name Remove-WmiObject).Parameters

        Get-help -Name Remove-WmiObject -Examples
        Get-help -Name Remove-WmiObject -Full
        Get-help -Name Remove-WmiObject -Online

        Get-Help about_*
        Get-Help about_Functions

        # Find all cmdlets / functions with a target parameter
        Get-Help * -Parameter Identity

        Get-Command -CommandType cmdlet `
        | Where-Object { $_.parameters.keys -match 'credential'} `
        | Format-Wide name -AutoSize

        # All Help topics locations
        explorer "$pshome\$($Host.CurrentCulture.Name)"

    What version of PoSH are you on. The latest version of PoSH have specific set of cmdlets for local user management.

    This section contains the help topics for the Local Accounts cmdlets in Windows PowerShell.

    Otherwise, you have to use the ADSI / WinNT provider and do this manually,

    ADSI WinNT Provider
    The Microsoft ADSI provider implements a set of ADSI objects to support various ADSI interfaces. The namespace name for the Windows provider is "WinNT" and this provider is commonly referred to as the WinNT provider. To access the WinNT provider, bind to any of the ADSI objects of WinNT, using the WinNT AdsPath.

    User Creation with the ADSI LDAP Provider
    With the ADSI LDAP provider, you can only create a global user account. Local accounts reside in the SAM database and must be created using the WinNT provider. For more information about creating a user object with the WinNT provider, see WinNT User Object.

    or take advantage of pre-written / tweak-able stuff.

    Local User Management Module
    This Windows PowerShell module contains the following functions: New-LocalGroup New-LocalUser Remove-LocalGroup Remove-LocalUser Set-LocalGroup Set-LocalUser Set-LocalUserPassword Test-IsAdministrator

    PowerShell Module to Manage Local Users and Groups 1.4
    This is version 1.4 of the module.  It's still early in it's development but should ease on some of the headaches of managing local users and groups.There is better version of this module compiled to Binary code