WHOAMI - CMD


Overview

The WHOAMI command in Windows Command Prompt displays user, group, and privileges information for the user running the command. It is primarily used for troubleshooting and system administration to confirm user account details and memberships. This command can be particularly useful in environments with complex security settings or multiple user accounts.

Syntax

The basic syntax of the WHOAMI command is:

WHOAMI [options]

Options can include:

  • /UPN : Displays the user name in User Principal Name (UPN) format.
  • /FQDN : Displays the fully qualified domain name (FQDN) for the user.
  • /USER : Displays user information.
  • /GROUPS : Displays the user groups.
  • /PRIV : Shows the security privileges of the current user.
  • /ALL : Displays all of the above information.
  • /FO format : Specifies the output format (TABLE, LIST, CSV).
  • /NH : Suppresses column headers in output. Useful in scripts or when piping output to other commands.

Options/Flags

  • /UPN: Useful when you need to know the user’s principal name, often required in applications that use domain-based credentials.
  • /FQDN: Helpful in networks where domain details are necessary for troubleshooting or network setup.
  • /USER: Provides concise user account details, including the account name and SID.
  • /GROUPS: Lists all group memberships, which is crucial for checking access permissions and roles.
  • /PRIV: Lists out the security privileges. This is important for security auditing or verifying that a process can run with the necessary rights.
  • /ALL: Offers a comprehensive summary of the user, groups, and privileges. Ideal for detailed audits.
  • /FO format: Allows for formatting the output to fit different use cases or to make it easier for further processing by other tools.
  • /NH: Typically used in scripting to produce cleaner output that is easier to parse.

Examples

  1. Basic Usage:

    WHOAMI
    

    Displays the current domain and user name.

  2. View User Account Details:

    WHOAMI /USER
    

    Displays detailed information about the user.

  3. List All Group Memberships:

    WHOAMI /GROUPS
    

    Lists all user groups the current user belongs to.

  4. Display Complete Information in Table Format:

    WHOAMI /ALL /FO TABLE
    

    Provides a detailed table of user, group memberships, and privileges.

  5. Output Without Headers in CSV Format:

    WHOAMI /GROUPS /FO CSV /NH
    

    Outputs group information in CSV format without column headers, ideal for scripting purposes.

Common Issues

  • Permission Errors: Some WHOAMI outputs, like /PRIV, might require administrative privileges. Ensure you have the necessary rights or run the command prompt as an administrator.
  • Output Clarity: Without proper formatting options, output can be overwhelming. Use /FO and /NH options to manage how information is displayed.

Integration

WHOAMI can be integrated with other CMD commands to build more complex scripts or solve specific problems:

  • Check Specific Group Membership and Act:
    FOR /F "tokens=*" %G IN ('WHOAMI /GROUPS /FO LIST /NH') DO (
      IF "%G" == "Administrators" (
        ECHO User is an Administrator.
      )
    )
    
  • Log User Details:
    WHOAMI /ALL > user_details.txt
    
  • NET USER: Provides information about user accounts and settings on the local machine or domain.
  • NET LOCALGROUP: Lists or modifies local groups on the computer.

Further information can be found in the official Microsoft documentation.