S
S
steven_sinofsky2014-04-25 08:16:48
PowerShell
steven_sinofsky, 2014-04-25 08:16:48

PowerShell - How to display parent and top user manager from Active Directory?

Good afternoon.
Created a script that displays the following data about a user from Active Directory:
SamAccountName - User name
displayName - Display name
Created - Date of user creation
Enabled - Active or not (True/false)
Manager - Superordinate manager (line in the organization)
AccountExpirationDate - Expiration date user expiration date

Get-ADUser -Filter {SamAccountName -like "UserPrefix*"} -Properties * `  -SearchBase "OU=Users,OU=OU,OU=Sites,OU=COMPANY,DC=domain,DC=com" |
  select SamAccountName, displayName, Created, Enabled, @{Name='Manager'; Expression={(Get-AdUser $_.Manager -Properties DisplayName).DisplayName}}, AccountExpirationDate |
  Export-CSV "Final15.csv"

Now we need to display the "Top" of the user manager. That is, the one that stands at the very top of the department (that is, one level lower than the head of the organization). Help.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai Turnaviotov, 2014-05-01
@foxmuldercp

1. In the user accounts in AD there is a "head" field, who prevents you from using it normally?
2. psh has a provider for accessing AD, and then technet.microsoft.com/en-us/library/ee617195.aspx

M
mtp, 2014-08-18
@mtp

Only if for each user to make a cycle in which to climb the ladder in the Manager field to the stop, and then take the previous value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question