Welcome › Forums › General PowerShell Q&A › How to get-adcomputer
- This topic has 22 replies, 6 voices, and was last updated 11 months ago by
Participant.
-
AuthorPosts
-
-
February 19, 2020 at 1:25 pm #204549
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.
-
February 19, 2020 at 2:01 pm #204555
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?
-
February 19, 2020 at 5:12 pm #204639
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
-
February 19, 2020 at 8:15 pm #204681
Well, 700k records is a lot of computer objects. Are you using a filter to only return what you need?
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
-
February 19, 2020 at 11:07 pm #204783
-
February 19, 2020 at 11:43 pm #204789
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
-
February 19, 2020 at 11:46 pm #204792
Hi rob.
Ill check on the links.thanks
-
February 20, 2020 at 12:38 am #204801
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*
"'}).TotalSecondsWhich returned 151.2605417 which is 2.5 minutes. So you may be in luck.
-
This reply was modified 11 months, 1 week ago by
TonyD.
-
This reply was modified 11 months, 1 week ago by
-
February 20, 2020 at 2:50 am #204813
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.
-
February 20, 2020 at 1:43 pm #204879
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.
-
February 20, 2020 at 2:55 pm #204897
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.
-
February 20, 2020 at 3:40 pm #204909
Maybe you can filter on names starting with ‘a’, then names starting with ‘b’, etc?
-
February 20, 2020 at 5:17 pm #204945
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 11 months, 1 week ago by
TonyD.
-
This reply was modified 11 months, 1 week ago by
-
February 20, 2020 at 6:23 pm #204969
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.
PowerShell12$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…
PowerShell1| where-object {$_.OperatingSystem -like "Windows Server 2019*"}-
This reply was modified 11 months, 1 week ago by
p42p0wd3r.
-
This reply was modified 11 months, 1 week ago by
-
February 21, 2020 at 2:24 am #205059
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.
-
February 24, 2020 at 4:46 pm #205746
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.
-
February 24, 2020 at 9:07 pm #205809
-
February 25, 2020 at 2:10 pm #205935
Js i dont nave list of computer.
I just run the command and export to csb file.
Thanks
-
February 25, 2020 at 2:13 pm #205938
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
-
February 25, 2020 at 4:28 pm #206028
Did you try using Invoke-Command ???
-
February 25, 2020 at 9:41 pm #206085
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 '*' |<br />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.
-
February 27, 2020 at 12:42 am #206388
I tried that invoke command but it’s not working:(
-
February 27, 2020 at 12:48 am #206391
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 🙁
-
-
AuthorPosts
- The topic ‘How to get-adcomputer’ is closed to new replies.