Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

[ADSI] Local Groups Users, Users Type, etc ...

$
0
0

I'm having an emergency for a compliance audit they want to know who has access to a list of servers.

I found some scripts which help, but unfortunately it doesn't go as far as I need.

I need to list all the local groups, and users of a server. That what the script below does pretty well:

$server = "." # servername to query
$computer = [ADSI]"WinNT://$server,computer"

$list=@()

$computer.psbase.children | where { $_.psbase.schemaClassName -eq 'group' } | foreach {
    $group =[ADSI]$_.psbase.Path
    $group.psbase.Invoke("Members") | foreach {
		$us = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
		$list += new-object psobject -property @{Group = $group.Name;User=$us}
	}
}

$list |ft -a 

What I would like to know, is the type of each group members. So if a member is a user, I would like to see the "JohnDoe (User)", and if it is a Group I would like to see "Group1 (Group)"

What would be also nice, is to recursively expand all the groups.

Here is an output example that I would like to get

GroupMemberTypeUsers expansion
AdministratorsLocal\User1User
AdministratorsDomainy\User2User
AdministratorsLocal\Group1GroupList of the Group1 member
AdministratorsDomainx\Group2GroupList of the Group2 member
Remote Desktop UsersUser1User
Remote Desktop UsersLocal\User5User
Remote Desktop UsersDomainx\Group3GroupList of the Group3 member


TIA




Viewing all articles
Browse latest Browse all 21975

Trending Articles