Need export of AD User's Manager's Detail using text file source RRS feed

  • Question

  • I have a text file with a simple single column list of AD User accounts (e.g. fde54326 ges11035).  I want to create a CSV based on that list.
    I want the output to include the user's manager's Last name, First name, Phone and Email.

    I have basic powershell skills and I'm one of those people who gets writer's block when I try to code almost anything.  I can usually piece and part things to get what I need, but I've tried a BUNCH of different things and need help.  I know pieces of my code work as part of other scripts I have pieced together.

    Here's my code:

    $UserList = Get-Content C:\scripts\LicenseCounts\hodUsers_short.txt
    ForEach ($user in $UserList)
        Get-AdUser $user -Properties * | Select SAMAccountName,DisplayName,GivenName,SN,TelephoneNumber,Department,Mail,Manager
        $managerDetails = Get-ADUser (Get-ADUser $User -properties manager).manager -properties sn,givenName,telephoneNumber,mail
        ### $managerDetails = Get-ADUser (Get-ADUser $User -properties manager | Select manager | ? {$_.manager -ne $null} ).manager -properties sn,givenName,telephoneNumber,mail | Select sn,givenName,telephoneNumber,mail | ? {$_.sn -ne $null} | ? {$_.givenName -ne $null} | ? {$_.telephoneNumber -ne $null} | ? {$_.mail -ne $null}
     $UserList |
     Select SamAccountName,DisplayName,GivenName,sn,TelephoneNumber,Department,Mail,$MGR_Last, $MGR_First,$MGR_Phone,$MGR_email
     ### | Export-CSV -Path C:\scripts\LicenseCounts\HODUsers_output.csv -NoTypeInformationcls

    I have an alternate "ManagersDetails" and the export commented out so I can see the result on screen.  My issue appears to be when I'm trying to "nest" the "managersdetail" part and the ouput from that.

    Thank you all for any help!

    • Edited by tlynch Friday, October 26, 2018 6:10 PM spelling
    Friday, October 26, 2018 6:01 PM

All replies