'PS Script to search all OU for "Servers" and move them to the "Servers" OU

Currently my AD has about 20 or so Computer OUs across the various depts within my organization. These Computer OUs contain both Servers and Workstations I would like a script that will search the entire AD domain to find any servers and then move them to the new "Servers" OU. We are working on some new tooling and need the servers to be in their own OU separate from workstations.



Solution 1:[1]

You can try to filter by OperatingSystem

Get-ADComputer -Filter "OperatingSystem -like '*server*'" -SearchBase "CN=Computers,DC=mydomain,DC=local" |
Move-ADObject -TargetPath "OU=Servers,DC=mydomain,DC=local"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexander Aschin