One common function in Active Directory is to create groups based on OUs. This post will provide a PowerShell script at the end that you can schedule that will do this rollup for you. It will also remove any objects from the group that are no longer present.
System Requirements and Assumptions
This script requires at least PowerShell 3.0 and the Active Directory PowerShell module.
This script assumes that you will have one rollup group per OU structure, and that the group exists at the top-level OU. This script will grab all computer objects from all child OU’s and add them to the rollup group.
Another assumption is that your rollup groups have a common naming scheme. If I need a rollup group for the accounting and sales departments, they should have a common scheme, such as Accounting_Comps and Sales_Comps. The script uses the common scheme (_Comps) to determine which group to add the computers too. There should also only be one group per top-level OU that uses that particular scheme.
Finally, the account that executes the script must have the correct permissions to add computers to the rollup groups.
Setup
The script is fairly easy to setup. In line 4, which begins with “$OUs”, type in the OU’s that need to be rolled up, separating them with a semi-colon (“;”). You can specify as many OU’s as you want here and script will take care of them all.
Next, in line 13 (begins with “$group =”), change the filter to your common naming scheme. Currently, the part that you want to change reads “*_Comps”. The “*” is the wildcard, so make sure to leave that. If your naming scheme occurs in the middle of the group name, and another wildcard at the end. Here’s a screenshot of what you need to change:
After that, the script should be ready. You can download the script at the bottom of the page.
Disclaimer
All content provided on this blog is for information purposes only. Windows Management Experts, Inc makes no representation as to accuracy or completeness of any information on this site. Windows Management Experts, Inc will not be liable for any errors or omission in this information nor for the availability of this information. It is highly recommended that you consult one of our technical consultants, should you need any further assistance.
[download id=”4896″]