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