Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


July 03, 2007

Setting Up Exchange Management Shell

Here's the scoop on using the right scope for your queries
RSS
Subscribe to Windows IT Pro | See More Scripting Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Executive Summary:
You can customize Microsoft Exchange Server 2007's Exchange Management Shell to look and perform the way you want it to.
When using Microsoft Exchange Server 2007's Exchange Management Shell, it's important to establish the correct scope for Active Directory (AD) lookups.

In previous articles, I've discussed how Exchange Management Shell lets you use scripts to automate Exchange Server 2007 management ("Windows PowerShell Transforms Exchange Server 2007 Management," April 17, 2007, InstantDoc ID 95295, and "Using the Shell to Manage Exchange 2007," June 5, 2007, InstantDoc ID 95843) . Now it's time to consider aspects such as customizing Exchange Management Shell and the importance of scoping to process the right data.

Personal PowerShell
When you install Exchange 2007 on a server (or the management components on a Windows XP workstation), Exchange Management Shell is placed on the Windows Start menu. Starting the management shell calls a PowerShell script, Exchange.ps1, from the Exchange binaries directory. Exchange.ps1 uses the Add-PSSnapin cmdlet to instruct PowerShell to load the Exchange snap-in, which contains the commands specific to Exchange objects such as mailboxes, servers, and public folders. After loading the snap-in, the commands in Exchange.ps1 define variables used by the shell. For example, the $ExBin variable points to the Exchange binaries directory and $ExScripts points to the Exchange scripts directory. The $AdminSessionADSettings variable is also defined—I'll return to its use shortly. These are all global variables: You can use them anywhere during your PowerShell session.

After everything is initialized, PowerShell presents you with a command window for working with Exchange. As Figure 1 shows, you can customize the font, layout, and colors that Exchange Management Shell uses in its command window by using the shell's properties sheet. For example, you might decide to use a larger or more readable font.

In addition to the variables defined by Exchange.ps1, you can define other variables in your personal PowerShell profile. Windows doesn't create your profile automatically; you'll have to create a file called Microsoft.PowerShell_profile.ps1 with an editor such as Notepad and save it to My Documents\WindowsPowerShell. (For a discussion about the use of PowerShell profiles, see http://www.leeholmes.com/blog/TheStoryBehindTheNamingAndLocationOfPowerShellProfiles.aspx.) You can define whatever variables you need and insert other commands to personalize your working environment. After you've created the profile, you can edit it from within Exchange Management Shell by using the command

Invoke-Item $Profile 

You have to restart the shell for changes in your profile to be effective. Figure 2 shows a sample profile, and Figure 3 shows how the shell displays that profile. You can scan the Internet to discover the many different customizations people have applied through their personal profiles, such as defining new aliases as command shortcuts and creating a different prompt. Note that PowerShell executes your profile first, then executes the commands in Exchange.ps1. It's important that you don’t attempt to create a variable in your profile that will then be overwritten by Exchange.ps1.

Scoping
The $AdminSessionADSettings global variable set by Exchange.ps1 controls the scope of Active Directory (AD) lookups during an Exchange Management Shell session. By default, the scope for queries performed against AD is the domain of the server or workstation on which you run the shell. If you have a multidomain forest, any query you perform still returns objects only from the local domain.

For example, let's assume you have a forest implementation where a root domain has three child domains to support accounts called South, West, and East. You have Exchange servers installed in each regional domain, and you use Custom Attribute 15 to identify which region mailboxes belong to. If you execute the command

Get-Mailbox -Filter `
 {CustomAttribute15 -eq "West"} | `
 Select Name 

you might expect to search the entire forest to return a list of mailboxes that belong to the West region. However, you'll find only the mailboxes in the local domain that have “West” set in Custom Attribute 15 because the default scope for AD lookups doesn't extend beyond the local domain. The potential for confusion is obvious.

When Exchange Management Shell initializes, the scope is set with the ViewEntireForest property of the $AdminSessionADSettings global variable. You can edit the ViewEntireForest property to set the scope to view the entire forest as follows:

AdminSessionADSettings.ViewEntireForest = $True 

To reset the scope so that the shell uses objects from only the local domain, type

$AdminSessionADSettings.ViewEntireForest = $False 

You can make the change interactively through the shell or by adding the code to your profile. The first option is best if you need to make a one-time change; use the profile option if you usually work in multidomain mode.

Clearly, creating the proper scope for AD lookups is critical for such things as retrieving the correct set of mailbox data. Incorrect scoping can catch you out in many ways. For example, the Update-SafeList cmdlet gathers safe list information from user accounts and aggregates them so that Exchange can synchronize the data to an Edge Transport server. Antispam agents running on the Edge server can then use the aggregated user safe list data to avoid false positives. If you execute the Update-SafeList cmdlet with the wrong scope, you'll aggregate only the safe list data from the in-scope domain and therefore provide the Edge server with incomplete data.

If you don't want to set your scope to the entire forest, a workaround is to specify a Global Catalog (GC) server in the remote domain to use for the query. For example, if we include a GC in the South domain, we can check whether any West mailboxes exist in that domain with the following command:

Get-Mailbox -DomainController `
 GC01.South.MyOrg.Com `
 -Filter {CustomAttribute15 `
 -eq "West"} | Select Name 

Changing the scope for AD queries will affect how you work with Exchange Management Shell. When you set a forestwide scope, you might have to wait longer for a response from any command, but in most cases the wait is worthwhile because you see the big picture and don't run the risk of missing something. To save time, you need to use parameters to focus on particular groups of objects, such as specifying that you want to work with the mailboxes from a specific server.

Of course, when you set a forestwide scope, it's important to be efficient with your queries, and that's where filters come to your assistance. I'll talk about filters as well as batch execution in my next article in this series on PowerShell for Exchange administrators.

End of Article



Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

Escape From Yesterworld

Kevin points you to the funniest SQL Server website ever! ...

The Desktop tab is missing from the Display Properties in Windows XP?

...


Related Articles Managing Public Folders in Microsoft Exchange Server 2007

Managing Mailboxes with Exchange Management Shell

Exchange Server and Outlook Whitepapers Anonymizers – The Latest Threat to Your Web Security

Replay for Exchange: Enterprise Protection and an Affordable Price

ETX Driving Embedded I/O

Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

Job Openings in IT


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

WinConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

Maximize your SharePoint Investment – 8 Cities
Discover best practices and tips for both architecting and administering SharePoint. Early Bird Price of $99 through Sept 15th.

Find a new job now on the all new IT Job Hound!
Search jobs, post your resume, and set up job e-mail alerts!

Master SharePoint with 3 eLearning Seminars
Learn how to build a better SharePoint infrastructure and enable powerful collaboration with MVPs Dan Holme and Michael Noel. Register today!

Top Tools for Virtualization Disaster Recovery & Replication
View this web seminar on August 14th to learn about two tools that will result in faster backup and restore with P2V disaster recovery.

SharePointConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

VMworld 2008 - Sign Up Today!
Join your peers on September 15-18 at The Venetian Hotel in Las Vegas as VMware hosts VMworld 2008, the leading Virtualization event.



When managing just VMware isn’t enough
Plan/Manage/Secure – NetIQ VMware management. Download whitepaper.

What’s up with your network? Find out with ipMonitor
Availability monitoring for servers, applications and networks – FREE trial

Microsoft® Tech•Ed EMEA 2008 IT Professionals
Advance your thinking with new ideas and practical real-world solutions at Microsoft’s FIVE day technical infrastructure conference 3-7 Nov., 2008. Register before 26 September 2008 to save €300.

Order Your Fundamentals CD Today!
Gain an introduction to Exchange, learn server security requirements, and understand how unified communications can play a role in your messaging strategies with this free Exchange CD.

Are You Really Compliant with Software Regulations?
View this web seminar that will help you with compliance best practices and check out a management solution to assure that you won’t be in jeopardy of an audit.

Virtualization Congress Oct. 14-16 in London
Don't miss Virtualization Congress, the premiere EMEA conference dedicated to hardware, OS and application virtualization. Oct. 14-16 in London.
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technical Resources Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing