PowerShell script to create Exchange Mailboxes for users in an OU structure.
For full instructions and documentation, visit my blog post
Auto Create Exchange Mailboxes can also be downloaded from:
Please consider supporting my work:
- Support with Github Sponsors.
- Support with a one-time donation using PayPal.
Please report any problems via the ‘issues’ tab on GitHub.
-Mike
- The script will run the WSUS server clean-up process, which will delete obsolete updates, as well as declining expired and superseded updates.
- The script can optionally create a log file and e-mail the log file to an address of your choice.
- The script can be run locally on a WSUS server, or on a remote sever.
- The script requires that the WSUS management tools be installed.
- The script has been tested on Windows 10 and Windows Server 2016.
The password used for SMTP server authentication must be in an encrypted text file. To generate the password file, run the following command in PowerShell, on the computer that is going to run the script and logged in with the user that will be running the script. When you run the command you will be prompted for a username and password. Enter the username and password you want to use to authenticate to your SMTP server.
Please note: This is only required if you need to authenticate to the SMTP server when send the log via e-mail.
$creds = Get-Credential
$creds.Password | ConvertFrom-SecureString | Set-Content c:\scripts\ps-script-pwd.txtAfter running the commands, you will have a text file containing the encrypted password. When configuring the -Pwd switch enter the path and file name of this file.
Here’s a list of all the command line switches and example configurations.
-OUThe AD Organisational Unit (including child OUs) that contains the users to create Exchange Mailboxes for.
-DatabThe Exchange database to create the mailboxes in. If you do not configure a Database, the smallest database will be used.
-RPThe retention policy that should be applied to the users.
-CompatUse this switch if you are using Exchange 2010.
-LThe path to output the log file to. The file name will be "Create-Mailboxes.log"
-SubjectThe email subject that the email should have. Encapsulate with single or double quotes.
-SendToThe e-mail address the log should be sent to.
-FromThe from address the log should be sent from.
-SmtpThe DNS name or IP address of the SMTP server.
-UserThe user account to connect to the SMTP server.
-PwdThe txt file containing the encrypted password for the user account.
-UseSslConnect to the SMTP server using SSL.
Create-Mailboxes.ps1 -Ou "OU=NewUsers,OU=Dept,DC=contoso,DC=com" -Datab "Mail DB 2" -Rp "1-Month-Deleted-Items" -L C:\scripts\logs -Subject 'Server: Created Mailboxes' -Sendto me@contoso.com -From Exch01@contoso.com -Smtp smtp-mail.outlook.com -User Exch01@contoso.com -Pwd P@ssw0rd -UseSslThis will create mailboxes for users that do not already have one in the OU NewUsers and all child OUs. It will create the mailbox using Mail DB 2 and apply the retention policy "1-Month-Deleted-Items". If you do not configure a database, the smallest database will be used. A log will be output to C:\scripts\logs and e-mailed with a custom subject line, using a secure connection.