Remove-ADUser

Remove an Active Directory user.

Syntax
      Remove-ADUser [-Identity] ADUser [-AuthType {Negotiate | Basic}]
         [-Credential PSCredential] [-Partition string]
            [-Server string] [-Confirm] [-WhatIf] [CommonParameters]

Key
   -AuthType {Negotiate | Basic}
       The authentication method to use: Negotiate (or 0), Basic (or 1)
       A Secure Sockets Layer (SSL) connection is required for Basic authentication.

   -Credential PSCredential
       A user account that has permission to perform this action.
       The default is the current user unless the cmdlet is run from an AD PowerShell provider drive
       in which case the account associated with the drive is the default.

       "User64" or "Domain01\User64" or a PSCredential object.

   -Identity ADUser
       Specify an AD user object by providing one of the following values.
       (The identifier in parentheses is the LDAP display name for the attribute.)

          Distinguished Name 
            Example: CN=GailMoss,OU=europe,CN=users,DC=corp,DC=SS64,DC=com 
          GUID (objectGUID) 
            Example: 599c4d2e-f72d-4d20-8a78-030d69495f20
          Security Identifier (objectSid) 
            Example: S-1-5-21-5165297888-301467370-576410423-1803
          Security Accounts Manager (SAM) Account Name (sAMAccountName)
            Example: GailMoss

       The cmdlet searches the default naming context or partition to find the object.
       If two or more objects are found, the cmdlet returns a non-terminating error.

       This parameter can also get this object through the pipeline or you can set this
       parameter to an object instance.

   -Partition string
       The distinguished name of an AD partition.
       The distinguished name must be one of the naming contexts on the current
       directory server. The cmdlet searches this partition to find the object defined by
       the -Identity parameter. 
       The following two examples show how to specify a value for this parameter.
          -Partition "CN=Configuration,DC=EUROPE,DC=TEST,DC=SS64,DC=COM"
          -Partition "CN=Schema,CN=Configuration,DC=EUROPE,DC=TEST,DC=SS64,DC=COM"
          
       In many cases, a default value will be used for the Partition parameter if no value
       is specified.

   -Server string
       The AD Domain Services instance to connect to, this may be a Fully qualified domain name,
       NetBIOS name, Fully qualified directory server name (with or without port number) or AD Snapshot instance.

       Examples: demo.SS64.com  demo  demoDC02.demo.ss64.com  demoDC02.demo.ss64.com:3268

   -Confirm
       Prompt for confirmation before executing the command.

    -WhatIf
       Describe what would happen if you executed the command, without actually executing the command.

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

Remove-ADUser removes an Active Directory user.

The -Identity parameter specifies the AD user to remove. Identify a user with a distinguished name (DN), GUID, security identifier (SID) or security accounts manager (SAM) account name. The Identity parameter can also be set to a user object variable, or a user object (Get-ADUser) passed through the pipeline.
If the ADUser is being identified by its DN, the -Partition parameter will be automatically determined.

For AD LDS environments, the -Partition parameter must be specified except in the following two conditions:
-The cmdlet is run from an Active Directory provider drive.
-A default naming context or partition is defined for the AD LDS environment. To specify a default naming context for an AD LDS environment, set the msDS-defaultNamingContext property of the Active Directory directory service agent (DSA) object (nTDSDSA) for the AD LDS instance.

Examples

Remove the user with samAccountName 'GailMoss':

PS C:\> Remove-ADUser -Identity GailMoss

Search for any users that have disabled accounts and remove them:

PS C:\> Search-ADAccount -AccountDisabled | where {$_.ObjectClass -eq 'user'} | Remove-ADUser

Remove the user with DistinguishedName 'CN=Gail Moss,OU=UserAccounts,DC=SS64,DC=com':

PS C:\> Remove-ADUser -Identity "CN=Gail Moss,OU=UserAccounts,DC=SS64,DC=com"

“.. almost everything – all external expectations, all pride, all fear of embarrassment or failure - these things just fall away in the face of death, leaving only what is truly important” ~ Steve Jobs

Related:

Remove-QADObject - Delete object(s) from Active Directory (Quest)
New-adUser - Create a new AD user.
Set-adUser - Modify an AD user.


© Copyright SS64.com 1999-2013
Some rights reserved