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:
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.
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
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]}