

#------------------------------------------------------------------------------
# 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   :-)
# 01-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   "Disable Services  | 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: OWA Access ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 1)   Disable User access to OWA'
	write-host                                              ' 2)   Disable access to OWA for all Office 365 users (BULK Mode)'
	write-host 
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue 'Section B: POP3/IMAP4 Access  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 3)   Disable User access to POP3/IMAP4'
	write-host                                              ' 4)   Disable access to POP3/IMAP4 for all Office 365 users (BULK Mode)'
	write-host 
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section C: ActiveSync Access  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 5)   Disable User access to ActiveSync'
	write-host                                              ' 6)   Disable access to ActiveSync for all Office 365 users (BULK Mode)'
	write-host 
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section D: Outlook AnyWhere Access  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 7)  Disable User access to Outlook AnyWhere'
	write-host                                              ' 8)  Disable Outlook AnyWhere Access for all Office 365 users (BULK Mode)'
	write-host 
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section E: Office 365 user account  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 9)   Disable Office 365 user account'
	write-host 
	Write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section F: Access to PowerShell  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 10)  Disable access to PowerShell'
	write-host 
	Write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue '  Section G: Display information  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 11)  Display information about User (Mailbox) Services'
	write-host                                              ' 12)  Display information about ALL Users (Mailboxs) Services'
	write-host                                              ' 13)  Display information about Locked users account'
	write-host 
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor Blue  -BackgroundColor Yello ' Exit\Disconnect ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host  -ForegroundColor Yellow                       ' 14)  Disconnect PowerShell session'
	write-host 
	write-host  -ForegroundColor Yellow                       ' 15)  Exit'
	write-host 
	write-host                                          

	

    $opt = Read-Host "Select an option [0-15]"
    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: Access to OWA
		#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


		1
		{


		#####################################################################
		#   Disable MailBox(User) access to OWA
		#####################################################################

		# 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  	"The following option will Disable user Access to: OWA. " 
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Set-CASMailbox  <User> -OWAEnabled $False'
		write-host  -ForegroundColor white		----------------------------------------------------------------------------  	
		write-host  -ForegroundColor white  	"If you want to re enable the OWA access, use the command with the parameter: $True "
		write-host  -ForegroundColor Yellow  	'Set-CASMailbox  <User> -OWAEnabled $True '
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
		write-host
		write-host


		
		# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Mailbox ( User) identity  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$UserAlias  = Read-Host "Type the Mailbox (user) name "
					write-host
					

					# Section 3: PowerShell Command

					Set-CASMailbox  "$UserAlias" -OWAEnabled $False

					# Section 4:  Indication 

						write-host
						write-host

						If ($lastexitcode -eq 1)
						{
							write-host "The command Failed :-(" -ForegroundColor red
						}
						Else
						{
							write-host -------------------------------------------------------------
							write-host -ForegroundColor Yellow	"The command complete successfully !" 
							write-host
							write-host -ForegroundColor Yellow	"access to: " -nonewline; write-host "OWA(Outlook Web App)".ToUpper() -ForegroundColor White	 
							write-host -ForegroundColor Yellow	"Was disabled for: "	-nonewline; write-host "$UserAlias".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Mailbox  "	
							write-host -------------------------------------------------------------
						}

						# End of Indication 

						# Section 4: Display Information

						write-host
						write-host ---------------------------------------------------------------------------
						write-host -ForegroundColor white	Available mail service for: "$UserAlias".ToUpper() Mailbox
						write-host ---------------------------------------------------------------------------

						Get-CASMailbox  $UserAlias | Out-String


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

		}



		2
		{


		#####################################################################
		# Disable access to OWA for all Office 365 users (BULK Mode)
		#####################################################################

		# 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  	"The following option will Disable Access to: OWA for ALL Office 365 users. " 
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Get-mailbox | Set-CASMailbox -OWAEnabled $False'
		write-host  -ForegroundColor white		----------------------------------------------------------------------------  	
		write-host  -ForegroundColor white  	"If you want to re enable the OWA access, use the command with the parameter: $True "
		write-host  -ForegroundColor Yellow  	'Get-mailbox | Set-CASMailbox -OWAEnabled $True'
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo           
		                            
		write-host
		write-host


		# Section 3: PowerShell Command

		Get-Mailbox -ResultSize Unlimited |  Set-CASMailbox -OWAEnabled $False



		# Section 4:  Indication 

		write-host
		write-host

		If ($lastexitcode -eq 1)
		{
			write-host "The command Failed :-(" -ForegroundColor red
		}
		Else
		{
			write-host -------------------------------------------------------------
			write-host -ForegroundColor Yellow	"The command complete successfully !" 
			write-host
			write-host -ForegroundColor Yellow	"access to: " -nonewline; write-host "OWA(Outlook Web App)".ToUpper() -ForegroundColor White	 
			write-host -ForegroundColor Yellow	"Was disabled for ALL Office 365 users. "		
			write-host -------------------------------------------------------------
		}

		# End of Indication 

		# Section 4: Display Information

		write-host
		write-host ---------------------------------------------------------------------------
		write-host -ForegroundColor white	"Display  Available Mail service for: ALL Office 365 users"
		write-host ---------------------------------------------------------------------------

		Get-CASMailbox | 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

}




	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	# Section B: POP3/IMAP4 Access 
	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	3
	{


			#####################################################################
			#  Disable User access to POP3/IMAP4 
			#####################################################################

			# 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  	"The following option will Disable user Access to: POP3/IMAP4. " 
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Set-CASMailbox  <User> -imapenabled $False -popenabled $False'
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  	
			write-host  -ForegroundColor white  	"If you want to re enable the POP3/IMAP4 access, use the command with the parameter: $True "
			write-host  -ForegroundColor Yellow  	'Set-CASMailbox  <user> -imapenabled $True -popenabled $True'
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo        
			                           
			write-host
			write-host


			
					# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Mailbox ( User) identity  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$UserAlias  = Read-Host "Type the Mailbox (user) name "
					write-host

			# Section 3: PowerShell Command

			Set-CASMailbox  "$UserAlias" -imapenabled $False -popenabled $False


			# Section 4:  Indication 

			write-host
			write-host

			If ($lastexitcode -eq 1)
			{
				write-host "The command Failed :-(" -ForegroundColor red
			}
			Else
			{
				write-host -------------------------------------------------------------
				write-host -ForegroundColor Yellow	"The command complete successfully !" 
				write-host
				write-host -ForegroundColor Yellow	"Access to: " -nonewline; write-host "POP3 and IMAP4".ToUpper() -ForegroundColor White	 
				write-host -ForegroundColor Yellow	"Was disabled for: "	-nonewline; write-host "$UserAlias".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Mailbox  "	
				write-host -------------------------------------------------------------
			}

			# End of Indication 

			# Section 4: Display Information

			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	Available mail service for: "$UserAlias".ToUpper() Mailbox
			write-host ---------------------------------------------------------------------------

			Get-CASMailbox  $UserAlias | Out-String


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

		}


		4
		{


		#####################################################################
		# Disable access to POP3/IMAP4 for all Office 365 users (BULK Mode)
		#####################################################################

		# 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  	"The following option will Disable Access to: POP3/IMAP4 for ALL Office 365 users. " 
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -PopEnabled $False -ImapEnabled $False'
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  	
			write-host  -ForegroundColor white  	"If you want to re enable the POP3/IMAP4 access, use the command with the parameter: $True "
			write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -PopEnabled $True -ImapEnabled $True'
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo     
			write-host


				# Section 3: PowerShell Command

				Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -PopEnabled $True -ImapEnabled $True 

				#--Additional Syntax----
				#$Mailboxes = Get-Mailbox -ResultSize Unlimited
				#ForEach ($Mailbox in $Mailboxes) {$Mailbox | Set-CASMailbox -PopEnabled $False -ImapEnabled $False }


				# Section 4:  Indication 

				write-host
				write-host

				If ($lastexitcode -eq 1)
				{
					write-host "The command Failed :-(" -ForegroundColor red
				}
				Else
				{
					write-host -------------------------------------------------------------
					write-host -ForegroundColor Yellow	"The command complete successfully !" 
					write-host
					write-host -ForegroundColor Yellow	"access to: " -nonewline; write-host "POP3 and IMAP4".ToUpper() -ForegroundColor White	 
					write-host -ForegroundColor Yellow	"Was disabled for ALL Office 365 users. "		
					write-host -------------------------------------------------------------
				}

				# End of Indication 

				# Section 4: Display Information

				write-host
				write-host ---------------------------------------------------------------------------
				write-host -ForegroundColor white	"Display  Available Mail service for: ALL Office 365 users"
				write-host ---------------------------------------------------------------------------

				Get-CASMailbox | 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

		}


	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	# Section C: ActiveSync Access
	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	5
	{


			#####################################################################
			#  Disable MailBox(User) access to  ActiveSync 
			#####################################################################

			# 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  	"The following option will Disable user Access to: ActiveSync . " 
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Set-CASMailbox  <user> -ActiveSyncEnabled $False'
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  	
			write-host  -ForegroundColor white  	"If you want to re enable the ActiveSync access, use the command with the parameter: $True "
			write-host  -ForegroundColor Yellow  	'Set-CASMailbox  <user> -ActiveSyncEnabled $True'
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo     
			write-host
			write-host


					# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Mailbox ( User) identity  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$UserAlias  = Read-Host "Type the Mailbox (user) name "
					write-host

					# Section 3: PowerShell Command

					Set-CASMailbox  "$UserAlias" -ActiveSyncEnabled $False


					# Section 4:  Indication 

					write-host
					write-host

					If ($lastexitcode -eq 1)
					{
						write-host "The command Failed :-(" -ForegroundColor red
					}
					Else
					{
						write-host -------------------------------------------------------------
						write-host -ForegroundColor Yellow	"The command complete successfully !" 
						write-host
						write-host -ForegroundColor Yellow	"Access to: " -nonewline; write-host "ActiveSync".ToUpper() -ForegroundColor White	 
						write-host -ForegroundColor Yellow	"Was disabled for: "	-nonewline; write-host "$UserAlias".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Mailbox  "	
						write-host -------------------------------------------------------------
					}

					# End of Indication 

					# Section 4: Display Information


					write-host
					write-host ---------------------------------------------------------------------------
					write-host -ForegroundColor white	Available mail service for: "$UserAlias".ToUpper() Mailbox
					write-host ---------------------------------------------------------------------------

					Get-CASMailbox  $UserAlias | Out-String


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

		}


		6
		{


		#####################################################################
		# Disable access to  ActiveSync for all Office 365 users (BULK Mode)
		#####################################################################

			# 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  	"The following option will Disable Access to: ActiveSync for ALL Office 365 users. " 
			write-host  -ForegroundColor white  	"The following option will Disable user Access to: ActiveSync . " 
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -ActiveSyncEnabled $False'
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  	
			write-host  -ForegroundColor white  	"If you want to re enable the ActiveSync access, use the command with the parameter: $True "
			write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -ActiveSyncEnabled $True'
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo     
			write-host


			# Section 3: PowerShell Command

			Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -ActiveSyncEnabled $False


			# Section 4:  Indication 

			write-host
			write-host

			If ($lastexitcode -eq 1)
			{
				write-host "The command Failed :-(" -ForegroundColor red
			}
			Else
			{
				write-host -------------------------------------------------------------
				write-host -ForegroundColor Yellow	"The command complete successfully !" 
				write-host
				write-host -ForegroundColor Yellow	"access to: " -nonewline; write-host "ActiveSync".ToUpper() -ForegroundColor White	 
				write-host -ForegroundColor Yellow	"Was disabled for ALL Office 365 users. "		
				write-host -------------------------------------------------------------
			}

			# End of Indication 

			# Section 4: Display Information

			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	"Display  Available Mail service for: ALL Office 365 users"
			write-host ---------------------------------------------------------------------------

			Get-CASMailbox | 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

	}




	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	# Section D: Outlook AnyWhere Access
	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	7
	{


		#####################################################################
		#  Disable MailBox(User) access to Outlook AnyWhere 
		#####################################################################

		# 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  	"The following option will Disable user Access to:  Outlook AnyWhere. " 
		write-host  -ForegroundColor white  	"The PowerShell command that we use is: "
		write-host  -ForegroundColor Yellow  	'Set-CASMailbox  <user> -MAPIEnabled $False '
		write-host  -ForegroundColor white  	"If you want to re enable the Outlook AnyWhere access, use the command with the parameter: $True "
		write-host  -ForegroundColor Yellow  	'Set-CASMailbox  <user> -MAPIEnabled  $True '
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
		write-host
		write-host


					# Section 2: user input	
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Mailbox ( User) identity  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$UserAlias  = Read-Host "Type the Mailbox (user) name "
					write-host

						# Section 3: PowerShell Command

						Set-CASMailbox  "$UserAlias" -MAPIEnabled $False


						# Section 4:  Indication 

						write-host
						write-host

						If ($lastexitcode -eq 1)
						{
							write-host "The command Failed :-(" -ForegroundColor red
						}
						Else
						{
							write-host -------------------------------------------------------------
							write-host -ForegroundColor Yellow	"The command complete successfully !" 
							write-host
							write-host -ForegroundColor Yellow	"Access to: " -nonewline; write-host "Outlook AnyWhere ".ToUpper() -ForegroundColor White	 
							write-host -ForegroundColor Yellow	"Was disabled for: "	-nonewline; write-host "$UserAlias".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Mailbox  "	
							write-host -------------------------------------------------------------
						}

						# End of Indication 



						# Section 4: Display Information

						write-host
						write-host ---------------------------------------------------------------------------
						write-host -ForegroundColor white	Available mail service for: "$UserAlias".ToUpper() Mailbox
						write-host ---------------------------------------------------------------------------

						Get-CASMailbox  $UserAlias | Out-String


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

		}


		8
		{


			#####################################################################
			# Disable access to  Outlook AnyWhere for all Office 365 users (BULK Mode)
			#####################################################################

			# 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  	"The following option will Disable Access to: Outlook AnyWhere  for ALL Office 365 users. " 
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -MAPIEnabled  $False'
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  	
			write-host  -ForegroundColor white  	"If you want to re enable the Outlook AnyWhere access, use the command with the parameter: $True "
			write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -MAPIEnabled   $True'
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo     
			write-host


			# Section 3: PowerShell Command

			Get-Mailbox -ResultSize Unlimited | Set-CASMailbox -MAPIEnabled  $False


			# Section 4:  Indication 

			write-host
			write-host

			If ($lastexitcode -eq 1)
			{
				write-host "The command Failed :-(" -ForegroundColor red
			}
			Else
			{
				write-host -------------------------------------------------------------
				write-host -ForegroundColor Yellow	"The command complete successfully !" 
				write-host
				write-host -ForegroundColor Yellow	"access to: " -nonewline; write-host "Outlook AnyWhere".ToUpper() -ForegroundColor White	 
				write-host -ForegroundColor Yellow	"Was disabled for ALL Office 365 users. "		
				write-host -------------------------------------------------------------
			}

			# End of Indication 

			# Section 4: Display Information

			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	"Display  Available Mail service for: ALL Office 365 users"
			write-host ---------------------------------------------------------------------------

			Get-CASMailbox | 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

	}



	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	# Section E: Office 365 user account
	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	9
	{


			#####################################################################
			#  Disable Office 365 user account
			#####################################################################

			# 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  	"The following option will Disable Office 365 user account. " 
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Set-MsolUser -UserPrincipalName <user@Domain.com> -blockcredential $True'
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  	
			write-host  -ForegroundColor white  	"If you want to re enable the user account, use the command with the parameter: $False "
			write-host  -ForegroundColor Yellow  	'Set-CASMailbox  <user> -MAPIEnabled  $False'
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo     
			write-host
			write-host

					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1.User UPN identity  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$UserUPN   = Read-Host "Type the User UPN name "
					write-host
			
								# Section 3: PowerShell Command

								Set-MsolUser -UserPrincipalName "$UserUPN" -blockcredential $True

								# Section 4:  Indication 

								write-host
								write-host

								If ($lastexitcode -eq 1)
								{
									write-host "The command Failed :-(" -ForegroundColor red
								}
								Else
								{
									write-host -------------------------------------------------------------
									write-host -ForegroundColor Yellow	"The command complete successfully !" 
									write-host
									write-host -ForegroundColor Yellow	"the user account "	-nonewline; write-host "$UserUPN".ToUpper() -ForegroundColor White 
									write-host -ForegroundColor Yellow	"is Disabled  "	
									write-host -------------------------------------------------------------
								}

								# End of Indication 

								# Section 4: Display Information

								write-host
								write-host ---------------------------------------------------------------------------
								write-host -ForegroundColor white	Display information about "$UserUPN".ToUpper() user account
								write-host ---------------------------------------------------------------------------

								Get-MsolUser -UserPrincipalName $UserUPN |FL DisplayName, BlockCredential | Out-String


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

	}





	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	# Section F: Access to PowerShell
	#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	10
	{


			#####################################################################
			#  Disable Access to PowerShell
			#####################################################################

			# 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  	"The following option will Disable Access to PowerShell. " 
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Set-User <User> -RemotePowerShellEnabled $False'
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  	
			write-host  -ForegroundColor white  	"If you want to re enable the PowerShell access, use the command with the parameter: $True "
			write-host  -ForegroundColor Yellow  	'Set-User <User -RemotePowerShellEnabled $True'
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo    
			write-host



					# Section 2: user input	
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Mailbox ( User) identity  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$UserAlias  = Read-Host "Type the Mailbox (user) name "
					write-host

							# Section 3: PowerShell Command


							Set-User "$UserAlias" -RemotePowerShellEnabled $False

							# Section 4:  Indication 

							write-host
							write-host

							If ($lastexitcode -eq 1)
							{
								write-host "The command Failed :-(" -ForegroundColor red
							}
							Else
							{
								write-host -------------------------------------------------------------
								write-host -ForegroundColor Yellow	"The command complete successfully !" 
								write-host
								write-host -ForegroundColor Yellow	"Access to PowerShell for: "	-nonewline; write-host "$UserAlias".ToUpper() -ForegroundColor White 
								write-host -ForegroundColor Yellow	"is Disabled  "	
								write-host -------------------------------------------------------------
							}

							# End of Indication 

							# Section 4: Display Information

							write-host
							write-host ---------------------------------------------------------------------------
							write-host -ForegroundColor white	Display information about "$UserUPN".ToUpper() user account
							write-host ---------------------------------------------------------------------------

							Get-CASMailbox | 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

		}





#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section G: Display information
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	11
	{


			#####################################################################
			#  Display information about User (Mailbox) Services 
			#####################################################################

			# 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  	"The following option will Display information about User (Mailbox) Services. " 
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Get-CASMailbox  <User>'
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo      
			write-host
			write-host


			
					# Section 2: user input	
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Mailbox ( User) identity  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$UserAlias  = Read-Host "Type the Mailbox (user) name "
					write-host



			# Section 4: Display Information

			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	Available mail service for: "$UserAlias".ToUpper() Mailbox
			write-host ---------------------------------------------------------------------------

			Get-CASMailbox  $UserAlias | Out-String


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

	}



	12
	{


		#####################################################################
		#Display information about ALL Users (Mailboxs) Services
		#####################################################################

		# 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  	"The following option will Display information about ALL Users (Mailboxs) Services. " 
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Get-mailbox | Set-CASMailbox -OWAEnabled $False'
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
		write-host
		write-host


		# Section 4: Display Information

		write-host
		write-host ---------------------------------------------------------------------------
		write-host -ForegroundColor white	"Display  Available Mail service for: ALL Office 365 users"
		write-host ---------------------------------------------------------------------------

		Get-CASMailbox | 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

	}




	13
	{


			#####################################################################
			#Display information about Locked users accounts
			#####################################################################

			# 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  	"The following option will Display information about:Locked users accounts " 
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Get-MsolUser |FL DisplayName, BlockCredential'
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo      
			write-host
			write-host


			# Section 4: Display Information

			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	"Display information about Locked users accounts"
			write-host ---------------------------------------------------------------------------

			Get-MsolUser |FL DisplayName, BlockCredential  | Out-String


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

		}


				 
				#+++++++++++++++++++
				# Step -05 Finish  
				##++++++++++++++++++
				 
				 
				14{

				##########################################
				# 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 


				}




				15{

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


				$Loop = $True
				Exit
				}

				}


				}
