Updating Create-LabUsers - take two

Over the past couple of days I've been tweaking and adding to this useful script.
(Previous update here: https://jc-nts.blogspot.com/2018/06/tweaks-to-create-labusers.html
Aarons blog posts can be found here: https://blogs.technet.microsoft.com/undocumentedfeatures/tag/create-labusers/
Several iterations later (and few thousand mailboxes):
  • Added functionality to enable Skype for Business
  • Split the user and mailbox creation
  • Tweaked mailbox creation to include users not previously enabled
  • Fixed an issue where the password complexity would error on user creation (that was fun!)
  • Fixed an issue where email addresses contain invalid characters
  • Shaved off a few seconds here and there
  • Included some extra logging and timings
It should reach around 1.1 million accounts per day if creating AD only, however the extra logging does add to the run times. Performance will be dependent on the specification of the DC being targeted.

This way I can fire up a DC, create 5000 users and associated groups and not have to worry about spinning up the entire test lab. When the servers are next on on, I can enable the mailboxes and for SfB.
Of course this is my preference when creating my lab - yours might be different.

For the skype functionality, I've added three command line parameters
  • -SfBEnable - Enable users for Skype for Business
  • -SfBFEServer - FQDN of a SfB front end server to powershell to
  • -SfBPool - The SfB pool FQDN that users should be enabled on

If not specified, the script will try to determine the SfB Front End server through a DNS lookup for _sipinternaltls._tcp.<domain>

Fixed:
Password complexity issue (accounts would remain locked as the password didnt match complexity requirements, history etc).
This one was a bit of a head scratcher as all the users had the same password. Clearly the password wasnt at fault. A quick check of usernames highlighted the issue - names had part of the word 'password' in them, in particular 'Word' as a surname.
Change the default password to P@ssw0rd solved the issue.

Errors setting email addresses.
Sometime an error would crop up when setting email and UPN.
Some forenames had a space in them. Removing spaces from the strings before setting fixed the issue.
        #remove spaces from samaccountname
        $sAMAccountName=$sAMAccountName.replace(' ','')
        $UPN=$sAMAccountName+'@'+$domain

Then when creating the user, use $UPN to set the email address and samaccountname e.g.
     New-ADUser -SamAccountName $sAMAccountName -Name $DisplayName -Path $OrgPath -Manager $Manager `
       -AccountPassword $SecurePassword -Enabled $true -GivenName $FirstName -Initials $MiddleInitial `
       -Surname $LastName -DisplayName $DisplayName -EmailAddress $UPN `
       -UserPrincipalName $UPN -Company $Company -Department $Department `
       -EmployeeNumber $EmployeeNumber -Title $Title -OfficePhone $OfficePhone -StreetAddress $StreetAddress `
       -City $City -PostalCode $PostalCode -State $State -Country $Country -Server $DomainController



I'd previously changed the send-mail command to speed things up (rather than a couple of seconds per email, it was now 3-4 emails per second). With attachments now in play, this needed to be expanded and disposed of once done (around line 851):
    #Send-MailMessage -To $Recipients -From $($User.PrimarySmtpAddress) -Body $Body -SmtpServer $SmtpServer -Subject $Subject -ea silentlycontinue -wa silentlycontinue -Attachments $FilePath
                $message=New-Object System.Net.Mail.MailMessage
                $message.from=$($user.PrimarySmtpAddress)
                $message.to.add($Recipients)
                $message.subject=$subject
                $attach=new-object net.mail.attachment($filepath)
                $message.attachments.add($attach)
                $message.body=$body
       $smtp=New-Object Net.Mail.SmtpClient($SmtpServer)
                $smtp.SendAsync($message,$null)
                $attach.Dispose()
                $message.Dispose()
                $smtp.dispose()
    Remove-Item -Path $FilePath -Force -ea SilentlyContinue -WA SilentlyContinue
   }
   Else
   {
    Write-Log -LogFile $Logfile -LogLevel INFO -Message "Sending message [$($UserCounter) / $($TotalMessagesToSend)] with subject $($Subject) to $($Recipients.Count) recipients"
    #Send-MailMessage -To $Recipients -From $($User.PrimarySmtpAddress) -Body $Body -SmtpServer $SmtpServer -Subject $Subject -ea silentlycontinue -wa silentlycontinue
       $smtp=New-Object Net.Mail.SmtpClient($SmtpServer)
                $smtp.SendAsync($($user.PrimarySmtpAddress),$Recipients,$Subject,$Body, $null)
                $smtp.dispose()

   }


Comments

Popular posts from this blog

Skype Online and MCOValidationError

SCCM 2012 R2 - Offline servicing error

Polycom provisioning - and Zoom!