7,023 questions
in powershell
# Import the Active Directory module
Import-Module ActiveDirectory
# Specify the distinguished name of the OU (Organizational Unit) where your computers are located
$ou = "OU=Computers,DC=yourdomain,DC=com"
# Get a list of computers with the "Managed By" attribute
$computers = Get-ADComputer -Filter * -SearchBase $ou -Properties ManagedBy | Where-Object { $_.ManagedBy }
# Display the computer names and their corresponding "Managed By" users
foreach ($computer in $computers) {
$computerName = $computer.Name
$managedBy = Get-ADUser -Identity $computer.ManagedBy
$managedByName = $managedBy.Name
Write-Output "Computer: $computerName - Managed By: $managedByName"
}