How to create 1 million OU's and linked GPO's using PowerShell
If you find yourself with a dull moment on a Monday afternoon and feel like capacity testing your test lab with a large number of OU's and GPO's - then the following PowerShell script is for you.
Note: *Don't* run this in a production environment - this is for testing purposes only.
Sample PowerShell code:
import-module ActiveDirectory
import-module GroupPolicy
$domOUVar ="ou=MyTestOU,dc=contoso,dc=com"
for ($i=1; $i -le 1000000; $i++)
{
$nameOU = "ScalingTestOU"+$i
$nameGPO = "ScalabilitytestGPO"+$i
$nameFullDN = "OU="+$nameOU+","+$domOUVar
$domOUVarTemp = New-ADOrganizationalUnit -Name $nameOU -Path $domOUVar -ProtectedFromAccidentalDeletion $false
write-host "Linking GPO"$nameGPO" with "$nameFullDN
New-GPO -name $nameGPO
New-GPLink -name $nameGPO -target $nameFullDN -LinkEnabled Yes
}