Disable an Active Directory account.

      Disable-ADAccount [-Identity] ADAccount
         [-AuthType {Negotiate | Basic}] [-Credential PSCredential]
            [-Partition string] [-PassThru] [-Server string]
               [-Confirm] [-WhatIf] [CommonParameters]

   -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
       The user account credentials to use to perform this task.
       The default credentials are those of the currently logged on user unless the
       cmdlet is run from an Active Directory PowerShell provider drive.
       If the cmdlet is run from such a provider drive, the account associated with the drive is the default.

       Type a user name, such as "User64" or "Domain64\User64" or specify a
       PSCredential object such as one generated by Get-Credential 

       If a user name is specified, the cmdlet will prompt for a password.

    -Identity ADAccount
       An Active Directory account object by providing one of the following values.
       (The identifier in parentheses is the LDAP provider name for the attribute.)

          Distinguished Name 
            Example: CN=JonSmith,CN=Sales,OU=europe,CN=users,DC=corp,DC=SS64,DC=com 
          GUID (objectGUID) 
            Example: 599c3d2e-f72d-4d20-8a88-030d99495f20
          Security Identifier (objectSid) 
            Example: S-1-5-21-3165297888-301567370-576410423-1103
          Security Accounts Manager (SAM) Account Name (sAMAccountName)
            Example: JonSmith

       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.

       This example shows how to set the parameter to a distinguished name.
          -Identity  "CN=JonSmith,CN=Sales,OU=europe,CN=users,DC=corp,DC=SS64,DC=com"

       This example shows how to set this parameter to a group object instance named "accountInstance".
          -Identity $accountInstance
   -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 -Partition if no value is specified.

   -PassThru switch
       Return the new or modified object.
       By default (i.e. if -PassThru is not specified), this cmdlet does not generate any output.
   -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)

       Prompt for confirmation before executing the command.

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

Disable-ADAccount disables an Active Directory user, computer, or service account.

The -Identity parameter specifies the AD user, computer service account, or other service account to be disabled. Identify an account with its distinguished name (DN), GUID, security identifier (SID), or Security Accounts Manager (SAM) account name. The -Identity parameter may also be set to an object variable, or an account object passed through the pipeline. For example, you can pipe from Get-ADUser to Disable-ADAccount. Similarly, you can use Get-ADComputer and Search-ADAccount to retrieve account objects.

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.


Disable an account with SamAccountName: SteveJobs:

PS C:\> Disable-ADAccount -Identity SteveJobs

Disable an account using a DistinguishedName:

PS C:\> Disable-ADAccount -Identity "CN=SteveJobs,OU=RemoteAccounts,DC=SS64,DC=COM"

Disables all accounts in an OU:

PS C:\> Get-ADUser -Filter 'Name -like "*"' -SearchBase "OU=RemoteAccounts,DC=SS64,DC=COM" | Disable-ADAccount

“Disability is a matter of perception. If you can do just one thing well, you're needed by someone” ~ Martina Navratilova

Related PowerShell Cmdlets

Enable-ADAccount - Enable an Active Directory account.
Search-ADAccount - Get Active Directory user, computer, and service accounts.
Unlock-ADAccount - Unlock an Active Directory account.

Copyright © 1999-2023 SS64.com
Some rights reserved