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

Members of group in remote forest

$
0
0

Hi I'd like to make the following code work against a remote forest so need to take credential and DC/DN name.

It finds members of group and is much faster than get-distributiongroupmember

Add-Type -AssemblyName System.DirectoryServices.AccountManagement Measure-Command {Get-ADGroupMember 'Domain Users' } $domain='DOMAIN'

$groupname ='GROUP'

$pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Domain, $domain) $group2 = [System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($pc, [System.DirectoryServices.AccountManagement.IdentityType]::Name, $groupname) $group2.Members.GetEnumerator() | % { $_.DisplayName }

Could you help where to add directory context and $credentials?

Thanks


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>