简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM