Friday, July 19, 2013

Randomly Selecting Computers from AD

I often have the need to grab a list of random workstations or servers to use in an audit or testing or for some other function. Here's an example of the command I use to get that list. In this case, I'm getting a list of 50 random Windows 7 workstations.

get-adcomputer -filter {operatingsystem -eq "Windows 7 Enterprise"} | get-random -count 50 | select DNSHostName

Here's the same example querying from a different domain than the one I'm currently in.

get-adcomputer -searchbase "DC=another,DC=domain,DC=com" -server another.domain.com -filter {operatingsystem -eq "Windows 7 Enterprise"} | get-random -count 50 | select DNSHostName

Even if you're querying the same domain, you may have valid reasons for using -searchbase and -server parameters to scope down your search.

No comments:

Post a Comment

One rule: Don't be a jerk.

You can correct me or other commenters all you want, just be cool about it. Of course, I mean "cool" in the nerdiest way possible.