Uddhav Ghanekar
Uddhav Ghanekar

Reputation: 11

PowerShell to Get local user membership remotely

Need some help here.

I need to get the local user list of a remote computer and what group they belong to using PowerShell script.

I tried:

Get-LocalUser
Get-LocalGroup
Get-LocalGroupMember

Also:

gwmi win32_UserAccount
gwmi win32_group 

but it is very slow and pulling the information more than requirement which consumes time.

I would like the output formatted something like below:

User     Memberof
------   --------------------
abc12    Administrators
efg23    remote desktop users
hij45    Administrators,Backup Operators,users
xyz56    remote desktop users,Backup Operators

Thanks in Advance, Cheers.

Upvotes: 2

Views: 11478

Answers (1)

Shawn Esterman
Shawn Esterman

Reputation: 2342

I use ADSI and it's pretty quick.

$RemoteComputerName = 'RemoteComputer'
$LocalGroup = 'Remote Desktop Users'

$ADSI = [ADSI]("WinNT://$RemoteComputerName,Computer")
$Group = $ADSI.PSBase.Children.Find($LocalGroup,'Group')
$Group.PSBase.Invoke('Members').Foreach{ $_.GetType().InvokeMember('Name','GetProperty',$null,$_,$null) }

Upvotes: 3

Related Questions