Powershell Get all Computers with a value in managedby

otip 21 Reputation points
2021-11-25T14:44:26.987+00:00

Hello community,

I'm trying to get the least of computer objects from my AD where there is a value in the managed by field (not the ones with empty value)

I tried different approaches such as :

Get-ADComputer -filter 'managedby -eq "*"' -properties * | select-object name, managedby

and

get-adcomputer -filter * -properties Name, managedBy | where {$_.managedby -like '*'} | select-object name, managedby 

=> this gives me all computers object even with manage by empty. -notlike * give nothing.

I tried different ways with -contains -like -notlike -ne etc but couldn't make it work.

Any help would be appreciated.

Thank you

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Gary Reynolds 9,621 Reputation points
    2021-11-25T19:52:53.097+00:00

    Hi @otip

    Or this version, which does the filtering server side so will be significantly faster.

     get-adcomputer -ldapfilter '(managedby=*)' -properties name, managedby | select-object name, managedby  
    

    Gary.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Leon Laude 86,026 Reputation points
    2021-11-25T15:00:06.8+00:00

    Hi @otip ,

    The following worked for me when I tried:

    Get-ADComputer -Filter * -Properties name, managedBy | Where {$_.managedby -ne $null} | Select-Object name, managedby

    ----------

    If the reply was helpful please don't forget to upvote and/or accept as answer, thank you!

    Best regards,
    Leon


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.