Share via


Update to the Create-LabUsers tool

While working on my last mini-series, I utilized my Create-LabUsers tool to automate the creation of a few thousand objects.  When I was synchronizing my AD users to another directory, I noticed that I didn't have mailNickname populated and had to add a quick script to fill that value in.  I decided to populate it as a default value using sAMAccountName (which is what Exchange does anyway when you mailbox-enable someone).  This will be helpful if you're trying to emulate users and groups with more messaging values filled out.

I also fixed the CreateGroups parameter. It erroneously checked for an Exchange server session during AD group creation.

And, it wouldn't be an update if I didn't add a new parameter:

THEWHOLESHEBANG

Yes, it's just like it sounds.  Use this parameter with -ExchangeServer and you'll automatically create 10,000 user mailboxes, oodles of resource mailboxes, configure all the nested security memberships you can shake a USB stick at, assign manager / direct report relationships, and inflate mailboxes like a boss (NSFW). The only thing it really doesn't do is send some faxes.

From a user comment in the gallery where I host the tool, I received a request to allow user input so you can supply your own list of names.

IT IS NOW SO.  Just use the UserList parameter, and submit a CSV with Firstname,MiddleName,LastName columns so labelled.  If you enter a value for Count that exceeds the number of users in the UserList, the script will fill in the difference with the already included seed data.

WOOT.

I also added a method of detecting an Exchange server:

 function LocateExchange
{
    If (!$ExchangeServer)
    {
        Write-Log -ConsoleOutput -LogFile $Logfile -LogLevel WARN -Message "No Exchange sever specified. Attempting to locate Exchange Servers registered in configuration container."
        [array]$ExchangeServers = (Get-ADObject -Filter { objectCategory -eq "msExchExchangeServer" } -SearchBase (Get-ADRootDSE).configurationNamingContext).Name
        If ($ExchangeServers)
        {
            $SuccessfulTest = @()
            Write-Log -ConsoleOutput -LogFile $Logfile -LogLevel INFO -Message "Found $($ExchangeServers.Count) Exchange servers registered in configuration partition. Selecting a server."
            ForEach ($obj in $ExchangeServers)
            {
                $Result = Try { Test-NetConnection $obj -ea stop -wa silentlycontinue -Port 443 }
                catch { $Result = "FAIL" }
                If ($Result.TcpTestSucceeded -eq $True) { $SuccessfulTest += $obj }
            }
            If ($SuccessfulTest -ge 1)
            {
                $ExchangeSever = (Get-Random $SuccessfulTest)
                Write-Log -Logfile $Logfile -LogLevel SUCCESS -Message "Selected Exchange Server $($ExchangeServer)."
            }
            Else
            {
                Write-Log -LogFile $Logfile -LogLevel ERROR -Message "Cannot locate or connect to an Exchange server. ExchangeServer parameter must be specified if CreateMailboxes parameter is used. Error Code: EXERR01" -ConsoleOutput
                Break
            }
        }
    }
    Else
    {
        Write-Log -ConsoleOutput -LogFile $LogFile -LogLevel ERROR -Message "Cannot locate or connect to an Exchange Server.  ExchangeServer parameter must be specified if CreateMailboxes parameter is used. Error Code: EXERR02"
        Break
    }
}

You can get the updated version at https://aka.ms/createlabusers.