Both Exchange Server 2007 and Exchange Server 2010 use Exchange Management Shell (EMS), a command-line management tool. Although you can perform basic Exchange management tasks using the graphical user interface, you can only perform certain administrative actions from the command line. This tip explains some basic EMS commands for managing Exchange Server from the command line.
Invoking an item
The Invoke-Item command can be compared to an automated double-click. For example, you could use the Invoke-Item command to open an HTML document, instead of double clicking on the file itself. To do so, append the path and filename to the Invoke-Item command:
Extracting information from Active Directory
Active Directory contains a wealth of information. When a new user account is created, information such as the user's title, department, manager and phone number may be entered into Active Directory.
You can extract this information from Active Directory using an EMS command. For example, you would use the following command to create a list of each user's name and job title.
Get-User | Format-Table Name, Title
The Get-User command retrieves a list of all Active Director users. The pipe symbol ( | ) redirects the command's output into a secondary command. In this case, the secondary command tells Exchange to format the output as a table and to display the user's name and title. Name and Title are names of Active Directory attributes; you can substitute other attribute names or add attributes.
Creating a public folder
Exchange Server 2007 required you to manage public folders from the command line, unless you had an Exchange Server 2003 public folder server in your organization. And although Exchange 2007 SP1 included public folder management tools, it's still important to know how to manage public folders from the command line.
One of the simplest public folder management tasks is creating a new public folder. For example, suppose that you wanted to create a public folder named HR. To do so, you should use this command:
New-PublicFolder –Name "HR" –Path "\" –Server "Lab-E2K7"
The path is set to \, so this command will create a top-level public folder. You could also create a sub folder by extending the path. For instance, you would include the HR folder in the pat to create a folder named Forms beneath the HR folder on the same public folder server.
New-PublicFolder –Name "Forms" –Path "\HR" –Server "Lab-E2K7"
Move a mailbox
EMS also allows you to move a mailbox to a different database. The following command moves a user named User3 to a mailbox database named Users:
Get-Mailbox "User3" | Move-Mailbox –TargetDatabase "Users"
This command begins with the Get-Mailbox command, which specifies User 3 in this instance. But you could use a variation of this command to retrieve multiple mailboxes. Next, the command pipes the retrieved mailbox into the Move-Mailbox command. Notice that you're required to provide the Move-Mailbox command with the name of the target mailbox database.
Testing an EMS command
Until you have a handle on how EMS works, it's easy to accidentally perform an unintended operation. The –ValidateOnly option protects you from your own mistakes.
The ValidateOnly option allows you to see what would have happened if you had executed a command -- without any potentially disastrous side effects. If you wanted to find out what would happen if you executed the Move-Mailbox command from the section above, for example, you could append the ValidateOnly option to the command. This command allows you to test the command without actually moving the mailbox.
Get-Mailbox "User3" | Move-Mailbox –TargetDatabase "Users" –ValidateOnly
Note: ValidateOnly doesn't work with every EMS command, but does work with several of them.
An EMS command hint
If you've done a lot of work with the Exchange Management Console (EMC), then you know that most of the administrative actions you can perform are wizard-based. When you complete a management task, the wizard's final screen provides you with an EMS command that would perform the same action. Figure 1 shows the command that displays after creating a new mailbox.
The Exchange Management Console is built on top of EMS. Whenever you perform a task through the console, it actually sends a command to EMS behind the scenes. This means that the command shown after the task was completed is the exact command that Exchange used internally.
About the author: Brien M. Posey, MCSE, is a five-time recipient of Microsoft's Most Valuable Professional (MVP) award for his work with Exchange Server, Windows Server, Internet Information Services (IIS), and File Systems and Storage. Brien has served as CIO for a nationwide chain of hospitals and was once responsible for the Department of Information Management at Fort Knox. As a freelance technical writer, Brien has written for Microsoft, TechTarget, CNET, ZDNet, MSD2D, Relevant Technologies and other technology companies. You can visit Brien's personal website at www.brienposey.com.
Do you have comments on this tip? Let us know.
Now that you have the basics, learn Exchange PowerShell commands for faster mailbox management