AL Part I TE D MA TE RI PowerShell for Exchange Fundamentals GH Chapter 1: Getting Started with Windows PowerShell Chapter 2: Using Exchange Management Shell RI Chapter 3: Using PowerShell to Deploy Exchange Server 2007 PY Chapter 4: Working with User and Group Objects CO Chapter 5: Public Folders
Getting Star ted with Windows PowerShell Windows PowerShell is the next-generation command-line shell and scripting language for Windows. Exchange Server 2007 is the first Microsoft application to utilize Windows PowerShell for deployment and administration. This chapter introduces Windows PowerShell and explains the basic concepts you’ll need to know to use Windows PowerShell effectively.
Part I: PowerShell for Exchange Fundamentals need for an advanced interface like Windows PowerShell. What follows is a discussion of the main features that set Windows PowerShell apart from other management interfaces and make it the most powerful administrative interface that Microsoft has ever produced. Shell History Before there was the Graphical User Interface (GUI), there was the Command Line Interface (CLI).
Chapter 1: Getting Started with Windows PowerShell Common Shell Limitations The traditional shells mentioned earlier offer an administrator greater control and flexibility for tackling everyday or even unusual management tasks, but they all suffer from significant drawbacks. Command shells operate by executing built-in commands that run within the process of the shell, or by executing a command or application in a new process outside of the shell.
Part I: PowerShell for Exchange Fundamentals Because Windows PowerShell is fully extensible, software developers can create their own custom built-in commands to handle those administrative tasks not already addressed in the default built-in command set. Exchange Management Shell is an example of Windows PowerShell extended to include more than 500 built-in commands.
Chapter 1: Getting Started with Windows PowerShell Figure 1-1 While invoking Windows PowerShell, this command specifies a console definition file identified by the PSConsoleFile parameter. The exshell.psc1 file contains a pointer to the Exchange Management Shell snap-in definition stored in the Registry at HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.Exchange.Management .PowerShell.Admin.
Part I: PowerShell for Exchange Fundamentals Exchange management. It also defines the appearance of the command-line prompt and the initial welcome banner shown in Figure 1-2. As you can see, the appearance of the Exchange Management Shell is a bit different from the default Windows PowerShell console application, yet all the functionality of the core shell remains intact.
Chapter 1: Getting Started with Windows PowerShell execution of the cmdlet. For example, the cmdlet Get-ExchangeServer returns a list of all Exchange servers in the organization in a formatted list as shown in Figure 1-3. Figure 1-3 Windows PowerShell commands are case-insensitive. The examples given in this section use the default form of capitalizing the first letter of each distinct word in the command elements. Only spelling and syntax count when entering Windows PowerShell commands.
Part I: PowerShell for Exchange Fundamentals The Get verb is the most common verb used in Exchange Management Shell cmdlets. It is also known as the default verb. When a cmdlet noun name is entered without a verb, Windows PowerShell assumes that the Get verb was implied and runs that cmdlet. In the preceding example, entering ExchangeServer instead of Get-ExchangeServer would yield the same results.
Chapter 1: Getting Started with Windows PowerShell In Figure 1-4, the Set-Mailbox cmdlet is being used to set the ProhibitSendQuota attribute on mailbox-enabled user John Doe. The expected data input type for parameter ProhibitSendQuota is an integer value or integer value with a standard byte size abbreviation as a suffix. Because an alphanumeric string value (somestring) was entered instead, the command fails to execute and the error message shown describes the exact cause for the error.
Part I: PowerShell for Exchange Fundamentals For example, the Get-Service cmdlet is used to gather information about services and supports wildcards for the Name parameter used to identify those services. Using the asterisk wildcard you can generate a list of all services with names that match the given pattern, as shown in Figure 1-6 for services that begin with Net. Figure 1-6 Most cmdlets that use the Identity parameter support wildcards as input.
Chapter 1: Getting Started with Windows PowerShell Optional and Required Parameters Cmdlets may have some parameters that are not required to be used each time the cmdlet is run and are considered optional. You will find that most cmdlets have at least some optional parameters, especially cmdlets that modify items, because not all properties of an item require changing at the same time.
Part I: PowerShell for Exchange Fundamentals For example, the Identity parameter is typically a positional parameter used in position 1 after the cmdlet name. The Get-Mailbox cmdlet uses the Identity parameter in position 1 to identify the mailbox-enabled user for which to retrieve information.
Chapter 1: Getting Started with Windows PowerShell The solution is to provide enough of the parameter name to make it unique, in this case posta would be enough to disambiguate PostalCode from PostOfficeBox. Discovering Commands and Getting Help Now that you have learned the basic concept of using cmdlets, we’ll discuss how to go about discovering cmdlets and learning how to use them.
Part I: PowerShell for Exchange Fundamentals In this example for Get-Help and for those that follow later in this section, input values are used without specifying the parameter Name. Because Name is a positional parameter (for position 1), it is not required to be named as long as the input value appears on the command line in the first position after Get-Help. Using the whole word database produces a list of cmdlets that have at least the word at the beginning of the noun name.
Chapter 1: Getting Started with Windows PowerShell Figure 1-13 The other possible role values you can use with the Role parameter are: ❑ *client* for Client Access Server ❑ *hub* for Hub Transport server ❑ *um* for Unified Messaging server ❑ *edge* for Edge Transport server Using Get-Command to Find Cmdlets In addition to the Get-Help cmdlet, the Get-Command cmdlet is very useful for discovering cmdlets and other Windows PowerShell command elements such as functions, aliases, applications, and ext
Part I: PowerShell for Exchange Fundamentals cannot be used in conjunction with either the Verb or Noun parameters. In Figure 1-14, Get-Command is used with the Verb and Noun parameters to return a list of matching cmdlets. Figure 1-14 The CommandType parameter allows you to specify the type of command for which to return matches. Possible values are Alias, Function, Cmdlet, ExternalScript, Application, and All.
Chapter 1: Getting Started with Windows PowerShell Get-Command can also be used to return detailed information about the syntax of a given cmdlet using the Syntax parameter. However, you may find the syntax information exposed in a cmdlet’s help information to be more useful in the long run because it is accompanied by other help details. Using Help Information Effectively Cmdlet help information is very detailed and you may find it difficult to follow when you first start learning about a given cmdlet.
Part I: PowerShell for Exchange Fundamentals The command Get-Help -Full displays the entire contents of the help file for the cmdlet including detailed information about each parameter. The command Get-Help -Examples displays the Examples topic along with the Synopsis topic. The command Get-Help -Parameter displays the detailed information about the specified parameter. Wildcards are permitted.
Chapter 1: Getting Started with Windows PowerShell Parameter details describe whether the parameter is required or optional and if it is positional or named. They also describe whether the parameter has a default value and if it accepts pipeline input and wildcard characters. For example, the parameter details for the Identity parameter as used with the SetMailbox cmdlet contain the information displayed in Figure 1-16 using Get-Help and the Parameter parameter.
Part I: PowerShell for Exchange Fundamentals Figure 1-17 Most shells offer some form of automatic completion to take some of the drudgery and guesswork out of entering certain command elements. Even cmd.exe offers automatic completion using the tab key when typing directory paths and filenames. Windows PowerShell takes this feature to whole new levels of functionality by providing tab expansion of cmdlet and parameter names as well.
Chapter 1: Getting Started with Windows PowerShell Using this procedure you can enter complex, mistake-free cmdlet names using a minimal number of characters and Tab keystrokes. One major benefit of tab expansion is you don’t have to remember exact cmdlet names as long as you can enter at least the verb name followed by a few letters of the noun name. Tab expansion works for parameter names in the same manner. This works especially well when you don’t know all the possible parameter names a cmdlet is using.
Part I: PowerShell for Exchange Fundamentals collection to the Set-User cmdlet along with the appropriate value for the Fax parameter you can change the fax number quickly and easily on every user account using a single command line. Commands that use multiple cmdlets and pipelines on a single line are often referred to as “one-liners.
Chapter 1: Getting Started with Windows PowerShell The value to test must be of the same data type of the property being tested. For example, if the property data type is string, a string value enclosed in quotes must be used for the test. If the property data type is integer, a numeric value must be used for the test and so on.
Part I: PowerShell for Exchange Fundamentals Figure 1-18 Controlling Output When you run a cmdlet in Windows PowerShell, the type of data displayed as output, if any, is determined by the default format of the cmdlet. The output format is determined at the time the cmdlet is created. Most cmdlets that use the Get verb have some form of default display formatting that results in what the programmer determined the most useful information.
Chapter 1: Getting Started with Windows PowerShell Format-List In the previous example Get-Mailbox displayed only those properties specified as default output for the cmdlet. By passing the object to Format-List (or its alias name fl) without any additional parameters, all properties are displayed in a list format as shown in Figure 1-20. Figure 1-20 To display only specific properties, add the property names, separated by commas, after Format-List.
Part I: PowerShell for Exchange Fundamentals Format-Table Format-Table (and its alias, ft) is similar to Format-List except it allows you to format output in table format. Unlike Format-List, passing objects to Format-Table without any additional parameters results in one of two displays. If the default format for displaying output is table format of select properties, the default format is used for display.
Chapter 1: Getting Started with Windows PowerShell To change this behavior, add the AutoSize parameter to force Format-Table to change column widths to make the most of the console screen width, and the Wrap parameter to wrap long values that won’t fit on a single line to the next line. The addition of these two parameters to the previous example yields the results shown in Figure 1-24.
Part I: PowerShell for Exchange Fundamentals All scripts included with Exchange Server 2007 have been code signed by Microsoft to ensure the scripts comply with the execution policy model for ensuring scripts can be accounted for before execution. The default execution policy setting for Exchange Management Shell is RemoteSigned. This level allows you to run scripts you create locally and warns you when scripts provided by Microsoft have been altered.
Chapter 1: Getting Started with Windows PowerShell Summar y ❑ Windows PowerShell is the next-generation command-line shell and scripting language for Windows. Exchange Server 2007 is the first Microsoft application to utilize Windows PowerShell for deployment and administration. ❑ Command shells provide a more flexible administrative interface compared to Graphical User Interfaces (GUIs). Administrators use scripts to automate everyday tasks and resolve issues GUI interfaces are not able to handle.