I want to fetch the manager's user object and grab the DisplayName instead of the DN.
$expiredaccounts = Search-ADAccount -AccountExpiring -TimeSpan 70.00:00:00 | Where-Object { ($_.Enabled -eq $true) }
$expiredaccounts | Select-Object name, SamAccountName, @{Name='EmployeeID';Expression={($_ |Get-ADUser -Properties employeeID).employeeID}} , @{Name='Manager';Expression={($_ |Get-ADUser -Properties manager).manager}}
Output:
name SamAccountName EmployeeID Manager
---- -------------- ---------- -------
User user01 CN=User,OU=IT,DC=contoso,DC=com
Pipe it to Get-ADUser
once again:
$expiredaccounts | Select-Object name, SamAccountName, @{Name='EmployeeID';Expression={($_ |Get-ADUser -Properties employeeID).employeeID}} , @{Name='Manager';Expression={ (($_ |Get-ADUser -Properties manager).manager | Get-ADUser).Name}}
Explanation :
You take the Manager
property and run Get-ADUser
against it. It returns user object of user's manager. Using .Name
you extract the only required property, which is display name.
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.