When you test SharePoint or any other products that use Active Directory, it is very important to use large amounts of data that are close to real. For example, if you have 10 or 20 test users in Active Directory, and perhaps 50 or 100 with names like Test 1, Test 2, etc., this is clearly not enough.
Consider how to fill Active Directory with a large (over 9000) amount of data as close to reality as possible.
Get the data
To generate user data, we use the
Fake Name Generator service . This wonderful service has the ability to generate up to
50,000 users at a time . In this case, you can select the country and user properties included in the export file.
')
Selecting all the properties, you will receive a file with all the data by e-mail.
Import data
Consider importing data from a previously obtained CSV file using PowerShell. We will slightly modify the source data, and then create accounts in Active Directory based on them.
First, create an OU (“Demo Users”), where we will place all new users and set a policy for passwords
Import-Module ActiveDirectory $dn = (Get-ADDomain).DistinguishedName $forest = (Get-ADDomain).Forest Set-ADDefaultDomainPasswordPolicy $forest -ComplexityEnabled $false -MaxPasswordAge "1000" -PasswordHistoryCount 0 -MinPasswordAge 0 $ou = Get-ADOrganizationalUnit -Filter 'name -eq "Demo Users"' if ($ou -eq $null) { New-ADOrganizationalUnit -Name "Demo Users" -Path $dn $ou = Get-ADOrganizationalUnit -Filter 'name -eq "Demo Users"' }
Import CSV file to PowerShell
$data = Import-Csv .\<__>.csv
We will now place our data in a new PowerShell object. Please note that this object uses the parameter names of the
New-ADUser cmdlet , so if you want to add attributes to your accounts, you need to do it here.
$refineddata = $data | select @{Name="Name";Expression={$_.Surname + ", " + $_.GivenName}},` @{Name="SamAccountName"; Expression={$_.Username}},` @{Name="UserPrincipalName"; Expression={$_.Username +"@" + $forest}},` @{Name="GivenName"; Expression={$_.GivenName}},` @{Name="Surname"; Expression={$_.Surname}},` @{Name="DisplayName"; Expression={$_.Surname + ", " + $_.GivenName}},` @{Name="City"; Expression={$_.City}},` @{Name="StreetAddress"; Expression={$_.StreetAddress}},` @{Name="State"; Expression={$_.State}},` @{Name="Country"; Expression={$_.Country}},` @{Name="PostalCode"; Expression={$_.ZipCode}},` @{Name="EmailAddress"; Expression={$_.EmailAddress}},` @{Name="AccountPassword"; Expression={ (Convertto-SecureString -Force -AsPlainText "WictorRocks!")}},` @{Name="OfficePhone"; Expression={$_.TelephoneNumber}},` @{Name="Title"; Expression={$_.Occupation}},` @{Name="Enabled"; Expression={$true}},` @{Name="PasswordNeverExpires"; Expression={$true}}
Notice that the Name and DisplayName properties are corrected in the above script, and the DNS name of the forest is used in the UPN. In addition, all users are active.
Time to add users to Active Directory! But we will not add them to the OU that we created earlier. Instead, create an OU for user countries. This allows you to better manage test data and test work in different OUs.
$refineddata | % { $subou = Get-ADOrganizationalUnit -Filter "name -eq ""$($_.Country)""" -SearchBase $ou.DistinguishedName if($subou -eq $null) { New-ADOrganizationalUnit -Name $_.Country -Path $ou.DistinguishedName $subou = Get-ADOrganizationalUnit -Filter "name -eq ""$($_.Country)""" -SearchBase $ou.DistinguishedName } $_ | Select @{Name="Path"; Expression={$subou.DistinguishedName}},* | New-ADUser }
If you have any errors during the creation of users, most likely they are related to the fact that some of them have the same usernames.
Result
Log into the Active Directory management console and see what you got.
If you choose any OU, you will see there are a lot of users there.
This will fill the user profile.
Conclusion
You looked at how quickly and simply you can fill your Active Directory directory for test scripts.
It is important that in the case of SharePoint it may be costly to create an unnecessarily large number of accounts due to the cost of synchronizing and indexing them.