PowerShell Version 2 script to ensure all users in specified organizational units are also members of a corresponding shadow group. Also makes sure users not in the OU's are not members of the group. A Fine Grained Password Policy can be applied to the group.
Shadow Groups are dynamic groups that include all users in a specified Organizational Unit, but no other users. In this way they shadow the OU. Because fine-Grained Password Policies can only be applied to users and groups, this is the best way to apply a FGPP to all users in an Organizational Unit. This script has been modified to allow you to shadow more than one OU.
There is no automatic mechanism in Active Directory to keep the shadow group membership up to date. A script must be run periodically to update the membership. The script must remove any members of the group that are no longer in the OU (or OU's), and add any users in the OU (or OU's) that are not in the group. This PowerShell Version 2 script is designed to accomplish this task.
A few other scripts have been found for the same purpose, but they have some shortcomings. This script has the following features.
The script exits with an error message under the following conditions.
To run the script in your environment for your purpose, you must assign values to the following variables in the configuration section of the script.
Variable | Description |
$Server | The DNS host name of a domain controller that supports the PowerShell AD modules. |
$LogFile | The path and name of a log file. If it does not exist it will be created. |
$Update | $False means the script only reports what it would do. $True means the script updates the group. |
$EnabledOnly | $True means the script only considers enabled users. $False means it considers all users. |
$OUDN | An array of the distinguished names of the organizational units. |
$GroupDN | The distinguished name of the corresponding shadow group. The group must exist, but it can be empty. |
ShadowGroup.txt <<-- Click here to view or download the program