get upn and samaccountname from directreports

Frequent Contributor

Hello all

First thank you for any help with this. I have the below one liner that shows me all the disabled users that have a value for direct reports on the disabled users account. What i am trying to get is the upn, and samaccountname for the accounts that are mentioned on the direct reports. If i run the below command it shows me the DN for the accounts, but i need upn and sam. Thanks in advance. 

$Disabled = Get-ADUser -Filter * -Properties samaccountname,directreports,enabled | where {$_.directreports -notlike $null -and $_.enabled -eq $False} |select samaccountname,enabled,directreports,distinguishedname

 

2 Replies
$Disabled = Get-ADUser -Filter * -Properties samaccountname,directreports,enabled | where {$_.directreports -notlike $null -and $_.enabled -eq $False} |select userprincipalname,samaccountname,enabled,directreports,distinguishedname

You forgot to include the userprincipalname after the select statement
Did this work for you?