John Yassa's Blog

Home » 2012 » May » 26

Daily Archives: May 26, 2012

create bulk of mailboxes in exchange 2010 / 2007

-If you need to craete a bulk of users in exchange 2010/2007 , you will have to use the EMS

-The followin command will allow you to enter a password that will be common for all next created users
$Password=Read-Host “Enter Password” -AsSecureString

-Create a CSV file with the below header containning the requires infor for each user

-Run the below command and give him the path of the created CSV file
Import-Csv “CSV file path”|foreach {new-mailbox -Alias $_.Alias -FirstName $_.FirstName -LastName $_.lastName -UserPrincipalName $_.UPN -name $ -DisplayName $_.Displayname -OrganizationalUnit $_.OrganizationalUnit -ResetPasswordOnNextLogon $true -password $password}

-You will find all the users created divided randonly among availiable DB with password you provided in the first command with unlimited Quota

Get Mailboxes size for users in a specified OU (VB Script)

‘this is a VB script that got the OU variable and an array of Back end servers , and iterates every server and match the users with the users in the OU

‘Option Explicit

‘On Error Resume Next

Dim ServerList                  ‘ List of computers to check

Dim server                                          ‘ Current computer to check

Dim fso                                                                ‘ File System Object

Dim strWinMgmts                                           ‘ Connection string for WMI

Dim objWMIExchange                   ‘ Exchange Namespace WMI object

Dim listExchange_Mailboxs        ‘ ExchangeLogons collection

Dim objExchange_Mailbox                          ‘ A single ExchangeLogon WMI object

Dim logfile                                         ‘ Output file

Dim ou1

Dim provider

Dim objParent

Dim WshShell

Dim objUser

‘Set objParent = GetObject(provider & ou1)

ou1 = “OU LDAP Path”

provider = “LDAP://”

Const cWMINameSpace = “root/MicrosoftExchangeV2”

Const cWMIInstance = “Exchange_Mailbox”

Const LOG_FILE = “EMailSize.csv”

set objParent = GetObject(provider & ou1)

objParent.Filter = Array(“user”)


‘ Set up the email servers


ServerList  = Array(“Mailbox server 1″,”Mailbox server 2”)


‘ Set up log file


set fso = CreateObject(“Scripting.FileSystemObject”)

Set logfile = fso.CreateTextFile(LOG_FILE)

logfile.WriteLine(“””Display Name””,””Mailbox Size””,””Mailbox TotalItems””,””Mailbox StoreName””,””Mailbox ServerName””,””Mailbox LegacyDN”””)

‘ Create the object string, indicating WMI (winmgmts), using the
‘ current user credentials (impersonationLevel=impersonate),
‘ on the computer specified in the constant cComputerName, and
‘ using the CIM namespace for the Exchange provider.

WScript.Echo “Starting now”

‘The rest of the script will fetch mailbox sizes for our servers. Mailbox sizes are in Kilobytes.

For Each server in ServerList

WScript.Echo “Starting ” & server & ” search.”

strWinMgmts = “winmgmts:{impersonationLevel=impersonate}!//” & server & “/” & cWMINameSpace

‘WScript.Echo strWinMgmts

Set objWMIExchange =  GetObject(strWinMgmts)

‘ Verify we were able to correctly set the object.

If Err.Number <> 0 Then

WScript.Echo “ERROR: Unable to connect to the WMI namespace.”


‘The Resources that currently exist appear as a list of

‘Exchange_Mailbox instances in the Exchange namespace.

Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)

‘ Were any Exchange_Mailbox Instances returned?

If (listExchange_Mailboxs.count > 0) Then

‘ If yes, do the following:
‘ Iterate through the list of Exchange_Mailbox objects.

For each objUser in objParent

For Each objExchange_Mailbox in listExchange_Mailboxs
‘logfile.writeline(“””legacyExchangeDN””,”& objUser.legacyExchangeDN &””)’ ‘logfile.writeline(“””legacyDN””,”& objExchange_Mailbox.LegacyDN &””)

If  ucase(objUser.legacyExchangeDN) = ucase(objExchange_Mailbox.LegacyDN) then

‘ Display the value of the Size property.
wscript.echo “Matched”
wscript.echo objUser.legacyExchangeDN

logfile.WriteLine(“””” & objExchange_Mailbox.MailboxDisplayName & “””,””” & objExchange_Mailbox.Size & “””,””” & objExchange_Mailbox.TotalItems & “””,””” & objExchange_Mailbox.StoreName & “””,””” & objExchange_Mailbox.ServerName & “””,””” & objExchange_Mailbox.LegacyDN & “”””)






‘ If no Exchange_Mailbox instances were returned, display that.

WScript.Echo “WARNING: No Exchange_Mailbox instances were returned.”

End If

End If


Wscript.Echo “Completed”

%d bloggers like this: