Showing posts with label Office 365 Exchnage Online. Show all posts
Showing posts with label Office 365 Exchnage Online. Show all posts

Wednesday, June 11, 2014

PowerShell Script : Office 365 Mailbox Sizes and Mailbox Quotas Email Reporting.

 

Picture1

We all love office 365.

Especially I like the Exchange Online most.

On Exchange Online when we create any new mailboxes we do set the various storage limits on the user mailbox and we assign different mailbox size as per the user requirements or company policies.

Sometime, we need to know the reports of:

1.     How much mailbox space is assigned to the user?

2.     How much his currently mail box usage is.

3.     What is the name of mailbox database?

Monitoring and Reporting are the two key main areas in our IT industry. We should monitor our IT stuff and we should often generate and view the reports.

I have created this script to know about the mailbox status of my all Office 365 Exchange Online mailboxes and the current usage of them.  It also contains the information on, Users Last Login time , Log Off time, size of this issue warning quota limit and size of total deleted items.

How to run the script?

It’s simple.

1.     Configure, your SMTP server, TO, FROM, Subject filed in the script.

2.     Run the script

3.     It ask you for your Office 365 Administrator Credentials.

4.     After providing credential, it will send an HTML email to the provided TO email id.

That’s all J Simple. Isnt?

 

You can download the script from Technet Gallery : http://gallery.technet.microsoft.com/scriptcenter/Office-365-Mailbox-Sizes-92b94563

 

#==================| Satnaam Waheguru Ji |===============================   
#
# Author : Aman Dhally
# E-Mail : amandhally@gmail.com
# website : www.amandhally.net
# twitter : @AmanDhally
# blog : http://newdelhipowershellusergroup.blogspot.in/
# facebook: http://www.facebook.com/groups/254997707860848/
# Linkedin: http://www.linkedin.com/profile/view?id=23651495
#
# Creation Date : 03-June-2014
# File : Email Reporting on Office 365 mail Statictic
#
# Version : 3
#
#
# My Pet Spider : /^(o.o)^\
#

#------------------------------------------------------------------------------------------------------------


function Send-O365MailStats {



begin {

try {
Write-Output "$(get-date) : Script Start."
Write-Output "$(get-date) : Asking for Office365 Administrative Credentials."
$UserCredential = Get-Credential
Write-Output "$(get-date) : Creating a Online PS Session with Office 365."
$ouSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection -ErrorAction 'Stop' -ErrorVariable 'ConnectionError'
Write-Output "$(get-date) : Importing PS Session."
Import-PSSession $ouSession -AllowClobber -ErrorAction 'Stop' -ErrorVariable 'SessionError'
}

catch {
$ConnectionError
$SessionError

}
}


process {

try {
#Your SMTP sever
$smtp = 'YOUR EMAIL SERVER'
# To E-Mail Address
$to = 'AMANdhally@gmail.com'
# From E-Mail Address
$from = 'Scripter@YourDOMAIN.COM'
# Subject of the Email
$subject = 'Office 365 MailBox Stats Report'
#Empty Array String
$body2 = @()
#Just a Counter
$int = 1
#All Magic Done here
Write-Output "$(get-date) : Running the Get-Mailbox and Get-MailboxStatistics cmdlet"
$userList = Get-Mailbox -Filter " RecipientType -eq 'UserMailbox'" | Get-MailboxStatistics

#Processing
Write-Output "$(get-date) : Processing the Results."
foreach ( $user in $userList)
{
#$user | fl * -Force

$body2 += "<tr>"
$body2 += "<td>" + $int++ + "</td>"
$body2 += "<td>" + $user.DisplayName + "</td>"

#manuplating
$UserTa= $user.TotalItemSize.value.ToString().split(" ")[0]
$UserTb = $user.TotalItemSize.value.ToString().split(" ")[1]
$userTotalSize = $UserTa + " " + $UserTb

$body2 += "<td>" + $userTotalSize + "</td>"

$body2 += "<td>" + $user.LastLogonTime + "</td>"
$body2 += "<td>" + $user.LastLogoffTime + "</td>"
$body2 += "<td>" + $user.ServerName + "</td>"
$body2 += "<td>" + $user.DatabaseName + "</td>"

#Manuplating
$userDDLa = $user.TotalDeletedItemSize.value.ToString().split(" ")[0]
$userDDLb = $user.TotalDeletedItemSize.value.ToString().split(" ")[1]
$userDelted = $userDDLa + " " + $userDDLb

$body2 += "<td>" + $userDelted + "</td>"

#Manuplated
$userDBa = $user.DatabaseProhibitSendReceiveQuota.value.ToString().split(" ")[0]
$userDBb = $user.DatabaseProhibitSendReceiveQuota.value.ToString().split(" ")[1]
$userDBQuota = $userDBa + " " + $userDBb

$body2 += "<td>" + $userDBQuota + "</td>"

#Manuplating
$userWQa = $user.DatabaseIssueWarningQuota.value.ToString().split(" ")[0]
$userWQb = $user.DatabaseIssueWarningQuota.value.ToString().split(" ")[1]
$userWquota = $userWQa + " " + $userWQb

$body2 += "<td>" + $userWquota+ "</td>"

#Manuplating
$UserDBPa = $user.DatabaseProhibitSendQuota.value.ToString().split(" ")[0]
$UserDBPb = $user.DatabaseProhibitSendQuota.value.ToString().split(" ")[1]
$userDBPS = $UserDBPa + " " + $UserDBPb

$body2 += "<td>" + $userDBPS + "</td>"
$body2 += "</tr>"


}

$body = "<h3>Office 365 {Exchnage Online}, User Mailbox Statics Report.</h3>"
$body += "<br>"
$body += "<br>"
$body += "<table border=2 style=background-color:silver;border-color:black >"
$body += "<tr>"
$body += "<th>S. No</th>"
$body += "<th>Display Name</th>"
$body += "<th>Total Mailbox Size </th>"
$body += "<th>Last LogonTime</th>"
$body += "<th>Last Logoff</th>"
$body += "<th>Server Name </th>"
$body += "<th>Database Name</th>"
$body += "<th>Deleted Item Size</th>"
$body += "<th>Prohibit S/R Quota</th>"
$body += "<th>Issue Warning Quota </th>"
$body += "<th>Prohibit Send Quota</th>"
$body += "</tr>"
$body += $body2
$body += "</table>"

#Sending Email Message to the $to
Write-Output "$(get-date) : Sending the Email."
Send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -UseSsl

}

catch
{

}


}


end {

try {

#Remvoing the Session with Office 365
Write-Output "$(get-date) : Removing PS Session."
Remove-PSSession $ouSession
Write-Output "$(get-date) : Script End."
}

catch {
}
}
}

Send-O365MailStats

# end of the script.


The output should be look like the below screenshot.


09-06-2014 12-57-09


You can download the script from Technet Gallery : http://gallery.technet.microsoft.com/scriptcenter/Office-365-Mailbox-Sizes-92b94563



Regards



Aman Dhally


Come and join my journey of : “100 Days of Self Improvement” on


 


Facebook: https://www.facebook.com/100DoSI 



If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.


Thursday, March 13, 2014

PowerShell Script : KB2692134 - Copy Outlook Contact's Other field data to other contact fields using PowerShell.

 

Quote of the Day: All our dreams can come true – if we have the courage to pursue them. – Walt Disney

 

If you remember, few days ago I have uploaded a script to which access “Outlook” contact’s using PowerShell and I also wrote a blog article on it.

In that post, I have also mention that, Why I need this kind of script to retrieve contacts from the outlook, you may know the answer in my coming blog posts.

 

Now please let me describe to you why I have written that script.

 

If you are an “Exchange 2007, Exchange 2010” administrator, then you must be aware of Microsoft knowledge base article number “KB 2692134”.

 

In “KB2692134” knowledge base Microsoft has mention this.

 

KB2692134

Consider the following scenario:

·         Your mailbox is hosted on a server that is running Microsoft Exchange Server 2007 or Microsoft Exchange Server 2010.

·         You create a new contact in Microsoft Office Outlook 2007.

·         Under Phone numbers, you type a telephone number in the Home and Mobile fields.

·         You click Business, click Other, and then type a telephone number in the Other field.

·         You synchronize your mobile device that uses Microsoft Exchange ActiveSync over-the-air.

In this scenario, the information in the Home and Mobile fields is synchronized as expected. However, the information in theOther field does not synchronize as expected

Cause

This issue occurs because the Exchange ActiveSync protocol does not support synchronizing some contact information.

More Information

The behaviour that is mentioned in the "Symptoms" section can occur if you change the field name for any of the default fields. For example, if you click Business, Home, Business FAX, or Mobile, and then change the field name to Other, the data is not synchronized as expected.

The following table summarizes the field names that will synchronize and that will not synchronize as expected:

Field names that will synchronize

Field names that will not synchronize

Company

Assistant

Pager

Callback

Business

Car

Business 2

ISDN

Business Fax

Other Fax

Home

Primary

Home 2

Other

Home Fax

Radio

Mobile

Telex

 

 

 

In nutshell, if you are running “Microsoft Exchange Server 2007” or “Microsoft Exchange Server 2012” , and if some of you user has telephone  number on there “Other” field of  Outlook contacts, they can’t see them on any device  which they has configure their email account using Active Sync.

 

Note: I am not sure, but I do believe “office 365 Exchange Online has a same issue too. {I tested this on iPhone + Office 365}”

 

Here comes the problem, if that user is your BOSS or Manager and he/she has an important telephone numbers in his/her Outlook contact’s  “other” , now what you will do? Show him/her the KB article? Do you think that going to work?

No! I am right, you have to do that.

 

If you check the above table, in the table “Field Names that will synchronize” we have two fields which normally most of the person won’t use, “Business 2” and “Home 2”.

What if? If we move the data from “Other” field to “Business 2” or “Home 2”.field.

Sound interesting? Yes it is. You like it, yes? Cool, now go and write a script to do it.  ;o) 

 

Don’t worry, I already done that for you too. You can download the script from the below link:

Download link : http://gallery.technet.microsoft.com/Copy-Other-field-data-of-e35891a0

How this script work.

 

This script run on a user’s laptop, it use the Outlook’s “Outlook. Application” as com object and bind it with PowerShell and do the further task.

How to use it.

 

Note: Before running it on a user’s laptop, make sure you backup his contact’s first.

I have tested this script on “windows 8.1” and with “Outlook 2013” installed and I do hope it worked well on “Windows 7” and with “Outlook 2010”.

In the screenshots, the script name is different, don’t worry, I have just renamed it after taking the screenshot.

 

You can see, in below screenshot that contact “Gobind”,”Aman” and Romy” has a data in there “Other Phone” field.

13-03-2014 17-04-17

Figure 1 Screenshot of  Outlook contacts, you can, see some has phone numbers in “Other Phone” , and some in “Business 2” and some in “Home 2”

 

Run the script, and you can see that, it will show you the list of all contacts, with their “other TelephoneNumber”, “FullName” , “First Name” and “Email Address field”.

13-03-2014 17-08-53

Figure 2 Script run, but no change has made, because “Edit-OtherOutlookContact” function is commented in the original script.”

 

Now open the script and uncomment the below “Edit-OtherOutlookCOntact” function and save the script file.

 

13-03-2014 17-10-37

Figure 3 Screenshot of the commented function

To

13-03-2014 17-11-33

Figure 4 Screenshot of the Function after un-commenting. {# removed from front of it}

 

Now run the script again, you can see, it done some changes on “Aman”, “Romy”, and “Gobind” contact names.

 

13-03-2014 17-13-16

Figure 5 , we run the script again, and you can see, that it is showing that, it is changing the comments and it also opened a text file, which has the name of the contacts which we have just changed.

 

When this script run, it saved the list of all users name those other fields are moved to either “Home 2” or “Business 2”.  This files open automatically when It changes anything, by default this file saves at:  "$env:APPDATA\ChangedContactList.txt"   , and the name of the file is ChangedContactList.txt”.

 

Let’s check our Outlook contacts.

You can see that. All or number from “Other” fields are either move to “Home 2” or Business 2”.

 

13-03-2014 17-27-03

Figure 6 Changes are made by the script. You can see that,

 

Remember: before moving number to “Home 2” or “Business 2”, this script check for existing data in any of these contact fields.

In-case if data is exists in “Home 2”, it will move the “Other” field data to “Business 2”, if “Business 2” has some data, then it try to save the data to “Home 2” fields.

 

What if? Home 2 and Business 2 both have the data.

In that case, it will create a text file named NotChangedContactList.txt" and open it for you , so that you can decide what to do next.

13-03-2014 17-29-03

Figure 7 If “Home 2” and “Business 2” fields are not blank, it will save the name of those contacts which has data in there “Other” filed and save it in to a file.

 

This file saves in the same location: "$env:APPDATA\NotChangedContactList.txt"

 

If you want to retain the data of the “Other” field. Then delete or uncomment the below scipt code in the script.

 

$name.OtherTelephoneNumber = $null ;

 

That’s all for toady and happy scripting.

 

clip_image016Download link : http://gallery.technet.microsoft.com/Copy-Other-field-data-of-e35891a0

 

Thanks for reading this post, I hope you will find it useful.

 

clip_image018

Regards

Aman Dhally

 

 

If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.