Share via

Script Question

James Elliott 1 Reputation point
2021-05-12T14:28:21.74+00:00

I would like the following script to include the variables on the second script and it "i" variable I would like to show as Location

Get-ADUser -Filter * -Properties title, department, manager | Select-Object title,department,@{name='ManagerName';expression={(Get-ADUser -Identity $_.manager | Select-Object -ExpandProperty name)}},@{name='ManagerEmailAddress';expression={(Get-ADUser -Identity $_.manager -Properties emailaddress | Select-Object -ExpandProperty emailaddress)}} | Format-list



Get-ADUser -Filter * -Properties Name, mail,title, canonicalName, department, l, Manager, mobile,telephoneNumber  | where {$_.Enabled -eq "True"} | Select-Object Name,mail,title,canonicalName,department,l,Manager,mobile,telephoneNumber | Export-CSV adusersactive.csv

The aim here is to export as clear list of users from AD which includes Name, email, job title, OU, department, location , Manager, mobile, and telephone number and formats it to a CSV , if there is a better way of doing this please let me know.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-05-13T05:27:39.197+00:00

    Hi,

    Please check to see if this works.

    Get-ADUser -Filter * -Properties mail,title,department,l,Manager,mobile,telephoneNumber |   
        Select-Object Name,mail,title,DistinguishedName,department,@{name='Location';expression={$_.l}},mobile,telephoneNumber,  
        @{name='ManagerName';expression={(Get-ADUser -Identity $_.manager | Select-Object -ExpandProperty name)}},  
        @{name='ManagerEmailAddress';expression={(Get-ADUser -Identity $_.manager -Properties emailaddress | Select-Object -ExpandProperty emailaddress)}}|  
        Export-Csv adusersactive.csv  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.