To check if your current PowerShell session has administrator rights, run the following command: ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator). If the output is True, you have admin rights; if it is False, you are running as a standard user.

Verifying your privilege level is essential because many system-level tasks—such as installing software, modifying the registry, or changing network configurations—will fail with an "Access Denied" error if the shell is not elevated. This guide explains how to use this command and how to properly launch an elevated session.

What You'll Need

  • A computer running Windows.
  • Access to the PowerShell console (Windows PowerShell or PowerShell Core/7).

Step-by-Step

  1. Open PowerShell: Click the Start menu, type "PowerShell," and click on the application to open it. Note that by default, this usually opens a non-administrative session.
  2. Enter the Verification Command: Copy and paste the following command exactly as written into the console window and press Enter:

    ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
  3. Interpret the Result:
    • True: Your current window is running with full administrative privileges. You can proceed with system-level changes.
    • False: You are running as a standard user. Any command requiring elevation will be blocked.
  4. Elevate the Session (If False): If the result was False and you need admin rights:
    • Close the current PowerShell window.
    • Right-click the PowerShell icon in the Start menu or taskbar.
    • Select Run as administrator.
    • If a User Account Control (UAC) prompt appears, click Yes.
  5. Re-verify: Run the command from Step 2 again to confirm the output now reads True.

Common Mistakes

  • Typing Errors: The command relies on specific .NET classes. A single missing bracket [ ] or a lowercase letter where an uppercase one is required (though PowerShell is generally case-insensitive, the class names should be precise) can cause the command to fail.
  • Assuming the User is Admin: A common mistake is assuming that because your Windows user account is an "Administrator," every PowerShell window you open is automatically elevated. By default, Windows runs processes with standard user tokens; you must explicitly choose "Run as administrator" to activate those rights.
  • Confusing "Admin Account" with "Admin Session": Having an admin account allows you to elevate, but it does not mean the session is already elevated. Always check the session status, not just the account type.

Tips

  • Check the Window Title: A quick visual cue is the title bar of the PowerShell window. If it starts with "Administrator: Windows PowerShell," you are elevated. If it just says "Windows PowerShell," you are likely a standard user.
  • Create a Shortcut: If you frequently need to check rights or run admin scripts, create a desktop shortcut to PowerShell, right-click it, go to Properties > Shortcut > Advanced, and check Run as administrator.
  • Use a Variable: If you are writing a script and want it to stop if the user isn't an admin, you can store the result in a variable:
    $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

Troubleshooting

If the command does not work or you cannot gain admin rights, try these steps in order:

  1. Check for Typos: Ensure there are no extra spaces or missing parentheses. Copying and pasting the command is the safest method.
  2. Verify Account Permissions: If "Run as administrator" is missing or asks for a password you don't have, your user account may not be part of the local Administrators group. You will need to contact the system owner or a network administrator to grant you these permissions.
  3. Restart the Console: Sometimes a hung process can cause issues with identity tokens. Close all PowerShell windows and restart the application.
  4. Check UAC Settings: If the UAC prompt does not appear when you select "Run as administrator," your User Account Control settings may be configured incorrectly or disabled by a group policy.

Frequently Asked Questions

Why does it say False even though I am the owner of the PC?

Windows uses User Account Control (UAC). Even if your account is an administrator, PowerShell starts in "standard" mode to protect the system from accidental changes. You must explicitly right-click and select "Run as administrator" to use those rights.

Is there a shorter command to check admin rights?

While there are shorter ways to guess (like trying to run a command that requires admin rights and seeing if it fails), the .NET method provided in this guide is the most accurate and professional way to programmatically verify the session state.

Does this work in PowerShell 7 (Core)?

Yes, this command works in both the traditional Windows PowerShell (version 5.1) and the newer cross-platform PowerShell 7, as both can access the Windows security principals on a Windows OS.

Can I elevate a PowerShell window without restarting it?

You cannot "promote" an existing window to admin. You must launch a new process with the elevated token. However, you can run Start-Process powershell -Verb runAs to launch a new administrator window from within your current standard window.

Will this command work on macOS or Linux?

No. This specific command uses Windows-specific security classes (Security.Principal). On macOS or Linux, you would typically check for admin (root) rights by using the whoami command or checking if the user ID is 0.