Forum Discussion
Skipster311-1
Dec 07, 2021Iron Contributor
Get upn and samaccount name for users mentioned on directreports
Hello all I am trying to get all disabled user accounts that have users listed on the disabled accounts "directreports" . The below code is showing me the disabled account and the directreports dist...
Jan 17, 2022
$users = Get-ADUser -Filter * -Properties samaccountname, directreports, enabled | Where-Object { $_.directreports -notlike $null -and $_.enabled -eq $False }
ForEach ($user in $users) {
$directreportsupn = (get-aduser -filter * | Where-Object DistinguishedName -Match $user.directreports).UserPrincipalName
$directreportssamaccountname = (get-aduser -filter * | Where-Object DistinguishedName -Match $user.directreports).SamAccountName
[PSCustomObject]@{
samaccountname = $user.samaccountname
enabled = $user.Enabled
distinguishedname = $user.distinguishedname
directreportupn = $directreportsupn
directteportsamaccountname = $directreportssamaccountname
}
}
Skipster311-1 Changed the code a little bit, could you verify and let me know if this is what you want?