question

JamesElliott-0300 avatar image
0 Votes"
JamesElliott-0300 asked IanXue-MSFT answered

Script Question

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-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.