Sunday, 18 July 2010

Recipient Bulk Management Tasks

You can create new mailboxes using the New-Mailbox cmdlet as described earlier in this post. Sometimes,  you may be asked to create a large number of user mailboxes based on a comma - separated value spreadsheet.
Fortunately, the Import-CSV cmdlet is helpful here. In this case you can easily import the CSV file and use the New-Mailbox cmdlet to quickly create the mailboxes.
The spreadsheet could look something like the following:
The spreadsheet provides minimal information (and needs to saved as a .CSV file).
To see the CSV file in powershell, simply type the following command:
[PS] Import-CSV c:\book3.csv | ft –au
To create new-mailboxes from this file try using the following cmdlet in powershell:
First you create a password variable
[PS] $Password = Read-Host “Enter a Password” –AsSecureString
Then, you can import the CSV file, loop through the file and create new mailboxes. Notice in the script below, that we can add the the new users to a specific organisational unit and we use the password variable to provide the needed passwords.
[PS] Import-Csv .\Book3.csv | foreach { New-Mailbox -Name $_.Name -FirstName $_.FirstName -LastName $_.LastName -Alias $_.Name -UserPrincipalName "$" -OrganizationalUnit Staff -Password $Password -Database "EX1\store2\db01" -ResetPasswordOnNextLogon $true }
As the above script does not include –Department, your new mailboxes will not be assigned relevant departments. Lets say you need to now include the department for these users. You can once again refer to your CSV file.
If you type the following cmdlet, you will see that the sales group is empty
The following command will set a department property for each user defined in the CSV file.
[PS] C:\>Import-Csv .\Book3.csv | foreach {Set-User -Identity $ -Department $_.Department}
The following result will be displayed

No comments:

Post a Comment