How to get-adcomputer

Welcome Forums General PowerShell Q&A How to get-adcomputer

Viewing 22 reply threads
  • Author
    Posts
    • #204549
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      Hi Team,

      Please advise on how to get-adcomputer objects every 1000 and continue until the end of the count?

      and also outpout in csv file. like first 1000 objects will output to csv file then continue again to next 1000 and output in the same csv file.

      i dont know on how to proceed to construct the script.

      Thanks.

       

    • #204555
      Participant
      Topics: 12
      Replies: 1623
      Points: 2,565
      Helping Hand
      Rank: Community Hero

      Get-ADUser doesn’t support paging as far as I’m aware. You can specify that the web service pages 1000 records at a time using -ResultPageSize, but it will still return all records based on -ResultSetSize param. Why do you want to get AD records in this manner? I’ve gotten 50000 AD records in a couple of min, so what is the use case for this?

    • #204639
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      Hi rob.

      Thanks for your question.

      Basicaly .when i execute the get-adcomputer and filter the operating system its getting halt or hang.

      And sometimes its showing server is down or not exist.

      And im querying 700 000 computet objects.

      I just want to query every 1000 objects until to reach the last count.and i dont how to achieve.

       

      Hope you can help me with my issue on how to consttuct the script

       

       

    • #204681
      Participant
      Topics: 12
      Replies: 1623
      Points: 2,565
      Helping Hand
      Rank: Community Hero

      Well, 700k records is a lot of computer objects. Are you using a filter to only return what you need?

      https://4sysops.com/archives/search-active-directory-with-the-powershell-cmdlet-get%E2%80%91adcomputer/

      There are timeouts, typically 2 minutes to get results in a recordset:

      https://www.randomizedharmony.com/blog/2018/10/7/get-aduser-times-out-after-2-minutes

    • #204783
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

      Boy howdy, that is a LOT of computers.

      • This reply was modified 3 months, 2 weeks ago by TonyD05.
    • #204789
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      Hi tony.

      Yes its very huge computer objects.and that is the peoblem. And my plan is to get every 1000 objects.i just dont know on how to achieve

    • #204792
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      Hi rob.

      Ill check on the links.thanks

    • #204801
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

      Well, I did a query using:

      Get-ADComputer -Filter 'OperatingSystem -like "*windows*"'

      Which returned 161K objects.

      I also ran

      Get-ADComputer -Filter 'OperatingSystem -like "*server*"'

      Which returned 29K objects. Have you tried anything yet? I don’t believe in either case a limit was exhausted, at least I did not get any errors.

      Rob points out there is a 2 minute limit to Get-Aduser, assuming that also applies to Get-ADComputer, I ran the following as a test of the time it took

      (Measure-Command -Expression{$winSystems = Get-ADComputer -Filter 'OperatingSystem -like "*windows*
      "'}).TotalSeconds

      Which returned 151.2605417 which is 2.5 minutes. So you may be in luck.

       

      • This reply was modified 3 months, 2 weeks ago by TonyD05.
    • #204813
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      Hi rob.

      I try the commammd that you provide but error occur.

       

      Server does not exist.i done know why.

      Server is reachable and pingable.

       

    • #204879
      Participant
      Topics: 12
      Replies: 1623
      Points: 2,565
      Helping Hand
      Rank: Community Hero

      Can you get any results from Get-ADComputer? If you search for a specific computer, does it work? You are saying to tried the commands? Which commands? What is working? What specifically is not working? Please provide examples of the code you are trying and the exact error.

    • #204897
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      Get-ADComputer -server test.domain -Filter ‘OperatingSystem -like “*windows*”‘

      That is the command i used.

      The result show 5k computer objrcts only then after awhile it was error showing unable to connect.

       

      And i just notice its takes an hour to get the 5k objects.

    • #204909
      js
      Participant
      Topics: 29
      Replies: 814
      Points: 2,456
      Helping Hand
      Rank: Community Hero

      Maybe you can filter on names starting with ‘a’, then names starting with ‘b’, etc?

    • #204945
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

      Wow – an hour ?? In theory, you should not need to define the server. It should connect to whatever is defined in $ENV:LogonServer. Are you able to RDP to a Domain Controller and try the commands from there?

      It seems like you may have underlying network performance issues. How did you determine the 5K count?

      • This reply was modified 3 months, 1 week ago by TonyD05.
    • #204969
      Participant
      Topics: 1
      Replies: 20
      Points: 109
      Helping Hand
      Rank: Participant

      With so many, batching it up is probably a good approach.  This might help you figure out a good filter, this is getting the info you want starting at a specific organizational unit.  From here, you could run it against each of larger containers individually, automate it, or whatever your intent is.

      $Things = "Name","OperatingSystem","PasswordLastSet","Enabled","DistinguishedName"
      (Get-ADOrganizationalUnit -Filter "DistinguishedName -like '*DC=contoso,DC=com'").DistinguishedName | % {Get-ADComputer -F * -Properties $Things | select $Things | Export-Csv C:\Temp\Stuff.csv -Append -NoClobber}

      For my test directory, about 2k objects were returned in a 256k CSV file in less than 2 seconds.  I also set the filters to include the operating system.  If you wanted to only look for a specific OS, you could do that with something like this before the select-object bits…

      | where-object {$_.OperatingSystem -like "Windows Server 2019*"}

       

      • This reply was modified 3 months, 1 week ago by p42p0wd3r.
    • #205059
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      Hi tony

      I dont have right to rdp the machine.

      Or no interactive access to log in.

      But im able to query the AD remotely.

      Basicaly i query 8 domains controllers

      Only one domain with huge computer objects that i having issue and the 7 domain are succesaful to query.

    • #205746
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

      Do you have enough privilege to try Invoke-Command ?

      Something like:

      Invoke-Command -ComputerName 'slowserver' -ScriptBlock {Get-ADComputer -Filter 'OperatingSystem -like "*windows*"'}

      In theory, this should run on the server in question, although 700K objects is a huge amount. I still think you may have underlying network issues. I would try these commands from a shell on a few servers and compare them to the slow server.

      ‘ping server’

      ‘tracert server’

      For the first command, make a note of ‘time=xxx’ and compare amongst servers

      For the second command, make a note of the number of hops. The more hops, the more latency, the slower things are.

    • #205809
      js
      Participant
      Topics: 29
      Replies: 814
      Points: 2,456
      Helping Hand
      Rank: Community Hero

      If you have a list of the computers, there’s various ways to run them a piece at a time.

      • This reply was modified 3 months, 1 week ago by js.
    • #205935
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      Js i dont nave list of computer.

      I just run the command and export to csb file.

      Thanks

    • #205938
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      What if using adsi ldap.

      Is that possible?

      Im not yet familiar with ldap adsi

      Can you give me on how to start using ldap instead of .net

      Thanks

    • #206028
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

      Did you try using Invoke-Command ???

    • #206085
      Participant
      Topics: 2
      Replies: 1013
      Points: 2,093
      Helping Hand
      Rank: Community Hero

      AS all are pointing out, you cannot do this paging-like thing with that cmdlet.

      Agreed with others, 700K AD objects is a lot, but that does not really translate into 700K domain-joined computers.  I’ve worked with a lot over very large orgs, and the only one I’ve come in contact with that has that kind of housing of computers, is the DoD, and even those are not in the same forest/domain.

      My simplified suggestion is to first to a general Get-ADComputer and pull back only specific properties, like, Name, Created, OperatingSystem, IPv4Address, for example.

      Get-ADComputer -Identity '*' |
      Select Name, Created, OperatingSystem, IPv4Address

      Take that sample, and use an IPA range to pull back the count you are after, then do the next IPA range.

    • #206388
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      I tried that invoke  command but it’s not working:(

    • #206391
      Participant
      Topics: 1
      Replies: 10
      Points: 17
      Rank: Member

      I used ldapfilter the operating system only.basically I’m querying 9 domains and 8 domains are successful  but with huge objects are not.  I do research about the adsi ldap query because it is not using a .net. and it is my first time to used adsi ldapquery and I don’t know how to get start  🙁

Viewing 22 reply threads
  • The topic ‘How to get-adcomputer’ is closed to new replies.