ENTERPRISE

Managing Exchange Server 2010 : The Exchange Management Shell (part 1) - Bulk user creation in the Exchange Management Shell

1/23/2011 11:59:01 AM
Windows Server 2008 was the first Operating System that came with PowerShell 1.0 by default, although it was available as a download as far back as Windows Server 2003. In case you don't know about it, PowerShell is a very potent command-line interface which can be used to fully manage your Windows server, and the first Microsoft application to fully utilize it was Exchange Server 2007; the Exchange Management Shell is actually a superset of commands built on top of PowerShell. Product Teams within Microsoft create their own Management Shell solutions, and Exchange Server was one of the first products building theirs. Naturally, there are other tools with Management Shells, such as the System Center products for example, and many of them are also built on top of PowerShell.

Exchange Server 2010 uses PowerShell version 2 (as does Exchange Server 2007 SP2), and in addition to the command-line interface this version also has an "Integrated Scripting Environment," which is an integrated graphical user interface that can be used to easily create PowerShell scripts. As I mentioned earlier, PowerShell 2.0 is also integrated with Windows Remote Management (WS-MAN), making it possible to use PowerShell to remotely manage your Exchange 2010 environment using the standard HTTPS protocol. All that's needed is a workstation or a server that has PowerShell version 2 installed on the workstation!

Figure 1. The PowerShell Virtual Directory in the Internet Information Snap-in.

Even the Exchange Management Console uses the Management Shell (i.e. is written on top of it), and so there are some functions which are not available in the Console but are available in the Shell, such as Attachment Filtering in the anti-spam options. As the Exchange Management Shell is the primary management tool in Exchange Server 2010 (as it was in Exchange Server 2007), this development direction may hurt a little bit if you're a diehard GUI administrator.

When the Exchange Management Shell is started, you'll basically see an empty box with just a command prompt – exactly like the Windows command prompt. You can get a list of all available commands at this stage by entering Get-Command.

For the benefit of those diehard GUI administrators, a PowerShell command consists of two parts: a Noun and a Verb. Verbs can be instructions like get, set, new, remove, enable, disable etc., and the Noun component can be any objects in Exchange Server. Just combine the Noun and the Verb like this:

  • Get-ExchangeServer – retrieve a list of all Exchange 2010 Servers in the organization.

  • Set-MailboxDatabase – set a property on a Mailbox Database.

  • New-Mailbox – create a new mailbox enabled User.

  • Remove-Mailbox – deletes a user object and its mailbox.

If you want to learn more about PowerShell commands, a quick web search will turn up scores and scores of learning resources.

NOTE

Besides the Exchange Management Shell, there's also the Windows 2008 PowerShell on your server or workstation. If you start the PowerShell instead of the Exchange Management Shell, you'll see a Command Prompt with a blue background, and the Exchange Server 2010 cmdlets won't be available. If you are new to PowerShell and the Exchange Management Shell, there will be a day when you start the wrong Shell.

1. Exchange Management Shell help

If there's anything you're not sure about when you're using the EMS, you have a friend in the form of the Quick Reference Guide, located in C:\Program Files\Microsoft\ExchangeServer\v14\bin\en\ExQuick.htm. This contains the most important and most-used cmdlets, and their variables.

If you need help on the fly, it's also possible to use the Shell's built-in help function. To get a list of all available help items, just type help *. If you need help about a specific cmdlet, just type help and the name of the cmdlet. To get help about mail-enabling an existing user, for example, just type help enable-mailbox.

2. Pipelining

Another great feature in PowerShell and the Exchange Management Shell is the pipelining function, which uses the output of one cmdlet as the input for a second command. This can drastically reduce the amount of work you need to put in to accomplish relatively complex tasks, and is more or less just limited by your own ingenuity.

For example, if you want to move all mailboxes in a mailbox database called "Mailbox Database 1988197524" to another mailbox database called "Mailbox Database 0823751426", you can use the following command:



This is what happens:

Get-Mailbox –Database "Mailbox Database 1988197524" retrieves a list of all mailboxes in this particular database. The output of this cmdlet is used as the input of the second cmdlet, the request to online move mailboxes to the other database. It's also possible to use more specific queries. For example, to get a list of all mailboxes whose name starts with "Chris" you would use the following command:



You can then use this as the input for a request to move all these mailboxes to another database:



3. Bulk user creation in the Exchange Management Shell

This can be very useful, particularly when you need to create a lot of mailboxes in a hurry. Suppose you have an Organizational Unit named "Sales" in Active Directory, where 100 user objects reside. This command will create a mailbox for each user in this Organizational Unit:



When there are multiple Organizational Units called "Sales" you have to specify the complete path of the Organizational Unit:



It's also possible to filter the output of the Get-User command with the –Filter parameter. For example, to Mailbox-Enable all users whose company attribute is set to "Inframan," enter the following command:



If you want to be even more specific, for example to Mailbox-Enable all users whose company attribute is set to "Inframan" and whose department attribute is set to "Intern," enter the following command:



The following operations are available for the –Filter option:

  • -and

  • -or

  • -not

  • -eq (equals)

  • -ne (does not equal)

  • -lt (less than)

  • -gt (greater than)

  • -like (string comparison)

  • -notlike (string comparison).

In some cases, you'll find it useful to import a list of users from a .CSV file. This list can be exported from another Active Directory or even from an HR (Human Resources) application. It is actually relatively easy to import a .CSV file using PowerShell; the only thing that you need to be mindful of is that the –Password option doesn't accept clear text input. The input to this field has to be converted to a secure string:



On the first three lines, three parameters are set that are used during the actual creation of the user and the mailbox. The file is read in a ForEach loop, and the actual users and the mailboxes are created as this loop progresses.

The SecurePassword function reads the password from the output .CSV file and converts it into a secure string which is used, in turn, as the password input during the creation of the users. The .CSV file itself is formatted like this:



To make this script usable, save the script file as "create.ps1" in a directory like c:\scripts. You'll also need to save the .CSV output file as users.csv in the same directory. To actually use the script, open a PowerShell command prompt, navigate to the c:\scripts directory and enter the following command:


Other  
  •  Migrating from Legacy SharePoint to SharePoint Server 2010 : Planning for an Upgrade to SharePoint 2010
  •  Migrating from Legacy SharePoint to SharePoint Server 2010 : Formulating a Migration Strategy
  •  Sharepoint 2007: Upload a File Using the Explorer View
  •  Sharepoint 2007: Upload a File Using Web Folders
  •  Sharepoint 2007: Upload a File from an Office Application
  •  Sharepoint 2007: Upload a File - Upload a File from the Web Interface
  •  Exchange Server 2007: Manage Recipients - Configure Expansion Servers
  •  Exchange Server 2007: Manage Recipients - Create Distribution Groups and Dynamic Distribution Groups
  •  Exchange Server 2007: Create Mail-Enabled Contacts and Mail-Enabled Users
  •  Advanced SharePoint 2010 Installation and Scalability : Scaling Logical SharePoint Components
  •  Installing SharePoint 2010 Using PowerShell
  •  Installing Exchange Server 2010 into an existing Exchange Server 2007 environment (part 3) - Configure Exchange Web Services
  •  Installing Exchange Server 2010 into an existing Exchange Server 2007 environment (part 2) - Installing the Exchange Server 2010 servers
  •  Installing Exchange Server 2010 into an existing Exchange Server 2007 environment (part 1) - Upgrading Active Directory
  •  Sharepoint 2007: Use the My Links to Manage Your Links
  •  Exchange Server 2007 : Administrate Transport Settings - Set Transport Rules
  •  Exchange Server 2007 : Work with Remote Domains
  •  Installing Exchange Server 2010 in an Exchange Server 2003 environment (part 3) - Finishing the installation
  •  Installing Exchange Server 2010 in an Exchange Server 2003 environment (part 2) - Installing the first Exchange Server 2010 server & Mailbox Server
  •  Installing Exchange Server 2010 in an Exchange Server 2003 environment (part 1) - Upgrading the Active Directory
  •  
    Most View
    Smartphone Tips: Customizable Settings, Security Features & More (Part 1)
    Tech Talk about Projectors
    Advice Centre by Photography Experts (Part 4)
    XtremeMac Portable Speaker Reviews
    Safe online transactions (Part 1) - Shared keys & Public key cryptography
    Android Security : Activities
    Buying Guide: Memory Kit (Part 2) - Corsair Dominator GT With DHX Pro Connector, G. Skill RipjawsZ DDR3-2133 & Mushkin Enhanced Redline 16GB DDR3-2133
    Spotflux - Enjoy The Privilege Of A US Based IP Address
    Company Profiles: Twitter
    Tablet … Google Nexus 7 By Asus
    Top 10
    ASP.NET 4 in VB 2010 : The Data Controls - Sorting and Paging the GridView
    Microsoft Content Management Server Development : A Date-Time Picker Placeholder Control (part 2)
    Microsoft Content Management Server Development : A Date-Time Picker Placeholder Control (part 1)
    Microsoft Content Management Server Development : Building SharePoint Web Parts - Configuring the Web Part, Debugging the Web Part
    Windows Server 2008 R2 networking : Planning and Deploying DNS (part 4) - Monitoring and troubleshooting DNS
    Windows Server 2008 R2 networking : Planning and Deploying DNS (part 3) - Setting up DNS zones
    Windows Server 2008 R2 networking : Planning and Deploying DNS (part 2) - Installing the DNS Server role, Configuring DNS Servers
    Windows Server 2008 R2 networking : Planning and Deploying DNS (part 1) - Designing a DNS infrastructure
    Windows Server 2008 R2 networking : Routing and Remote Access
    ADO.NET Programming : Microsoft SQL Server (part 4) - Working with Typed Data Sets