Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating bulk multiple ex2007 Mailbox via CSV for Existing AD Accounts 1

Status
Not open for further replies.

andrewjamesb

Technical User
May 22, 2012
9
0
0
GB
Hi

I want to create around 1000+ new exchange 2007 mailboxes for existing AD user accounts. Is there a simpler way to do this?

Script to create mailboxes for users

$mailbox=import-csv C:\Users\admin-me\Desktop\mail.csv
foreach ($mailbox in $mailbox) {enable-mailbox -identity $mailbox.identity -database $mailbox.database}

The above script seems to create the mailboxes but throws up an error due to the enable-mailbox function:

The term 'enable-mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.

I also need to create another script or add to above script to set a mailbox retention policy as I have tried below

$data = import-csv C:\Users\admin-me\Desktop\180.csv
foreach ($line in $data) {set-mailbox $line.mailboxname -managedfoldermailboxpolicy 'Mailbox retention 180 days' -managedfoldermailboxpolicyallowed -confirm:$false}

Also need to create a script to prohibit email sending restrictions to 17MB per email, but allow users to receive emails

Any help on merging all above scripts would be very much appreciated. Or if I have to run three seperate scripts thats fine too for same user base

Many Thanks for reading
 
In your script, are you running it in Exchange Management Shell, or just PowerShell? It requires either EMS, or that you load the Exchange snapin in PowerShell.

You don't mention what (if any) error you're getting with the second block of code.

As for merging, just put all of the code you have in a single .ps1 file.

Code:
$mailboxes = import-csv "C:\Users\admin-me\Desktop\mail.csv"
foreach ($mailbox in $mailboxes) {
Enable-Mailbox -Identity $mailbox.identity -Database $mailbox.database
}

Remove-Variable Mailbox
Remove-Variable Mailboxes

$mailboxes = import-csv "C:\Users\admin-me\Desktop\180.csv"
foreach ($mailbox in $mailboxes) {
Set-Mailbox $mailbox.mailboxname -ManagedFolderMailboxPolicy "Mailbox retention 180 days" -ManagedFolderMailboxPolicyAllowed -Confirm:$false
}

I noticed you call the mailboxes column in the first .csv "identity", and in the second "mailboxname". Not a biggie, but I find keeping them the same makes coding and troubleshooting a little easier.

Do you have your Tek-Tips.com Swag? I've got mine!

Stop by the new Tek-Tips group at LinkedIn.
 
Hi Sniper

Thank you for your useful response. I have combined all 3 scripts into PS file as below, but getting error when I try to run it via Exchange powershell (./mail)

When you say "I noticed you call the mailboxes column in the first .csv "identity", and in the second "mailboxname". Not a biggie, but I find keeping them the same makes coding and troubleshooting a little easier." What did you mean to change here exactly?

$mailbox=import-csv C:\Users\admin-me\Desktop\mailscripts\mail.csv
foreach ($mailbox in $mailboxes) {enable-mailbox -identity $mailbox.identity -database $mailbox.database}

remove-variable mailbox
remove-variable mailboxes

$data = import-csv C:\Users\admin-me\Desktop\mailscripts\180.csv
foreach ($line in $data) {set-mailbox $line.mailboxname -managedfoldermailboxpolicy 'Mailbox retention 180 days' -managedfoldermailboxpolicyallowed -confirm:$false}

remove-variable line
remove-variable data

$data = import-csv C:\Users\admin-me\Desktop\mailscripts\180.csv
foreach ($line in $data) {set-mailbox $line.mailboxname -managedfoldermailboxpolicy 'Mailbox retention 180 days' -managedfoldermailboxpolicyallowed -confirm:$false}

Error I get when I run script

[PS] C:\Users\admin-me\Desktop\mailscripts>./mail
Enable-Mailbox : Cannot bind argument to parameter 'Identity' because it is nul
l.
At C:\Users\admin-me\Desktop\mailscripts\mail.ps1:2 char:59
+ foreach ($mailbox in $mailboxes) {enable-mailbox -identity <<<< $mailbox.ide
ntity -database $mailbox.database}
+ CategoryInfo : InvalidData: :)) [Enable-Mailbox], ParameterBind
ingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
icrosoft.Exchange.Management.RecipientTasks.EnableMailbox

Remove-Variable : Cannot find a variable with name 'mailboxes'.
At C:\Users\admin-me\Desktop\mailscripts\mail.ps1:5 char:16
+ remove-variable <<<< mailboxes
+ CategoryInfo : ObjectNotFound: (mailboxes:String) [Remove-Varia
ble], ItemNotFoundException
+ FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.R
emoveVariableCommand

WARNING: The command completed successfully but no settings of
'domain.local/domain/Accounts/user' have been modified.
WARNING: The command completed successfully but no settings of
'domain.local/domain/Accounts/user' have been modified.
[PS] C:\Users\admin-m\Deesktop\mailscripts>
 
Sorry. The script is as follows;

$mailbox=import-csv C:\Users\admin-me\Desktop\mailscripts\mail.csv
foreach ($mailbox in $mailboxes) {enable-mailbox -identity $mailbox.identity -database $mailbox.database}

remove-variable mailbox
remove-variable mailboxes

$data = import-csv C:\Users\admin-me\Desktop\mailscripts\180.csv
foreach ($line in $data) {set-mailbox $line.mailboxname -managedfoldermailboxpolicy 'Mailbox retention 180 days' -managedfoldermailboxpolicyallowed -confirm:$false}

remove-variable line
remove-variable data

$data = import-csv C:\Users\admin-me\Desktop\mailscripts\sendlimit.csv
foreach ($line in $data) {set-mailbox $line.mailboxname -prohibitsendquota 15974400 -userdatabasequotadefaults $false}

I want to limit email sending to 15MB per email per user, but still allow user to receive emails
 
$mailbox is empty when the enable-mailbox cmdlets runs. Either the .csv wasn't found, it didn't contain data, the field names are wrong, or there is a typo.

Do you have your Tek-Tips.com Swag? I've got mine!

Stop by the new Tek-Tips group at LinkedIn.
 
Hi Sniper

Thank you very much for your help, much appreciated

Is there a way I can rate you for your great help?

Regards
Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top