need help to list users with second owner in a csv file

Hello.

My Problem is, i have to list all Users in a specified OU, with entries in the Second Owner field.

How i can do this and export in a CSV File?

Would be great if someone could help.

Thanks and best regard

Eddi

  • Hey Eduard,

    You can do this through the web interface. Browse to the OU and select it. Once the user list populates, hit the hamburger button next to the filter bar, and select "choose columns". Ensure only Name and Secondary Owners is selected.

    The user list should now show a list of users and their secondary owners in separate columns. Click the hamburger button again and select "save to file" to export the list as a CSV.

  • Hi Nick.

    Thanks for your answer. 

    Thats one solution, but we need them as a powershell script. It has to run everyday at 2 O'clock morning.

    Now i wrote a script to get the Secondary Owners, but in CSV File, some Users have not the Secondary Owners inside, only System Object.

    But if i run the script without export, i can see all secondary owners.

    Thanks for your help

    Eduard 

  • If you show us your script, we can suggest how to update it to get by the issue.  Mostly likely you will need to do an '-ExpandProperty' on edsvaSecondaryOwners but we need to see your existing code in order to suggest the appropriate modifications.

  • Hi. 

    Sorry, here is my script. 

    Connect-QADService -Proxy -Credential (Get-Credential)
    Get-QADUser -Sizelimit 0 -searchroot 'OU=example_Accounts_Users_external,OU=Accounts_Users_external,OU=external,OU=Users,OU=Accounts,DC=corp,DC=example,DC=com' -IncludedProperties edsvaSecondaryOwners | Select-Object -Property Name,edsvaSecondaryOwners | Export-CSV -Path c:\temp\UserExport2.csv

    This is my output:

    #TYPE Selected.ActiveRoles.ManagementShell.Data.ArsUserObject
    Name,"edsvasecondaryowners"
    EXT Lukas,"CN=Matthias,OU=Accounts_Users_internal,OU=Accounts_Users_internal,OU=internal,OU=Users,OU=Accounts,DC=corp,DC=example,DC=com"
    EXT Leonhard,"CN=Matthias,OU=Accounts_Users_internal,OU=Accounts_Users_internal,OU=internal,OU=Users,OU=Accounts,DC=corp,DC=example,DC=com"
    EXT Richard,"CN=Matthias,OU=Accounts_Users_internal,OU=Accounts_Users_internal,OU=internal,OU=Users,OU=Accounts,DC=corp,DC=example,DC=com"
    EXT Klaus,"CN=Matthias,OU=Accounts_Users_internal,OU=Accounts_Users_internal,OU=internal,OU=Users,OU=Accounts,DC=corp,DC=example,DC=com"
    EXT Marian,"CN=Florian - Depro 2020-01-22,OU=Accounts_Disabled,OU=_Disabled,OU=Accounts,DC=corp,DC=example,DC=com"
    EXT Dmytro,"CN=Florian - Depro 2020-01-22,OU=Accounts_Disabled,OU=_Disabled,OU=Accounts,DC=corp,DC=example,DC=com"
    EXT Robert,"System.Object[]"
    EXT Scrum,"System.Object[]"
    EXT BASE,"CN=Juergen,OU=Accounts_Users_internal,OU=Accounts_Users_internal,OU=internal,OU=Users,OU=Accounts,DC=corp,DC=example,DC=com"
    EXT Eva,"System.Object[]"
    EXT Gabriel,"System.Object[]"
    EXT Johannes,"System.Object[]"

    Thanks and BR

    Eduard

  • Quick fixes to your select and export CSV:

    Select-Object -Property Name,@{Name="edsvaSecondaryOwners";Expression={[string]::join(";",($_.edsvaSecondaryOwners))}} | Export-CSV -Path c:\temp\UserExport2.csv -NoTypeInformation

    NOTES

    1.  The Name / Expression allows you to take a returned property and do some transformation on it (described below)

    2.  The string/join takes the ...SecondaryOwners list and converts it to a string delimited by semi-colons.

    Reference

    3.  The "-notypeinformation" gets rid of the message at the top of your output file.

  • Had to edit the above...please re-check online version

  • Hi Johnny

    Thanks for your help! 

    It works for me Smiley  

    Thanks a lot, you saved my day. 

    Cheers Eduard

  • Hi Johnny.

    Short question. 

    What i have to change, when i would get the SamAccountName, Name and DistinguishedName from the Secondary Owners and removing the User OU Paths.

    EXT Dmytro,"CN=Florian - Depro 2020-01-22,OU=Accounts_Disabled,OU=_Disabled,OU=Accounts,DC=corp,DC=example,DC=com"   <-should removed.

    Thank You and cheers 

    Eduard

  • I'm not sure I follow 100% - for each Secondary Owner, you would like to show the samaccountname,Name and Distinguished name.  What is confusing me though is that you want to remove the User OU path - this is part of the distinguished name so do you only want the "CN=" part of the distinguishedname shown for SecondaryOwners?

    Something like this?