There are tons of Powershell scripts available over internet for creating accounts, I thought of writing my own article on this.
Nothing is changed much in this script.
Our goal is to have approximately 10 users in a given OU. Here is an OU named ISATown and will host 10 users.
Let me breakdown the script itself before we start writing it.
We will be using “New-Mailbox” Cmd-let to achieve our goal.
The parameters that’s required are
-Name: The name of the mailbox
-Database: In which mailbox database we want to create the mailbox
-Password: This parameter will take its value from a variable that we will define before we run the script.
-UserPrincipalName: The FQDN of user
-Alias: as it says by itself.
-Displayname: Yes, you are right.
-FirstName:
-LastName:
-SAMAccountName:
-OrganizationalUnit: the name of OU where we want to create users.
Lets define a variable to store password
$password = Read-Host “Enter Password” –AsSecureString
This will prompt us for password.
Now we will use Counter and ForEach Loop.
In the counter part we will specify the number of users we want to create, and will pipe it counter to ForEach Loop
1..10 | ForEach-Object
In ForEach-Object we will write the New-Mailbox script which will create mailbox user accounts.
1..10 | ForEach-Object { New-Mailbox -Name BH$_ -Database MBDB02 -Password $password -UserPrincipalName BH$_@msexchange.in -Alias BH$_ -DisplayName BH$_ -FirstName BH -LastName User$_ -SamAccountName BH$_ -OrganizationalUnit ISATown }
The $_ is the current value in the pipeline.