Quantcast
Viewing all articles
Browse latest Browse all 21975

Problem with contains() method while using with get-AdGroupMember cmdlet

Hello PowerShell Experts,

I have a problem with using contain() method with Get-adgroupMember  cmdlet.

I am using a simple cmdlet to check the member of AD Group.

my script contains :

$u=(Get-ADUser -Identity user1).distinguishedname
$g=Get-ADGroupMember testgroup
if ($g.contains($u))
{
Write-Host "success" }
else
{
write-host "failed"
}


Error showing :

Method invocation failed because [System.Object[]] doesn't contain a method named 'contains'.
At line:3 char:16
+ if ($g.contains <<<< ($u))
    + CategoryInfo          : InvalidOperation: (contains:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
But , when we check all member of $g  . contains() method is present .

PS C:\Users\administrator> $g|Get-Member -MemberType method

   TypeName: Microsoft.ActiveDirectory.Management.ADPrincipal

Name          MemberType Definition                                              
----          ---------- ----------                                              
Contains      Method     bool Contains(string propertyName)                     
Equals        Method     bool Equals(System.Object obj)                          
GetEnumerator Method     System.Collections.IDictionaryEnumerator GetEnumerator()
GetHashCode   Method     int GetHashCode()                                       
GetType       Method     type GetType()                                          
ToString      Method     string ToString()                                       


I can see Contains() method here ,  then why I my script doesn't work ?

Any idea please ?

Thanks in Advance .

Viewing all articles
Browse latest Browse all 21975

Trending Articles