简体   繁体   中英

Get an AD user's manager and input it into column of table

I have a .csv file that has the first and last names, as well as the email addresses of employees who've taken our security awareness training.
I want to take the email address column and compare it to the email address in AD, then take the manager from AD and put it into the appropriate column of my table.

This is what I have so far:

Import-Csv -Path "filename.csv" | 
    Select-Object "First Name",
        "Last Name",
        "Email",
        @{n="Manager";e={(Get-ADUser $_.Manager).EmailAddress}},
        "Module Status",
        "Module Status Date" | 
    Select -f 30 | 
    Format-Table

Thanks!

@{n="Manager";e={
    $self = Get-ADUser $_.Email -properties manager
    $manager = Get-ADUser $self.manager -properties emailAddress
    $manager.emailAddress
}

Of course you can write it shorter if you want to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM