2

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.

boxdog
  • 7,894
  • 2
  • 18
  • 27
  • The nice thing about PowerShell is that you can send any command that does local work over using `Invoke-Command` (assuming you've set up PowerShell remoting, of course). Including `Get-LocalUser`. – Jeroen Mostert Apr 06 '18 at 14:08

1 Answers1

3

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) }
Shawn Esterman
  • 2,292
  • 1
  • 10
  • 15