Have you already seen and tried this approach…
‘bogs.msmvps.com/richardsiddaway/2017/11/27/get-an-ad-users-manager’
Many of the default or extended properties for AD object are empty. They have to be manually populated by an administrators or by some other process / service. If this was not done, nothing will be returned.
To see all AD properties and their values on a user or computer object, of course, just do this.
(Get-ADComputer -Filter * -Properties *)[0]
(Get-ADUser -Filter * -Properties *)[0]
Get all empty AD properties of the object, this is a bit ugly but gets the needed empty fields.
Computer object property collection
Clear-Host;(Get-ADComputer -Filter * -Properties *)[0] > “$PWD\ADComputerProps.txt”
Clear-Host;(Get-ADUser -Filter * -Properties *)[0] > “$PWD\ADUserProps.txt”
Clear-Host;$RegEx = ‘: .’
Select-String -Path “$PWD\ADComputerProps.txt” -NotMatch $RegEx
Select-String -Path “$PWD\ADUserProps.txt” -NotMatch $RegEx
Computer
…
ADCOmputerProps.txt:3:AccountExpirationDate :
ADCOmputerProps.txt:5:AccountLockoutTime :
ADCOmputerProps.txt:22:Deleted :
ADCOmputerProps.txt:23:Description :
ADCOmputerProps.txt:24:DisplayName :
ADCOmputerProps.txt:31:HomePage :
ADCOmputerProps.txt:34:IPv6Address :
ADCOmputerProps.txt:36:isDeleted :
ADCOmputerProps.txt:38:LastBadPasswordAttempt :
ADCOmputerProps.txt:39:LastKnownParent :
ADCOmputerProps.txt:45:Location :
ADCOmputerProps.txt:48:ManagedBy :
ADCOmputerProps.txt:63:OperatingSystemHotfix :
ADCOmputerProps.txt:64:OperatingSystemServicePack :
…
ADCOmputerProps.txt:128:UserPrincipalName :
User
…
ADUserProps.txt:3:AccountExpirationDate :
ADUserProps.txt:5:AccountLockoutTime :
ADUserProps.txt:17:City :
ADUserProps.txt:20:Company :
ADUserProps.txt:22:Country :
ADUserProps.txt:26:Deleted :
ADUserProps.txt:27:Department :
ADUserProps.txt:31:Division :
ADUserProps.txt:35:EmployeeID :
ADUserProps.txt:36:EmployeeNumber :
ADUserProps.txt:38:Fax :
ADUserProps.txt:39:GivenName :
ADUserProps.txt:40:HomeDirectory :
ADUserProps.txt:42:HomeDrive :
…
ADUserProps.txt:45:HomePage :
ADUserProps.txt:46:HomePhone :
ADUserProps.txt:47:Initials :
ADUserProps.txt:50:isDeleted :
ADUserProps.txt:53:LastKnownParent :
ADUserProps.txt:62:LogonWorkstations :
ADUserProps.txt:66:Manager :
…
ADUserProps.txt:103:Office :
ADUserProps.txt:104:OfficePhone :
ADUserProps.txt:105:Organization :
ADUserProps.txt:106:OtherName :
ADUserProps.txt:111:POBox :
ADUserProps.txt:112:PostalCode :
ADUserProps.txt:116:ProfilePath :
ADUserProps.txt:123:ScriptPath :
…
ADUserProps.txt:135:State :
ADUserProps.txt:136:StreetAddress :
ADUserProps.txt:137:Surname :
ADUserProps.txt:138:Title :
…
Anyway, if you follow the approach of the link above, you could do something like this…
(Get-ADComputer -Filter * -Property *) `
| ForEach ($) {
If ($.ManagedBy)
{
$User = (Get-ADUser -Identity $.ManagedBy)
$User | Add-Member -MemberType NoteProperty -Name ‘ManagedBy’ -Value $.ManagedBy -Force
$User | Select Name, SamAccountName, UserPrincipalName,ManagedBy
}
}
Name SamAccountName UserPrincipalName ManagedBy
User01 TestUser User01 User01@contoso.com CN=HelpDesk Manager,OU=…
User02 TestUser User02 User02@contoso.com CN=HelpDesk Manager,OU=LabUsers,DC=…