+4 votes
249 views
Mailboxes with Exchange 2010 PowerShell

in Exchange by (552k points)
reopened | 249 views

1 Answer

+5 votes
Best answer

Introduction

With the PowerShell, I can perform an action for an object but I can also do it for 10, 100, or 1,000 objects.
The Exchange 2010 server can have one or more databases, in this case we will connect to a main one. The commands that we will execute can be executed in a single command line.

Excel Sizes and Export

1) Sizes

Let's throw some commands to check the size of the company mailboxes and the Alias. We will be using a sentence that in my opinion is one of the most important for this case in a PowerShell,

Get-MailboxStatistics .

ForEach ($ MailBox In (Get-Mailbox -ResultSize Unlimited))

{

Get-MailboxStatistics -Identity $ MailBox | `

Format-Table @ {Label = "sAMAccountName"; Exp ression = {$ MailBox.sAMAccountName}}, `

@ {Label = "Size"; Exp ression = {$ _. TotalItemSize.Value.ToBytes ()}},

@ {Label = "DeletedSize"; Exp ression = {$ _. TotalDeletedItemSize.Value.ToBytes ()}},

@ {Label = "TotalSize"; Exp ression = {$ _. TotalItemSize.Value.ToBytes () + $ _. TotalDeletedItemSize.Value.ToBytes ()}} -AutoSize

}




2) Export

With these sentences we will be exporting to an Excel, following these sentences we will achieve a successful export.


Add-PsSnapin Microsoft.Exchange.Management.PowerShell.Admin

$ Return = @ ()

ForEach ($ MailBox In (Get-Mailbox -ResultSize Unlimited))

{

$ Statistics = $ null

$ Buzon = New-Object PsCustomObject | Select-Object sAMAccountName, `

Size, `

DeletedSize, `

TotalSize

$ Statistics = Get-MailboxStatistics -Identity $ MailBox -ErrorAction SilentlyContinue

If ($ Statistics -ne $ null)

{

$ Buzon.sAMAccountName = $ MailBox.sAMAccountName

$ Buzon.Size = $ Statistics.TotalItemSize.Value.ToBytes ()

$ Buzon.DeletedSize = $ Statistics.TotalDeletedItemSize.Value.ToBytes ()

$ Buzon.TotalSize = $ Buzon.Size + $ Buzon.DeletedSize

$ Return + = $ Buzon

}

}

$ Return | Export-Csv -Delimiter "," -Path c: usersSOLVETICDocumentsbuzones.csv -NoTypeInformation

$ Return = $ null



To be executed as a scheduled task, it can be saved in a text file of extension "PS1" and it can also be executed from a .bat .

3) Executing the Script

PowerShell executes scripts with extension ".PS1", so that you can write all the code in a Text File with the indicated extension. To edit scripts you only need a text editor. If you want more features such as debugging and seeing the value of the variables in real time, you can use PowerGui.
To execute a PowerShell script we have to indicate its location in an absolute way. There are two ways to do it:
  • From the conventional command line:

powershell. list-mailboxs.ps1



In this case, the script file list-mailboxs.ps1 must be located in the current folder. We have to write the whole path if the script is in another folder that is not the current one:


powershell c: scriptslistar-mailboxs.ps1

  • Or from the PowerShell command line (we are in the same folder as the script):

powershell>. list-mailboxs.ps1

  • Indicating the complete path from the PowerShell command line:

PoweShell> c: scripts list-mailboxs.ps1


Following these steps we can start to handle without any problems, a PowerShell for our sentences on a Microsoft Exchange 2010.

by (3.5m points)

Related questions

+3 votes
1 answer
+4 votes
1 answer
asked Jun 24, 2019 in Exchange by backtothefuture (552k points) | 268 views
+3 votes
1 answer
asked Jun 24, 2019 in Exchange by backtothefuture (552k points) | 295 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users