locked
Search AD for computers with 2 naming conventions RRS feed

  • Question

  • How do I get all computers in AD that have values SNO or HAR?

    Get-ADComputer -Filter * | Where-Object Name -like "*SNO*","*HAR*"| Select -Property Name|Export-Csv "C:\PSscripts\ou.txt"

    Thursday, January 11, 2018 6:02 PM

Answers

  • This is faster and easier:

     Get-ADComputer -Filter "Name -like '*SNO*' -or Name -like '*HAR*'"


    \_(ツ)_/

    • Proposed as answer by jrv Thursday, January 11, 2018 6:23 PM
    • Marked as answer by Richard MuellerMVP Saturday, February 17, 2018 4:11 PM
    Thursday, January 11, 2018 6:23 PM

All replies

  • Hello,

    Get-ADComputer -Filter * | Where-Object {$_.Name -like "*SNO*" -OR $_.Name -like "*HAR*"} | Select -Property Name|Export-Csv "C:\PSscripts\ou.txt"

    • Proposed as answer by Romain Wager Thursday, January 11, 2018 6:19 PM
    Thursday, January 11, 2018 6:19 PM
  • This is faster and easier:

     Get-ADComputer -Filter "Name -like '*SNO*' -or Name -like '*HAR*'"


    \_(ツ)_/

    • Proposed as answer by jrv Thursday, January 11, 2018 6:23 PM
    • Marked as answer by Richard MuellerMVP Saturday, February 17, 2018 4:11 PM
    Thursday, January 11, 2018 6:23 PM
  • Also:


    Get-ADComputer -LDAPFilter "(|(name=*SNO*)(name=*HAR*))"


    -- Bill Stewart [Bill_Stewart]

    Thursday, January 11, 2018 6:33 PM
  • +1 for jrv

    We can also pass property inside Get-ADComputer, final result:

    Get-ADComputer -Filter "Name -like '*SNO*' -or Name -like '*HAR*'" -Property Name | Export-CSV "C:\PSscripts\ou.txt"
    Thursday, January 11, 2018 6:37 PM
  • +1 for jrv

    We can also pass property inside Get-ADComputer, final result:

    Get-ADComputer -Filter "Name -like '*SNO*' -or Name -like '*HAR*'" -Property Name | Export-CSV "C:\PSscripts\ou.txt"

    Don't look now  but "Name" is already a default property and never needs to be specified.


    \_(ツ)_/

    Thursday, January 11, 2018 6:39 PM
  • Oh really ? this command doesn't mean that only the property Name is selected and will be output in the CSV? I thought it was...


    Then we should use that: ?

    (Get-ADComputer -Filter "Name -like '*SNO*' -or Name -like '*HAR*'").Name | Export-CSV "C:\PSscripts\ou.txt

    Thursday, January 11, 2018 6:41 PM
  • Oh really ? this command doesn't mean that only the property Name is selected and will be output in the CSV? I thought it was...

    No.   It is used to add properties that are not in the default set.

    Get-ADComputer -Filter "Name -like '*SNO*' -or Name -like '*HAR*'" |
         Select-Object Name |
         Export-Csv C:\PSscripts\ou.txt


    \_(ツ)_/

    • Proposed as answer by Romain Wager Thursday, January 11, 2018 6:45 PM
    Thursday, January 11, 2018 6:44 PM
  • Thanks for the help, it works most of the time but I keep getting a timeout error on one network, "The operation returned because the timeout limit was exceeded".  Any suggestions?
    Wednesday, February 28, 2018 5:54 PM
  • We cannot help you with network problems.  Contact your net admins for assistance.

    THe query governor in AD may be exceeded by a large size AD and a busy call. 

    You can try:

    Get-ADComputer -Filter "Name -like '*SNO*' -or Name -like '*HAR*'"  -ResultSetSize 256

    OR

    Get-ADComputer -Filter "Name -like '*SNO*' -or Name -like '*HAR*'"  -ResultPageSize 256


    \_(ツ)_/

    Wednesday, February 28, 2018 6:11 PM