I was able to piece together a script. This script will query the AD and return a list which is needed. The problem we had was when we used manager it returned this very long list and (the entire OU path), and what we really wanted was the managers email address.
I searched and found some code that would give the samaccountname. I figured easy enough to change that to the attribute “mail” but when I do modify it nothing is returned for manager.
we was able to use the script below and then HR concatenated the end of the email onto the samaccountname in excel so we found a work around. However, as a young powershell user learning the basics its driving me crazy that I cannot get this to just give the email =(
any ideas?
Below is the code.
$props = @(‘employeeNumber’, ‘Name’, ‘mail’, ‘manager’)
$ous=@(“ou=testfolder,dc=test,dc=net,dc=int”)
$ous | ForEach {
Get-ADUser -Properties $props -Filter ‘Enabled -eq $true’ -SearchBase $_ | Select employeeNumber, name, mail, @{Name=‘Manager’;Expression={(Get-ADUser $_.Manager).sAMAccountName}}
} |export-csv -NoTypeInformation c:\scripts\HRdata.csv
The portion that was new to this script was the following @{Name=‘Manager’;Expression={(Get-ADUser $_.Manager).sAMAccountName}}
I tried as stated earlier to change it to @{Name=‘Manager’;Expression={(Get-ADUser $_.Manager).mail}}
However that would not work for some reason.
Everything else I have been using for awhile now to pull up information on attributes.