

#------------------------------------------------------------------------------
# THIS CODE AND ANY ASSOCIATED INFORMATION ARE PROVIDED AS IS WITHOUT
# WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
# FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE, INABILITY TO USE, OR 
# RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#
# AUTHOR(s):
#       Eyal Doron (o365info.com)
#------------------------------------------------------------------------------
# Hope that you enjoy it ! 
# And May the force of PowerShell will be with you   :-)
# 05-05-2014    
# Version WP- 001 
#------------------------------------------------------------------------------


Function Disconnect-ExchangeOnline {Get-PSSession | Where-Object {$_.ConfigurationName -eq "Microsoft.Exchange"} | Remove-PSSession}
function Validate-UserSelection
{
    Param(
        $AllowedAnswers,
        $ErrorMessage,
        $Selection
    )
    foreach($str in $AllowedAnswers.ToString().Split(","))
    {
        if($str -eq $Selection)
        {
            return $true
        }
    }
    Write-Host $ErrorMessage -ForegroundColor Red -BackgroundColor Black
    return $false

}

function Format-BytesInKiloBytes 
{
    param(
        $bytes
    )
    "{0:N0}" -f ($bytes/1000)
}

Function Set-AlternatingRows {
       <#
       
       #>
    [CmdletBinding()]
       Param(
             [Parameter(Mandatory=$True,ValueFromPipeline=$True)]
        [string]$Line,
       
           [Parameter(Mandatory=$True)]
             [string]$CSSEvenClass,
       
        [Parameter(Mandatory=$True)]
           [string]$CSSOddClass
       )
       Begin {
             $ClassName = $CSSEvenClass
       }
       Process {
             If ($Line.Contains("<tr>"))
             {      $Line = $Line.Replace("<tr>","<tr class=""$ClassName"">")
                    If ($ClassName -eq $CSSEvenClass)
                    {      $ClassName = $CSSOddClass
                    }
                    Else
                    {      $ClassName = $CSSEvenClass
                    }
             }
             Return $Line
       }
}


$FormatEnumerationLimit = -1


#------------------------------------------------------------------------------
# PowerShell console window Style
#------------------------------------------------------------------------------

$pshost = get-host
$pswindow = $pshost.ui.rawui

	$newsize = $pswindow.buffersize
	
	if($newsize.height){
		$newsize.height = 3000
		$newsize.width = 150
		$pswindow.buffersize = $newsize
	}

	$newsize = $pswindow.windowsize
	if($newsize.height){
		$newsize.height = 50
		$newsize.width = 150
		$pswindow.windowsize = $newsize
	}

#------------------------------------------------------------------------------
# HTML Style start 
#------------------------------------------------------------------------------
$Header = @"
<style>
Body{font-family:segoe ui,arial;color:black; }
H1{ color: white; background-color:#1F4E79; font-weight:bold;width: 70%;margin-top:35px;margin-bottom:25px;font-size: 22px;padding:5px 15px 5px 10px; }
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 5px;border-style: solid;border-color: #d1d3d4;background-color:#0072c6 ;color:white;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
.odd  { background-color:#ffffff; }
.even { background-color:#dddddd; }
</style>

"@

#------------------------------------------------------------------------------
# HTML Style END
#------------------------------------------------------------------------------



$Loop = $true
While ($Loop)
{
    write-host 
    write-host ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    write-host   " Exchange Online: Display and Export information  | PowerShell Script menu"  
    write-host ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    write-host
    write-host -ForegroundColor green  'Connect PowerShell session to AD Azure and Exchange Online' 
    write-host -ForegroundColor green  '--------------------------------------------------------------' 
    write-host -ForegroundColor Yellow ' 0)   Login in using your Office 365 Administrator credentials' 
    write-host
    write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue 'Section A:  Display information by Mailbox Type ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 1)   Display List of all Mailboxes type'
	write-host                                              ' 2)   Display List of Office 365 Users Mailboxes'
	write-host                                              ' 3)   Display List of Room Mailboxes'
	write-host                                              ' 4)   Display List of Equipment Mailboxes'
	write-host                                              ' 5)   Display List of Shared Mailboxes'
	write-host                                              ' 6)   Count the Mailboxes number'
	write-host 
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue 'Section B: Find and display information about Email address  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 7)   Display recipients Primary + Alias Email Address + SIP Address'
	write-host                                              ' 8)   Display Office 365 users UPN names'
	write-host                                              ' 9)   Find: Mail recipients with specific Domain name suffix'
	write-host                                              ' 10)  Find: Mail recipients with specific Alias'
	write-host                                              ' 11)  Find: Mail recipients with specific Alias + Domain name suffix'
	write-host                                              ' 12)  Find: Mailboxes with specific Usage Location'
	
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue 'Section C: View Mailbox Statistics  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 13)  View Specific Mailbox Statistics'
	write-host                                              ' 14)  View Mailbox Statistics of All Office 365 Mailboxes'
	write-host                                              ' 15)  View all quotas assigned to a Mailbox'
	write-host                                              ' 16)  View all quotas assigned to ALL Mailboxes '
	write-host                                              ' 17)  View all quotas assigned to a Archive Mailbox'
	write-host                                              ' 18)  View Statistic of all Archive Mailboxes'
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section D:  Display Mail recipients  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 19)  Display list of Distribution Groups '
	write-host                                              ' 20)  Display list of Mail contacts'
	write-host  
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section E: Export information about Mailboxs to file (CSV Format)  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 21)  Export information about Mail recipients to file(CSV format)'
	
	
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor Blue  -BackgroundColor Yello ' Exit\Disconnect ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host  -ForegroundColor Yellow                       ' 22)  Disconnect PowerShell session'
	write-host 
	write-host  -ForegroundColor Yellow                       ' 23)  Exit'
	write-host 
	write-host                                          

	

    $opt = Read-Host "Select an option [0-23]"
    write-host $opt
    switch ($opt) 


{


		#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		# Step -00 |  Create a Remote PowerShell session to AD Azure and Exchange Online
		#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


		0
        {

            # Specify your administrative user credentials on the line below 

            $user = Admin@.....

            # This will pop-up a dialogue and request your password
            

            # Import the Local Microsoft Online PowerShell Module Cmdlets and  Establish an Remote PowerShell Session to AD Azure  
            
            Import-Module MSOnline

            

            # Establish an Remote PowerShell Session to Exchange Online 

            $msoExchangeURL = https://ps.outlook.com/powershell/
			$connected = $false
			$i = 0
			while ( -not ($connected)) {
				$i++
				if($i -eq 4){
					
										
					Write-host
					Write-host -ForegroundColor White	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
					Write-host -ForegroundColor Red    "Too many incorrect login attempts. Good bye."	
					Write-host
					Write-host -ForegroundColor White	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
					
					
					exit
				}
				$cred = Get-Credential -Credential $user
				try 
				{
					$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $msoExchangeURL -Credential $cred -Authentication Basic -AllowRedirection  -ErrorAction stop
					Connect-MsolService -Credential $cred -ErrorAction stop
					Import-PSSession $session 
					$connected = $true 
				}
				catch 
				{
					Write-host
					Write-host -ForegroundColor Yellow	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
					Write-host -ForegroundColor Red    "There is something wrong with the global administrator credentials"	
					Write-host
					Write-host -ForegroundColor Yellow	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
				}
			}
            
			$host.ui.RawUI.WindowTitle = ("Windows Azure Active Directory |Connected to Office 365 using: " + $Cred.UserName.ToString()  ) 
        }



		
		#+++++++++++++++++++++++++++++++++++++++++++++++++
		# Section A: XXXXXXXXXXXXXXXXXXXXXXXXXXXX
		#+++++++++++++++++++++++++++++++++++++++++++++++++

		

#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section A:  Display information by Mailbox Type
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<






1{


#####################################################################
#   Display List of all Mailboxes type
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display List of all Mailboxs type '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command


# Section 4:  Indication 

write-host
write-host


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 Display List of all Mailboxs type
write-host ---------------------------------------------------------------------------

Get-Mailbox -ResultSize Unlimited  | Where {$_.name -notlike '*DiscoverySearchMailbox*'} | Out-String


#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}






2{


#####################################################################
#  Display List of Office 365 Users Mailboxes 
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display List of Office 365 Users Mailboxs  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	"Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' | Select RecipientTypeDetails,Name, Alias  "
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command


# Section 4:  Indication 

write-host
write-host


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display List of Office 365 Users Mailboxs 
write-host ---------------------------------------------------------------------------

Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' | Select RecipientTypeDetails,Name, Alias  | Out-String


#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}



3{


#####################################################################
#  Display List of Room Mailboxes
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display List of Room Mailboxs '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	"Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Select Name, Alias  "
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command


# Section 4:  Indication 

write-host
write-host


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 Display List of Room Mailboxs
write-host ---------------------------------------------------------------------------



Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Select Name,Alias  | Out-String



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}


4{


#####################################################################
#  Display List of Equipment Mailboxes
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display List of Equipment Mailboxs '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	"Get-Mailbox -Filter '(RecipientTypeDetails -eq "EquipmentMailbox")' | Select Name, Alias  "
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command


# Section 4:  Indication 

write-host
write-host


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 Display List of Equipment Mailboxs
write-host ---------------------------------------------------------------------------



Get-Mailbox -Filter '(RecipientTypeDetails -eq "EquipmentMailbox")' | Select Name, Alias | Out-String



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}


5{


#####################################################################
#  Display List of Shared Mailboxes
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display List of Shared Mailboxs '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	"Get-Mailbox -Filter '(RecipientTypeDetails -eq "SharedMailbox")' | Select RecipientTypeDetails,Name, Alias  "
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command


# Section 4:  Indication 

write-host
write-host


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 List of Shared Mailboxs
write-host ---------------------------------------------------------------------------


Get-Mailbox -Filter '(RecipientTypeDetails -eq "SharedMailbox")' | Select RecipientTypeDetails,Name, Alias | Out-String



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}




6{


#####################################################################
#  Count the Mailboxes number 
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Count the Mailboxs number  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'(Get-Mailbox -ResultSize Unlimited).Count '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command



# Section 4:  Indication 

write-host
write-host


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 Count the Mailboxs number 
write-host ---------------------------------------------------------------------------

(Get-Mailbox -ResultSize Unlimited).Count 





#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}





#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section B: Find and display information about Email Address
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



7{


#####################################################################
#  Display recipients Primary + Alias Email Address + SIP Address
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display recipients Primary + Alias Email Address  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox   -ResultSize Unlimited  | Where {$_.name -notlike '*DiscoverySearchMailbox*'} |FL EmailAddresses'
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command


# Section 4:  Indication 

write-host
write-host


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 Display recipients Primary + Alias Email Address 
write-host ---------------------------------------------------------------------------


Get-Mailbox -ResultSize Unlimited  | Where {$_.name -notlike '*DiscoverySearchMailbox*'} |FL EmailAddresses | Out-String



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}



8{


#####################################################################
#  Display Office 365 users UPN names
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display Office 365 users UPN name  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-MsolUser |Select-Object DisplayName, UserPrincipalName'
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command


# Section 4:  Indication 

write-host
write-host


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	  List of Office 365 users UPN names
write-host ---------------------------------------------------------------------------


Get-MsolUser |Select-Object DisplayName, UserPrincipalName


#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}





9{


#####################################################################
#Find: Mail recipients with specific Domain name suffix
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Find: Mail recipients with specific Domain name suffix   '
write-host  -ForegroundColor white  	'The information will include:  '
write-host  -ForegroundColor white  	'*Office 365 user UPN name that have the specific domain name suffix '
write-host  -ForegroundColor white  	'*Mailboxes - that have the specific domain name suffix '
write-host  -ForegroundColor white  	'*Distribution Groups - that have the specific domain name suffix '
write-host  -ForegroundColor white  	'*Contacts - that have the specific domain name suffix '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to Provide 1 parameter:"  
write-host
write-host -ForegroundColor Yellow	"1) Domain name suffix name"  
write-host -ForegroundColor Yellow	"   For example: o365info.com"
write-host
$domname = Read-Host "Type the Domain name suffix name  "
write-host

# Section 3: PowerShell Command





# Section 4: Display Information

write-host
write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Office 365 users that have UPN With $domname.ToUpper() Domain name  
write-host ---------------------------------------------------------------------------

#get-msoluser  | Where {$_.UserPrincipalName -like "*$alias*"}


Get-MsolUser -DomainName $domname | FL   UserPrincipalName   | Out-String


write-host
write-host

write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white MailBox Email Addresses that incloude $domname.ToUpper()  Domain name
write-host ---------------------------------------------------------------------------

Get-Mailbox | Where {$_.emailaddresses -like "*$domname*"} | FL  -Property Name,alias,EmailAddresses     | Out-String 

 




write-host
write-host


write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Distribution Groups Email Addresses that incloude $domname.ToUpper()  Domain name
write-host ---------------------------------------------------------------------------

write-host
Get-DistributionGroup | Where {$_.PrimarySmtpAddress -like "*$domname*"} | FL  -Property Name,EmailAddresses  | Out-String


# Format-Table -Property Path,Name,Id,Company -

write-host
write-host

write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Contacts Email Addresses that incloude $domname.ToUpper()  Domain name
write-host ---------------------------------------------------------------------------

Get-mailcontact | Where {$_.PrimarySmtpAddress -like "*$domname*"} | FL  -Property Name,alias ,EmailAddresses | Out-String

write-host
write-host

write-host ---------------------------------------------------------------------------


#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}





10{


#####################################################################
#Find: Mail recipients with specific Alias
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Find: Mail recipients with specific Alias  '
write-host  -ForegroundColor white  	'The information will include:  '
write-host  -ForegroundColor white  	'*Mailboxes - that have the specific Alias'
write-host  -ForegroundColor white  	'*Distribution Groups - that have the specificAlias '
write-host  -ForegroundColor white  	'*Contacts - that have the specific Alias '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to Provide 1 parameter:"  
write-host -ForegroundColor Yellow	"1) Alias name"  
write-host -ForegroundColor Yellow	"   For example: John"
write-host
$alias = Read-Host "Type the Alias name  "
write-host
# Section 3: PowerShell Command





# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	MailBox with Email Addresses that incloude the $alias.ToUpper()  Alias name
write-host ---------------------------------------------------------------------------

Get-Mailbox | Where {$_.emailaddresses -like "*$alias*"} | FL  Name, alias ,EmailAddresses     | Out-String 

write-host
write-host


write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Distribution Groups with Email Addresses that incloude the $alias.ToUpper()  Alias name
write-host ---------------------------------------------------------------------------

write-host
Get-DistributionGroup | Where {$_.PrimarySmtpAddress -like "*$alias*"} | FL   Name, alias ,EmailAddresses  | Out-String


# Format-Table -Property Path,Name,Id,Company -

write-host
write-host

write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 Contacts with Email Addresses that incloude the $alias.ToUpper()  Alias name
write-host ---------------------------------------------------------------------------

Get-Mailcontact | Where {$_.PrimarySmtpAddress -like "*$alias*"} | FL  Name, alias ,EmailAddresses | Out-String

write-host
write-host

write-host ---------------------------------------------------------------------------


#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}









11{


#####################################################################
# Find: Mail recipients with specific Alias + Domain name suffix
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Find: Mail recipients with specific Alias + Domain name suffix  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox | Where { $_.Name -like "*$alias*" -and $_.EmailAddresses -like "*$domname*" }  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



write-host -ForegroundColor Yellow	"You will need to Provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) Domain name suffix name"  
write-host -ForegroundColor Yellow	"   For example: o365info.com"
write-host
$domname = Read-Host "Type the Domain name suffix name  "
write-host
write-host -ForegroundColor Yellow	"2) Alias name"  
write-host -ForegroundColor Yellow	"   For example: John"
write-host
$alias = Read-Host "Type the Alias name  "
write-host
# Section 3: PowerShell Command





# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	MailBox Email Addresses that incloude the $alias.ToUpper() Alias name and $domname.ToUpper() Alias name
write-host ---------------------------------------------------------------------------

Get-Mailbox | Where { $_.Name -like "*$alias*" -and $_.EmailAddresses -like "*$domname*" }  | FL  Name, alias ,EmailAddresses   | Out-String 

write-host
write-host




#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}


12{


#####################################################################
# Find: Mailboxs with specific Usage Location
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Find: Mailboxs with specific Usage Location  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox | Where { $_.UsageLocation -like "*$Usage*"  }  | FL  Name, alias ,EmailAddresses ,UsageLocation   '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to Provide 1 parameter:"  
write-host -ForegroundColor Yellow	"1) Usage Location"  
write-host -ForegroundColor Yellow	"   For example: USA"
write-host
$Usage = Read-Host "Type the Alias name  "
write-host
# Section 3: PowerShell Command



# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	MailBoxs that with  $Usage.ToUpper()  UsageLocation
write-host ---------------------------------------------------------------------------

Get-Mailbox | Where { $_.UsageLocation -like "*$Usage*"  }  | FL  Name, alias ,EmailAddresses ,UsageLocation  | Out-String 

write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}


#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section C: View Mailbox Statistics
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


13{


#####################################################################
# View Specific Mailbox Statistics 
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display Specific Mailbox Statistics   '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-MailboxStatistics <Mailbox> | FL DisplayName ,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount   '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to Provide 1 parameter:"  
write-host -ForegroundColor Yellow	"1) Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: John"
write-host
$MB = Read-Host "Type the Mailbox name  "
write-host
# Section 3: PowerShell Command



# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display $MB.ToUpper()  Mailbox Statistics   
write-host ---------------------------------------------------------------------------

Get-MailboxStatistics $MB | FL DisplayName ,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount       | Out-String 
 
write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}


14{


#####################################################################
# View Mailbox Statistics of All Office 365 Mailboxes
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'DisplayMailbox Statistics of All Office 365 Mailboxes   '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


# Section 3: PowerShell Command



# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 Mailbox Statistics of All Office 365 Mailboxes
write-host ---------------------------------------------------------------------------

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select DisplayName,StorageLimitStatus,@{name="TotalItemSize (MB)";expression={[math]::Round(($_.TotalItemSize.Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},@{name="TotalDeletedItemSize (MB)";expression={[math]::Round(($_.TotalDeletedItemSize.Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},ItemCount,DeletedItemCount | Sort "TotalItemSize (MB)" -Descending       | Out-String 

write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}



15{


#####################################################################
#  View all quotas assigned to a Mailbox
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display all quotas assigned to a Mailbox   '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox <Mailbox> | FL *Quota   '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to Provide 1 parameter:"  
write-host -ForegroundColor Yellow	"1) Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: John"
write-host
$MB = Read-Host "Type the Mailbox name  "
write-host
# Section 3: PowerShell Command



# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display all quotas assigned to $MB.ToUpper() Mailbox    
write-host ---------------------------------------------------------------------------

Get-Mailbox $MB | FL *Quota      | Out-String 

# Get-Mailbox <Mailbox> | FL *Quota  


write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}



16{


#####################################################################
# View all quotas assigned to ALL Mailboxs
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'View all quotas assigned to ALL Mailboxs   '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited | FL DisplayName,alias, *Quota   '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input

# Section 3: PowerShell Command



# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display all quotas assigned to $MB.ToUpper() Mailbox    
write-host ---------------------------------------------------------------------------

Get-Mailbox -ResultSize Unlimited | FL DisplayName, alias, *Quota     | Out-String 

write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}


17{


#####################################################################
# View all quotas assigned to a Archive Mailbox
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display all quotas assigned to a Archive Mailbox  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-MailboxStatistics <Mailbox> -Archive | FL DisplayName,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to Provide 1 parameter:"  
write-host -ForegroundColor Yellow	"1) Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: John"
write-host
$MB = Read-Host "Type the Mailbox name  "
write-host
# Section 3: PowerShell Command



# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display all quotas assigned to $MB.ToUpper() Mailbox    
write-host ---------------------------------------------------------------------------

Get-MailboxStatistics $MB -Archive | FL DisplayName,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount   | Out-String 

write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}



18{


#####################################################################
#View Statistic of all Archive Mailboxes
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'DisplayMailbox Statistics of All Office 365 Mailboxes   '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


# Section 3: PowerShell Command



# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 Mailbox Statistics of All Office 365 Mailboxes
write-host ---------------------------------------------------------------------------

Get-Mailbox -Archive -ResultSize Unlimited | Get-MailboxStatistics -Archive | Select DisplayName,StorageLimitStatus,@{name="TotalItemSize (MB)";expression={[math]::Round(($_.TotalItemSize.Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},@{name="TotalDeletedItemSize (MB)";expression={[math]::Round(($_.TotalDeletedItemSize.Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},ItemCount,DeletedItemCount | Sort "TotalItemSize (MB)" -Descending       | Out-String 

write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}


#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#Section D:  Display Mail recipients 
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


19{


#####################################################################
# Display list of Distribution Groups
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display list of Distribution Groups   '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-DistributionGroup | FL  Name,DisplayName,GroupType,PrimarySmtpAddress  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


# Section 3: PowerShell Command



# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 Display list al all distribution groups
write-host ---------------------------------------------------------------------------

Get-DistributionGroup | FL  Name,DisplayName,GroupType,PrimarySmtpAddress |Out-String 

write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}





20{


#####################################################################
# Display list of Mail contacts
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	' Display list of Mail contacts   '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailcontact   '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


# Section 3: PowerShell Command



# Section 4: Display Information



write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	  Display list of Mail contacts
write-host ---------------------------------------------------------------------------

Get-Mailcontact     | Out-String 

write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}


#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section F: Export information about Mailboxes to file (CSV Format) 
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



21{

#####################################################################
# Export information about Mail recipients to file(CSV format)
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'1. Automatically create folder named: INFO in C drive '
write-host  -ForegroundColor white  	'2. Export all of the information to a CSV Files '
write-host  -ForegroundColor white  	'3. Open the INFO folder in the explorer  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


# Section 3: PowerShell Command



# Section 4: Display Information



if (!(Test-Path -path C:\INFO))
{
New-Item C:\INFO\ -type directory
}



Get-DistributionGroup | Export-Csv c:\info\o365-Distribution-Group.csv

Get-mailcontact | Export-Csv c:\info\o365-Mail-Contact.csv

Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' | Select RecipientTypeDetails,Name, Alias  |  Export-Csv c:\info\o365-User-Mailbox.csv
Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Select Name, Alias  |  Export-Csv c:\info\o365-Room-Mailbox.csv
Get-Mailbox -Filter '(RecipientTypeDetails -eq "EquipmentMailbox")' | Select Name, Alias | Export-Csv c:\info\o365-Equipment-Mailbox.csv
Get-Mailbox -Filter '(RecipientTypeDetails -eq "SharedMailbox")' | Select RecipientTypeDetails,Name, Alias | Export-Csv c:\info\o365-Shared-Mailbox.csv


explorer.exe c:\info

write-host
write-host



#Section 5: End the Command
write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host

}


 
		
						
				 
				#+++++++++++++++++++
				# Step -05 Finish  
				##++++++++++++++++++
				 
				 
				22{

				##########################################
				# Disconnect PowerShell session  
				##########################################


				write-host -ForegroundColor Yellow Choosing this option will Disconnect the current PowerShell session 

				Function Disconnect-ExchangeOnline {Get-PSSession | Where-Object {$_.ConfigurationName -eq "Microsoft.Exchange"} | Remove-PSSession}
				Disconnect-ExchangeOnline -confirm

				write-host
				write-host

				# Indication 

				if ($lastexitcode -eq 0)
				{
					write-host -------------------------------------------------------------
					write-host "The command complete successfully !" -ForegroundColor Yellow
					write-host "The PowerShell session is disconnected" -ForegroundColor Yellow
					write-host -------------------------------------------------------------
				}
				else

				{
					write-host "The command Failed :-(" -ForegroundColor red
					
				}

				# End of Indication 


				}




				23{

				##########################################
				# Exit  
				##########################################


				$Loop = $true
				Exit
				}

				}


				}
