Create Lync-enabled Active Directory users in bulk with PowerShell!
This blog post explores how to create Lync-enabled users in Active Directory in bulk using PowerShell. This is a general outline for creating a bunch of generic accounts in Active Directory and then configuring them to be able to sign on to Skype for Business. This is tested against Skype for Business server 2015. The use case here is how to create a bunch of accounts for load testing.
The accounts will look as follows:
Windows logon (username): TestUser01
First name: Test
Last name: User 01
Display name: Test User 01
Email: TestUser01@acme.com
Password: default_password01!
This pattern will be used to create 1000 test user accounts.
The accounts will look as follows:
Windows logon (username): TestUser01
First name: Test
Last name: User 01
Display name: Test User 01
Email: TestUser01@acme.com
Password: default_password01!
This pattern will be used to create 1000 test user accounts.
Step 1: Create users in Active Directory
This script uses the ActiveDirectory PowerShell module. The variables startIndex and endIndex can be modified to create different ranges of users, for example if you need 25 more users at some point, you could change the startIndex to 1001 and the endIndex to 1025.
Import-Module ActiveDirectory
$startIndex = 1;
$endIndex = 1000;
$totalusers = $endIndex - $startIndex + 1
Write-Host "Starting"
for ($i=$startIndex; $i -le $endIndex ; $i++)
{
$userID = "{0:00}" -f ($i)
$userName = "TestUser$userID"
$givenName = "Test"
$surname = "User $userID"
$displayName = "$givenName $surname"
Write-Host "Creating AD user" ($i) "of" $totalusers ":" $userName
New-ADUser `
-Name $userName `
-Path "OU=MyFooBar,DC=Acme,DC=com" `
-EmailAddress ("$userName@acme.com")`
-SamAccountName $userName `
-GivenName $givenName `
-Surname $surname `
-DisplayName $displayName `
-AccountPassword (ConvertTo-SecureString "default_password01!" -AsPlainText -Force) `
-Enabled $true
}
Write-Host "Done"
Step 2: Enable users in Skype for Business 2015
This script uses the pattern we know that our test users are created from to identify users by their display name and enable them in Lync.
$lyncServer = "myLync1.acme.com"
$domain = "acme.com";
$startIndex = 1;
$endIndex = 1000;
$totalusers = $endIndex - $startIndex + 1
Write-Host "Starting"
for ($i=$startIndex; $i -le $endIndex ; $i++)
{
$userID = "{0:00}" -f ($i)
$userName = "TestUser$userID"
$givenName = "Test"
$surname = "User $userID"
$displayName = "$givenName $surname"
Write-Host "Enabling AD user for Lync " ($i) "of" $totalusers ":" $userName
Enable-CsUser -Identity $displayName -RegistrarPool $lyncServer -SipAddressType SamAccountName -SipDomain $domain
}
Write-Host "Done"