none
Extract disabled users from an OU and extract their group membership details as well. RRS feed

  • Question

  • Hello Guys!

    Hope you can help me. I have been trying to extract disabled users from an OU and also their group membership details. I was able to extract the users fine but not successful in getting the individual groups to which they are a member of.

    Please find my script below which I have managed so far:

    Search-ADAccount  -SearchBase “OU=Students,OU=NA,OU=Portals,OU=NLP Farm,DC=ni,DC=org”  –AccountDisabled  –UsersOnly |

    Select name, @{n=’MemberOf’; e={$_.MemberOf –join ‘;’}} |

    Export-CSV “C:\Users\t1\Desktop\Test\Test.csv”  –NoTypeInformation  -Encoding UTF8

    Thank you so much for looking into this.


    • Edited by annietiby Tuesday, April 17, 2018 10:08 AM
    Tuesday, April 17, 2018 10:07 AM

Answers

  • Hi,

    Try Get-ADUser:

    Get-ADUser -Filter {Enabled -eq $false} -Properties MemberOf -SearchBase "DC=contoso,DC=com" | Select Name, @{name = "MemberOf"; expression = { $_.MemberOf -join '' }}

    • Marked as answer by annietiby Tuesday, April 17, 2018 11:40 AM
    Tuesday, April 17, 2018 10:36 AM

All replies

  • Hi,

    Try Get-ADUser:

    Get-ADUser -Filter {Enabled -eq $false} -Properties MemberOf -SearchBase "DC=contoso,DC=com" | Select Name, @{name = "MemberOf"; expression = { $_.MemberOf -join '' }}

    • Marked as answer by annietiby Tuesday, April 17, 2018 11:40 AM
    Tuesday, April 17, 2018 10:36 AM
  • Hello,

    Thank you for your reply.

    I have tried this but it doesn't seem to be executing. I get two arrows and no further action as if it is expecting some input?

    Get-ADUser  -Filter {Enabled  -eq$false}  -Properties MemberOf  -SearchBase “OU=Students,OU=NA,OU=Portals,OU=NLP Farm,DC=ni,DC=org” | Select Name, @{name = “MemberOf”; expression = {$_.MemberOf  -join”}} | Export-CSV “C:\Users\t\Desktop\Test\Test.csv”  -NoTypeInformation  -Encoding UTF8

    Am I going wrong somewhere?

    Thank you for your help!


    Tuesday, April 17, 2018 11:06 AM
  • Are you getting any results if you just run:

    Get-ADUser -Filter {Enabled -eq $false} -Properties MemberOf -SearchBase "OU=Students,OU=NA,OU=Portals,OU=NLP Farm,DC=ni,DC=org"
    ?

    Tuesday, April 17, 2018 11:13 AM
  • Yes. It is listing all the disabled users.
    Tuesday, April 17, 2018 11:28 AM
  • The second part is working as well. Let me try the third part where it exports into CSV
    • Edited by annietiby Tuesday, April 17, 2018 11:35 AM
    Tuesday, April 17, 2018 11:33 AM
  • All good. When I did it part by part, it is working very well. I seemed to have missed an apostrophe somewhere.

    Thank you very much for your help!

    Tuesday, April 17, 2018 11:39 AM
  • Here is the pipeline method:

    $sb = 'OU=Students,OU=NA,OU=Portals,OU=NLP Farm,DC=ni,DC=org'
    Get-ADUser -Filter {Enabled -eq $false} -PipelineVariable usr -Search $sb | 
        Get-ADPrincipalGroupMembership | 
        select @{n='UserID';e={$usr.SAmAccountName}},@{n='GroupName';e={$_.Name}}


    \_(ツ)_/

    Tuesday, April 17, 2018 11:40 AM