powershell - list local users and their groups

Nicola Cossu picture Nicola Cossu · Dec 28, 2010 · Viewed 110.7k times · Source

I'd like to have a report with all the local users and their relative groups (users, power users, administrators and so on.

I get the users in this way:

$adsi = [ADSI]"WinNT://."
$adsi.psbase.children | where {$_.psbase.schemaClassName -match "user"} | select @{n="Name";e={$_.name}}

but I don't know how to retrieve their groups. Thanks in advance.

Answer

mjswensen picture mjswensen · Nov 26, 2013

For Googlers, another way to get a list of users is to use:

Get-WmiObject -Class Win32_UserAccount

From http://buckeyejeeps.com/blog/?p=764