Share via


How to filter search by property MemberOf !?

Question

Wednesday, September 26, 2012 10:29 PM

Hi Everyone

I would like make a query to my AD DS where I can get the names of the computers that do not belong to a certain group. I have the following query:

Get-ADComputer -Filter {MemberOf -NotLike "SomeGroup*"} -Property * | Format-Table Name,OperatingSystem -Wrap -Auto

But when I run it does not show me any results and I'm sure there are computers that do not belong to that group... Any recommendations !?

Regards,

 

Jimcesse
Principal: http://sysadmin-cr.com/
Alterno: http://blogs.itpro.es/jimcesse

All replies (12)

Wednesday, September 26, 2012 11:03 PM ✅Answered | 1 vote

Try this:

Get-ADComputer  -Property * |  where {$_.memberof -notmatch 'SomeGroup'} |   Format-Table Name,OperatingSystem -Wrap -Auto

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


Wednesday, September 26, 2012 10:37 PM

I believe it returns distinguishednames of the groups, so you may need to wildcard both ends of the group name ('*SomeGroup*') or add CN= to the beginning.

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


Wednesday, September 26, 2012 10:49 PM

Hello mjolinor

Same result does not return anything...

Jimcesse
Principal: http://sysadmin-cr.com/
Alterno: http://blogs.itpro.es/jimcesse

Wednesday, September 26, 2012 10:56 PM

I'm not where I can test.  What does

get-adcomputer <computername> -property memberof

return?

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


Wednesday, September 26, 2012 10:58 PM

Sure, that way if it returns results...

Jimcesse
Principal: http://sysadmin-cr.com/
Alterno: http://blogs.itpro.es/jimcesse

Wednesday, September 26, 2012 11:08 PM

You Rock !!!

That way returns me results ... thank you very much...

Regards,

Jimcesse
Principal: http://sysadmin-cr.com/
Alterno: http://blogs.itpro.es/jimcesse

Wednesday, September 26, 2012 11:12 PM

I forgot to mention...You have toaddthe parameter -Filter *

Get-ADComputer -Filter * -Property * | 
 where {$_.memberof -notmatch 'SomeGroup'} | 
  Format-Table Name,OperatingSystem -Wrap -Auto
Jimcesse
Principal: http://sysadmin-cr.com/
Alterno: http://blogs.itpro.es/jimcesse

Wednesday, September 26, 2012 11:26 PM

I always forget that.  I'm not where I can test right now, so this is "air code".

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


Monday, September 24, 2018 7:21 PM

this works? I find that filtering on memberof is inconsistent at best, because  "memberof" is truncated and the groups in it are not sorted consistently.


Monday, September 24, 2018 9:00 PM

"memberof" is an array:

Get-ADComputer -Filter * -Property OperatingSystem | 
    where {$_.memberof -notcontains 'SomeGroup'} | 
    Format-Table Name,OperatingSystem -AutoSize

Try not to use a * for properties.

\(ツ)_/


Tuesday, September 25, 2018 3:01 PM

tell me what i'm doing wrong here.

#count all users in the OU, returns 618
(get-aduser -searchbase $searchbase -filter * | ? {$_.distinguishedname -notlike "*service accounts*"}).count

#count all users in the OU, in the group, returns 252

(get-aduser -searchbase $searchbase -filter * -Properties memberof | ? {$_.distinguishedname -notlike "*service accounts*" -and $_.memberof -like $group}).count

#count all users in the OU, NOT in the group, returns 602

(get-aduser -searchbase $searchbase -filter * -Properties memberof | ? {$_.distinguishedname -notlike "*service accounts*" -and $_.memberof -notlike $group}).count

#count all users in the OU, NOT in the group, using filterscript, returns 602

(get-aduser -searchbase $searchbase -filter * -Properties memberof | ? -filterscript {$_.distinguishedname -notlike "*service accounts*" -and $_.memberof -notlike $group}).count

#count all users in the OU, Not in the group, using notcontains, returns 618

(get-aduser -searchbase $searchbase -filter * -Properties memberof | ? {$_.distinguishedname -notlike "*service accounts*" -and $_.memberof -notcontains $group}).count

if there are 618 users in the OU, and 252 of them are in the group, how can 602 of them not be in the group?


Tuesday, September 25, 2018 3:09 PM

Please do not add an unrealted question to another users topic. Also this topic has been answered and closed for many years.

\(ツ)_/