locked
Powershell Export Active Directory RRS feed

  • Question

  • Hello Community

    I have a Powershell, that exports all enabled users from a specific OU to an Excel-File. 

    Now there are 4 Users i don't want in the excel export. Is there any way to exclude them?

    Then i want to show instead of the username the DisplayName. But with the attribute displayName it didn't work.

    Here my Script:

    Get-ADUser -Filter * -SearchBase "OU=Users,OU=DOMAIN,DC=DOMAIN,DC=LOCAL" -Properties EmployeeNumber | Where-Object {$_.Enabled -eq $true} | Select-Object userPrincipalName | Export-Csv -Path 'C:\Support\Export AD Users\enabled.csv' -NoTypeInformation

    Many thanks for your help!

    Friendly Greetings

    Dominic

    Monday, April 9, 2018 6:24 AM

All replies

  • Just specify the "DisplayName" property.  Use "Where-Object" to filter unwanted users.


    \_(ツ)_/

    Monday, April 9, 2018 7:15 AM
  • Get-ADUser -Filter 'Name -notlike "*some_filter*"' -SearchBase "OU=Users,OU=DOMAIN,DC=DOMAIN,DC=LOCAL" -Properties EmployeeNumber, DisplayName | 
        Where-Object {$_.Enabled -eq $true} | 
        Select-Object userPrincipalName, DisplayName | 
        Export-Csv -Path 'C:\Support\Export AD Users\enabled.csv' -NoTypeInformation
    The preferred way is to use the "Filter Left, Format Right" rule , hence try to use Filter. Otherwise, go for Where-Object
    Monday, April 9, 2018 7:56 AM
  • "like" and "notlike" are not very useful without "*".


    \_(ツ)_/

    Monday, April 9, 2018 9:02 AM
  • Thank you! That works for me.. :-)

    Monday, April 9, 2018 9:37 AM
  • Hi,

    I'm checking how the issue is going, was your issue resolved?

    And if the replies as above are helpful, we would appreciate you to mark them as answers. It will be greatly helpful to others who have the same question.

    Appreciate for your feedback.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 10, 2018 3:10 AM