Managing Exchange Server 2010 – A PowerShell Approach (Part 3)

Managing Exchange Server 2010 – A PowerShell Approach (Part 3)
 
Those who have missed the earlier series, please find them as below.
https://blogs.technet.com/b/ashwinexchange/archive/2012/06/20/managing-exchange-server-2010-a-powershell-approach-part-1.aspx
https://blogs.technet.com/b/ashwinexchange/archive/2012/06/21/managing-exchange-server-2010-a-powershell-approach-part-2.aspx

So, Let’s target these commands.

Get-MailboxDatabase
Get-PublicFolderDatabase

Note: As we move on we will be including more commands in one part, and this part will be specifically made to make all understand the 4 Step rule to tame PowerShell.

Now you got the commands, now the task is to get it working.

LAB
We are going to use the below mentioned Lab
https://cmg.vlabcenter.com/default.aspx?moduleid=7a24cd3c-9be4-4ec1-ae43-9bfb9f8ecbd6

Once connected, we are ready to rock and roll.

Get-MailboxDatabase

So here you go let's start with my 4 Step Rule to tame PowerShell 

Step 1 
Get-Command
One Stop Search to understand the available commands

What if, I’m not aware of the command Get-MailboxDatabase? Quiet possible. But I’m aware that I need to get some details about the MailboxDatabase. And I know for PowerShell MailboxDatabase is a noun.
Let’s see the possible options.
 
Option 1
 
I’m aware that MailboxDatabase is a valid noun for PowerShell, but unaware of the verb (although that is a real rear case for many), I will use the below command on Exchange Management Shell.
 
Get-Command –noun MailboxDatabase

Here you can easily choose Get-MailboxDatabase.
 
Option 2
 
I aware that the verb is Get and noun which I’m looking for may contain database in its name, I will use the below command on Exchange Management Shell.
 
Get-Command –verb Get –noun *database*

Similarly, here you can easily choose Get-MailboxDatabase.
 
Note:
And to have a better understanding, please refer to.
https://blogs.technet.com/b/heyscriptingguy/archive/2012/05/15/find-powershell-commands-by-using-the-get-command-cmdlet.aspx
https://technet.microsoft.com/library/ee176842.aspx
 
Now that you know the command, let’s move to the next step.
 

Step 2
Get-Help
 
This gives the detailed manual of each command.
Let’s see the possible options.
 
Option 1
 
To start with, first we must know how to use Get-Help command.
So let’s first check the manual for Get-Help command, for that just type.
 
Get-Help

Output shows as follows, and yes it give a lot to read, maybe we can highlight those which are really important and truncate the other details
 
Syntax
get-help {<CmdletName> | <TopicName>}
help {<CmdletName> | <TopicName>}
<CmdletName> -?
 
 
"Get-help" and "-?" display help on one page.
"Help" displays help on multiple pages.
 
Examples:

get-help get-process : Displays help about the Get-Process cmdlet.
get-help about_signing : Displays help about signing scripts.
help where-object: Displays help about the Where-Object cmdlet.
help about_foreach : Displays help about foreach loops in PowerShell.
set-service -? : Displays help about the Set-Service cmdlet.
 
You can use wildcard characters in the help commands (not with -?).

Examples:
 
get-help *: Displays all help topics.
get-help get-* : Displays topics that begin with get-.
help *object* : Displays topics with "object" in the name.
get-help about* : Displays all conceptual topics.
 
Note:
 
And below link can get you a detailed idea on this.
https://technet.microsoft.com/en-us/library/ee176848.aspx
So, a lot told about Help command, let’s get to work using the above knowledge.
 
Here we are going to check the Help File for Get-MailboxDatabase

Any gusses for the Syntax? Oh, yeah I know it is easy.

Get-Help Get-MailboxDatabase

And as I said earlier, let’s see the examples.

Get-Help Get-MailboxDatabase –Examples
 
-------------------------- EXAMPLE 1 --------------------------
 
This example retrieves information about all the mailbox databases in the Exchange organization, including the mailbox databases that reside on computers running Exchange 2010 and earlier versions of Exchange.
 
Get-MailboxDatabase -IncludePreExchange2010
 
-------------------------- EXAMPLE 2 --------------------------
 
This example retrieves information about MailboxDatabase01 on Server01. This example also retrieves the status information, and pipes the output to the Format-List cmdlet so that you can view all the information about the mailbox database.
 
Get-MailboxDatabase -Identity Server01\StorageGroup01\MailboxDatabase01 -Status | Format-List
 
 
 
Step 3
Parameter Sets

Parameter Sets are the different ways of using the same Windows PowerShell command.
And hence it is very important to understand.
 
Note:
And below link can get you a detailed idea on this.
https://blogs.technet.com/b/heyscriptingguy/archive/2012/05/16/use-the-get-command-powershell-cmdlet-to-find-parameter-set-information.aspx
 
 
But It won’t have any impact as Get-MailboxDatabase is a simple command.
What do you see if you follow the below syntax?
 
Syntax you can use are:
$command=Get-MailboxDatabase
$command. DefaultParameterSet
$command.ParameterSets

 So here it’s not a big deal, but we have just started.

Step 4
Discover all available properties of a PowerShell Command.

Get-Member is an important command for discovering more about a PowerShell Command.
Here in this series, we were will be focusing on properties available for each command.

Apart from properties, we can also get methods, which I will leave it to reader for experimenting.

<Command> | Get-Member -MemberType property
OR
<Command> -Property * | Get-Member -MemberType property
OR
<Command> <-Filter *> -Property * | Get-Member -MemberType property

This will get you all available properties that you are work around.

 

Step 5
Practice with some examples.

 

Get the list of all MailboxDatabase with Database Size
Get-MailboxDatabase –Status | Ft Name, DatabaseSize –AutoSize

Get the list of all MailboxDatabase with BackupInProgress Staus
Get-MailboxDatabase –Status | Ft Name, BackupInprogress –AutoSize
 
 
Advanced Level

Get the list of MailboxDatabases for which currently backup is in progress
Get-MailboxDatabase -Status | where {$_.backupinprogress -eq $True}

Get the list of MailboxDatabases whose Database Size is over 1TB
Get-MailboxDatabase -Status | where {$_.DatabaseSize -gt 1TB}

In general, If you know the PropertyName and the condition
Get-MailboxDatabase -Status | where {$_.ProperyName -condition}

To list all properties of a MailboxDatabase.
Get-MailboxDatabase –Identity “Name” -DumpsterStatistics –Status | fl
 
Now when comes to Get-PublicFolderDatabase, it is more or less similar and so let’s add that in your Try yourself list.

For more details on these commands please refer the below links
 https://technet.microsoft.com/en-us/library/bb124924.aspx
https://technet.microsoft.com/en-us/library/aa998827.aspx

So now, we have mastered two commands of Exchange Server 2010.
Stay tuned!