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?
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
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.
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?
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.
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*"}
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.