Asked by:
Need export of AD User's Manager's Detail using text file source

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} $MGR_Last=$managerDetails.sn $MGR_First=$managerDetails.givenName $MGR_Phone=$managerDetails.telephoneNumber $MGR_email=$managerDetails.mail } $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
-
I recommend that you start by learning basic PowerShell and not by guessing and copying.
- Microsoft Virtual Academy - Getting Started with Microsoft PowerShell
- PowerShell Documentation
- PowerShell Style Guidelines
Once you have the basics then your issues will be gone.
You can also find scripts in the Gallery that do what you are asking:
\_(ツ)_/
Friday, October 26, 2018 8:45 PM -
While I do appreciate the links and advice, I have learned over the past 42 years that I suck at programming. And that it mostly just doesn't click from a creation standpoint. I have read a lot of powershell training, and I'm still in this bind. Can you suggest another forum where I can get direct assistance on my issue?Friday, October 26, 2018 9:22 PM
-
As I posted above. You can ask for someone to write a script for you in that forum.
\_(ツ)_/
Friday, October 26, 2018 9:24 PM