Update as an alternative to the excellent answer from 2010:
You can now use the Get-LocalGroupMember
, Get-LocalGroup
, Get-LocalUser
etc. from the Microsoft.PowerShell.LocalAccounts
module to get and map users and groups, available in PowerShell 5.1 and above.
Example:
PS C:\WINDOWS\system32> Get-LocalGroupMember -name users
ObjectClass Name PrincipalSource
----------- ---- ---------------
User DESKTOP-R05QDNL\someUser1 Local
User DESKTOP-R05QDNL\someUser2 MicrosoftAccount
Group NT AUTHORITY\INTERACTIVE Unknown
You could combine that with Get-LocalUser
. Alias glu
can also be used instead. Aliases exists for the majority of the new cmdlets.
In case some are wondering (I know you didn't ask about this)
Adding users could be for example done like so:
$description = "Netshare user"
$userName = "Test User"
$user = "test.user"
$pwd = "pwd123"
New-LocalUser $user -Password (ConvertTo-SecureString $pwd -AsPlainText -Force) -FullName $userName -Description $description