IT tutorials
 
Technology
 

Exchange Server 2010 : Object-Oriented Use of PowerShell (part 2) - Formatting Output, Directing Output to Other Cmdlets

9/3/2013 10:03:22 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. Formatting Output

If you look at the output of the Get-Mailbox cmdlet shown in Figure 1, you might be tempted to think that the output capabilities of PowerShell are limited, but this is far from the truth. The output shown in Figure 1 was the default output for the Get-Mailbox cmdlet. The programmer decided that the output should be in a formatted table with the name, alias, home server, and ProhibitSendQuota properties as columns. However, you can select on your own the properties you want by merely piping the output of the Get-Mailbox cmdlet to either the Format-Table (FT for short) or Select cmdlet:

Get-Mailbox | FT Name,ProhibitSendQuota,ProhibitSendReceiveQuota

Figure 2 shows the output of the preceding command.

Figure 2. Formatting output to a formatted table

The output of the Get-Mailbox cmdlet was directed to the Format-Table or FT cmdlet; the result was columns for the Name, ProhibitSendQuota, and ProhibitSendReceiveQuota limits.

You may be wondering how you can learn all the properties of an object. The default output of the Get-Mailbox cmdlet, for example, is probably not the most useful for your organization.

When you direct the output of a cmdlet such as Get-Mailbox to the Format-List cmdlet, you will see all the properties for that object. Figure 3 shows an example where we have directed the output of a Get-Mailbox cmdlet to the FL (Format-List) cmdlet. You will notice in Figure 3 that the properties filled up more than one screen. However, you will find that outputting all the properties of an object using the Format-List cmdlet is very useful if you need to know specific property names.

The command we used is as follows:

Get-Mailbox "Clayton Kamiya" | Format-List

3. Directing Output to Other Cmdlets

You have already seen a couple of examples where we used the pipe symbol (|) to direct the output of one command to be used as input for the next command, such as Get-Mailbox | Format-Table. You can do this because PowerShell commands act on objects, not just text. Unlike with other shells or scripting languages, you don't have to use string commands or variables to pass data from one command to another. The result is that you can use a single line to perform a query and complex task — something that might have required hundreds of lines of programming in the past.

One of our favorite examples would be making specific changes to a group of people's mailboxes. Let's say you need to ensure that all executives in your organization should be able to send and receive a message that is up to 50 MB in size rather than the default 10 MB to which the system limits the user. Earlier we showed you how you could get the properties of the mailbox that you were interested in, such as the MaxSendSize and MaxReceiveSize properties.

Figure 3. Formatting output to a formatted list

First, let's use the Get-DistributionGroupMember cmdlet to retrieve the members of the Executives distribution group:

Get-DistributionGroupMember "Executives"
Name RecipientType
---- -------------
Mark Watts MailboxUser
David Elfassy MailboxUser
Brian Tirch MailboxUser
Paul Robichaux MailboxUser
Devin Ganger MailboxUser
Julie Samante MailboxUser
Cynthia Wang MailboxUser

Remember that though you see the text listing of the group members, what is actually output are objects representing each of the members.

It is important to note that while piping the output of one cmdlet as input for another cmdlet works frequently, it does not work all the time. Piping input to a cmdlet will always work when the noun used by the two cmdlets is the same, such as this:

Get-Mailbox -Server HNLMBX01 | Set-Mailbox -CustomAttribute1 "I am on a 

great server!"

For cmdlets that do not support piping between them, you can usually use a trick such as using the foreach cmdlet to process the data.

So, now let's pipe the output of that cmdlet to the Set-Mailbox cmdlet and do some real work! To change the maximum incoming and outgoing message size for the members of the Executives group, you would type the following command:

Get-DistributionGroupMember "#Executives" | Set-Mailbox  

-MaxSendSize:50MB -MaxReceiveSize:50MB

-UseDatabaseRetentionDefaults:$False

Notice that the Set-Mailbox cmdlet did not require any input because it will take as input the objects that are output from Get-DistributionGroupMember. When you run these two commands, there will be no output unless you have specified other options. But you can easily check the results by requesting the membership of the Executives group, piping that to the Get-Mailbox cmdlet, and then piping that output to the Format-Table cmdlet, as shown here:

Get-DistributionGroupMember "#Executives" | Get-Mailbox | Format-Table 

Name,MaxSendSize,MaxReceiveSize
Name MaxSendSize MaxReceiveSize
---- ----------- --------------
Clarence A. Birtcil 50 MB (52,428,800 bytes) 50 MB (52,428,800 bytes)
Cheryl Tung 50 MB (52,428,800 bytes) 50 MB (52,428,800 bytes)
Jonathan Core 50 MB (52,428,800 bytes) 50 MB (52,428,800 bytes)
Kevin Wile 50 MB (52,428,800 bytes) 50 MB (52,428,800 bytes)
Julie R. Samante 50 MB (52,428,800 bytes) 50 MB (52,428,800 bytes)
Gerald Nakata 50 MB (52,428,800 bytes) 50 MB (52,428,800 bytes)

Pretty cool, eh? After just a few minutes working with PowerShell and the EMS extensions, we hope that you will be as pleased with the ease of use as we are.

 
Others
 
- Exchange Server 2010 : Object-Oriented Use of PowerShell (part 1) - Filtering Output
- Exchange Server 2010 : Introduction to PowerShell and the Exchange Management Shell - Understanding the Command Syntax
- Windows 8 : Controlling Access to Files and Folders with NTFS Permissions (part 5) - Determining the Effective Permissions and Troubleshooting
- Windows 8 : Controlling Access to Files and Folders with NTFS Permissions (part 4) - Applying Permissions Through Inheritance
- Windows 8 : Controlling Access to Files and Folders with NTFS Permissions (part 3) - Assigning Claims-Based Permissions, File Ownership and Permission Assignment
- Windows 8 : Controlling Access to Files and Folders with NTFS Permissions (part 2) - Assigning Special Permissions
- Windows 8 : Controlling Access to Files and Folders with NTFS Permissions (part 1) - Understanding and Using Basic Permissions
- Windows 8 : Managing File Security and Resource Sharing - File Security and Sharing Options
- Scripting Windows Home Server : Programming the WshShell Object (part 2) - Working with Registry Entries, Working with Environment Variables
- Scripting Windows Home Server : Programming the WshShell Object (part 2) - Running Applications, Working with Shortcuts
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us