2

I need to get the names of all administrator accounts in Powershell, but this command

get-ciminstance -class win32_account | select name | where name -eq administrator

returns only the account with the name administrator, it doesn't recognize other admin users with different names

I have also tried

get-ciminstance -class win32_account | select name | where name -eq administrator*

but it doesn't return anything when I use the wildcard.

What do I need to change in order to get a list of admin users on my computer?

Rohit Gupta
  • 2,721
  • 18
  • 27
  • 35

1 Answers1

1
get-ciminstance -class win32_account | select name | where name -match administrator

this will return all the users that have the word administrator in them, for example administrator1 or administrator-mike instead of using *, you should be using -match

a better commandlet would be:

Get-LocalGroupmember -name administrators | select name

This will list all administrators like this: computername\user where computername is your computer's name and user is an administrator user for example: Windows-pc\Admin123

if you want an output with only usernames without the computer name, then use:

net localgroup administrators
Michel
  • 104
  • 8