PowerShell to Get local user membership remotely

9.5k views Asked by At

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.

1

There are 1 answers

0
Shawn Esterman On

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) }