IT tutorials
 
Applications Server
 

Exchange Server 2013 : The Exchange Management Shell - EMS basics (part 2) - Handling information EMS returns , Selective output

12/1/2013 8:16:38 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. Handling information EMS returns

Any cmdlet such as Get-EventLog that retrieves some information about an object will output a default set of properties about the object (or references to an object). Sometimes those properties are not exactly the ones you want to examine, so you will inevitably use the Format-List and Format-Table cmdlets to expand the set of properties a command returns. For example, if you use the Get-Mailbox cmdlet to view the properties of a mailbox, the information returned isn’t interesting:

Get-Mailbox –Identity TRedmond
Name                  Alias              ServerName           ProhibitSendQuota
---- ----- ---------- -----------------
Tony Redmond TRedmond ExServer1 unlimited

However, if you pipe the output to Format-List, you see much more information—far too much to review comfortably on screen—so it’s better to pipe the output to a text file and compare it at your leisure.

The Get-Mailbox cmdlet does not return every property you can set on a user object because EMS differentiates between general Active Directory properties for a user object and those that are specific to Exchange. For example, Get-Mailbox does not list the Office property for a user because every user object in Active Directory has this property regardless of whether it is mail-enabled. Thus, if you want to retrieve or update the Office property, you have to use the Get-User and Set-User cmdlets, respectively. The same differentiation exists for groups and contacts when the Get-Group/Set-Group and Get-Contact/Set-Contact cmdlets are available.

3. Selective output

It is easy to list every property, but when you have limited screen space, you need to be more selective about the properties you want to output, and that’s why it’s often a good idea to use the Select-Object cmdlet to select the data you need before you pipe to Format-Table. In this case, you use the Select alias for Select-Object just because this cmdlet is used so often and it is nice to use shorthand.

Get-Mailbox –Identity Pelton | Select Name, PrimarySmtpAddress, Database
Name                 PrimarySmtpAddress                    Database
---- ------------------ --------
David Pelton [email protected] ExServe1\DB1

PowerShell output can obscure data because it contains too many spaces. For example:

Get-ExchangeServer
Name        Site                  ServerRole   Edition      AdminDisplayVersion
---- ---- ---------- ------- -------------------
EXSERVER1 contoso.com/Conf…. Mailbox,… Enterprise Version 15.0 (Bu…
EXSERVER2 contoso.com/Conf…. Mailbox Enterprise Version 15.0 (Bu…

To force PowerShell to remove spaces and display more useful data, pipe the output to the Format-Table cmdlet and use the –AutoSize parameter to fit the output columns into the available space:

Get-ExchangeServer | Format-Table -AutoSize
Name       Site      ServerRole              Edition        AdminDisplayVersion
---- ---- ---------- ------- -------------------
EXSERVER1 contoso.com/Configuration/Sites/Default-First-Site-Name
Mailbox, ClientAccess Enterprise Version 1…
EXSERVER2 contoso.com/Configuration/Sites/Default-First-Site-Name
Mailbox, ClientAccess Enterprise Version 1…

Another way of extracting and then working with data is to direct the output of a command into a variable, in which case you have a complete picture of the object’s properties in the variable. For example, this command loads all the available information about the ExServer2 server into the $Server variable:

$Server = Get-ExchangeServer –Identity 'ExServer2' -Status

You can extract additional information about the server to use by including the name of the property in which you’re interested. (Specifying the –Status parameter requests Get-ExchangeServer to provide some additional information about the current domain controller and global catalog the server is using.) You can also use a variable as an array and populate the array with a call to a command.

In this example, you populate a $Mailboxes array with a call to Get-Mailbox, using a filter to extract details of all the mailboxes stored in a particular database. This output is a good example of how cmdlets can generate individual objects or an array of objects with each object being individually accessible within the array.

$Mailboxes = Get-Mailbox –Database DB2

When it is populated, you can then navigate through the array as follows:

$Mailboxes[0]
$Mailboxes[1]
$Mailboxes[2] etc etc etc.

You can reference specific properties of the objects by using the “.” operator.

$Mailbox[2].Name
$Mailbox[53].PrimarySmtpAddress

Inside Out Finding what you want when there’s a lot of output

The output from a cmdlet such as Get-Mailbox can easily result in a lot of data that are hard to read to find the piece of information in which you are really interested. One technique that helps is to pipe the output to the Out-String cmdlet and then use the FindStr cmdlet to search the output for a particular term. For example, here’s how to use the two cmdlets to search the output from Get-Mailbox to find a particular term. In this instance, EMS lists any occurrence of the word “Tony” if it exists in the list of mailbox names Get-Mailbox returns:

Get-Mailbox | Out-String | FindStr "Tony"

By default, EMS truncates the output of multivalue properties after 16 values. For example:

Get-Mailbox –Identity 'Pelton, David' | Format-List Name, EmailAddresses
Name           : Pelton, David
EmailAddresses : {smtp:[email protected], smtp:[email protected], smtp:[email protected],
smtp:[email protected], smtp:[email protected], smtp:[email protected], smtp:[email protected],
smtp:[email protected], smtp:[email protected], smtp:[email protected], smtp:[email protected], smtp:[email protected]…}

Truncation can hide some valuable data. In the preceding example, many of the email addresses are defined for a mailbox, but the default Simple Mail Transfer Protocol (SMTP) address is not shown. If this limitation becomes a concern, you can force EMS to output more values for a property by amending a $FormatEnumerationLimit variable. This variable is defined in the EMS initialization script (\bin\Exchange.ps1), and the default value of 16 is usually more than sufficient for normal purposes. If you want to see more variables, you can set the variable to a different limit or set it to -1 to instruct EMS that it can enumerate as many values as are available for any property. For example:

$FormatEnumerationLimit = -1
Get-Mailbox –Identity 'Pelton, David' | Format-List Name, EmailAddresses
Name           : Pelton, David
EmailAddresses : {smtp:[email protected], smtp:[email protected], smtp:[email protected],
smtp:[email protected], smtp:[email protected], smtp:[email protected], smtp:[email protected],
smtp:[email protected], smtp:[email protected], smtp:[email protected], smtp:[email protected],
smtp:[email protected], smtp:[email protected], smtp:[email protected], smtp:[email protected],
smtp:[email protected], smtp:[email protected], smtp:[email protected], SMTP:[email protected]}
 
Others
 
- Exchange Server 2013 : The Exchange Management Shell - EMS basics (part 1) - Command editing
- Exchange Server 2013 : The Exchange Management Shell - Using remote Windows PowerShell - Connecting to remote PowerShell
- Exchange Server 2013 : The Exchange Management Shell - How Exchange uses Windows PowerShell
- Active Directory Planning and Installation : Installing Active Directory - Promoting a Domain Controller
- Active Directory Planning and Installation : Understanding Domain and Forest Functionality
- Active Directory Planning and Installation : Verifying Network Connectivity - Tools and Techniques for Testing Network Configuration
- Active Directory Planning and Installation : Verifying the Filesystem - Setting Up the NTFS Partition
- Sharepoint 2013 : Building an Application with Access Services (part 6) - Adding a Macro, Reporting and External Data
- Sharepoint 2013 : Building an Application with Access Services (part 5) - Modifying Application Views, Creating a Query
- Sharepoint 2013 : Building an Application with Access Services (part 4) - Adding, Removing, and Editing Tables
 
 
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