Pull of AD users managers name and email to existing script powershell script

I currently have a script which I am trying to alter, which is able to pull of from AD groups Usernames, Name, Email and Managers:

$ou = 'OU=OUoftheADgroups,OU=My,DC=Domain,DC=net'
Get-ADGroup -Filter * -SearchBase $ou -Properties Description | ForEach-Object {
   $params = @{
       LDAPFilter = '(memberof={0})' -f $_.DistinguishedName
       Properties = 'mail', 'manager'
   }
   foreach($member in Get-ADUser @params) {
       [pscustomobject]@{
           Username       = $member.SamAccountName
           Name           = $member.Name
           Mail           = $member.Mail
           Manager        = $member.Manager
           GroupName      = $_.Name
       }
   }
} | Export-csv C:UsersTestUserDesktopNameOfMyFile.csv -NoTypeInformation

The problem is the manager details is it pull off is just displaying the managers distinguishedName name e.g. CN=Manager1,CN=Users,DC=My,DC=Domain,DC=net

I have been looking online and try to get this working but unable to do so.

I have been looking online managed to find a script which audit a single AD groups rather than an OU (found via https://forums.powershell.org/t/getaduser-need-manager-name-and-email-in-results/16471/4)

$adGroupList = 'BI_FINANCE_FULL','BI_FIN_EXP_FACILITIES_FULL_R1'
$results = foreach ($group in $adGroupList) {
    Get-ADGroupMember -identity $group -Recursive | 
        Get-ADUser -Properties * | 
            Select-Object @{Name='Group';Expression={$group}},
                   displayname,
                   name,
                   employeeID,
                   Department,
                   title,
                   physicalDeliveryOfficeName,
                   Manager,
                   @{Name='ManagerName';Expression={Get-ADUser -Identity $_.Manager | Select-Object -ExpandProperty DisplayName}},
                   sAMAccountName,
                   givenName,
                   surname,
                   UserPrincipalName
}

$results | Export-Csv -Append “C:tempGetADGroupMember4.csv” -NoTypeInformation -Encoding UTF8

UPDATE 1

Just ran the script above and the same issue occurs with that also, managers details is supplied as but the managername field is blank and the managers field is distinguishedName (same as my script above)

UPDATE 2

I have modified the code as requested (probably done this wrong):

$ou = 'OU=OUoftheADgroups,OU=My,DC=Domain,DC=net'
Get-ADGroup -Filter * -SearchBase $ou -Properties Description | ForEach-Object {
   $params = @{
       LDAPFilter = '(memberof={0})' -f $_.DistinguishedName
       Properties = 'mail', 'manager'
   }
   foreach($member in Get-ADUser @params) {
    Manager = (Get-ADuser $member.Manager).DisplayName 
       [pscustomobject]@{
           Username       = $member.SamAccountName
           Name           = $member.Name
           Mail           = $member.Mail
           Manager        = $member.Manager
           GroupName      = $_.Name
       }
   }
} | Export-csv C:UsersTestUserDesktopNameOfMyFile.csv -NoTypeInformation

When trying to run the code I get the following error:

Manager : The term 'Manager' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At C:UsersTestUserDesktopAudit.ps1:9 char:5
+     Manager = (Get-ADuser $member.Manager).DisplayName
+     ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Manager:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I have tried to put add code Manager = (Get-ADuser $member.Manager).DisplayName to other areas of hte code but still fails

Update 3

I did try that but as I tried placing the line of code in different areas I didn’t to post loads of uncessary code.

Made the change you requested and got this error message:

Get-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the 
command again.
At C:UsersTestUserDesktopAudit.ps1:13 char:42
+             Manager        = (Get-ADUser $member.Manager).DisplayName
+                                          ~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Update 4

The script now works but the manager display name is not being pulled from AD into the CSV:

UPDATE

Seems like it is only pull one manager of AD and repeating for all users:

10

The first code snippet is correct, you just need to query AD to get the manager’s Display Name from $member.Manager (the manager’s Distinguished Name). Some user’s might not have a manager assigned so you can simply add a condition that checks if the .Manager attribute is populated. The could would be:

$ou = 'OU=OUoftheADgroups,OU=My,DC=Domain,DC=net'
Get-ADGroup -Filter * -SearchBase $ou -Properties Description | ForEach-Object {
    $params = @{
        LDAPFilter = '(memberof={0})' -f $_.DistinguishedName
        Properties = 'mail', 'manager'
    }

    foreach ($member in Get-ADUser @params) {
        $manager = if ($member.Manager) {
            (Get-ADUser $member.Manager -Properties DisplayName).DisplayName
        }
        else {
            'No manager assigned in AD'
        }

        [pscustomobject]@{
            Username  = $member.SamAccountName
            Name      = $member.Name
            Mail      = $member.Mail
            Manager   = $manager
            GroupName = $_.Name
        }
    }
} | Export-Csv C:UsersTestUserDesktopNameOfMyFile.csv -NoTypeInformation

11

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật