

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



Function Write-White($Message)
{
    Write-Host  $Message -ForegroundColor White 
}


$FormatEnumerationLimit = -1
$ExportInfo = "The information was exported to the following location C:\INFO"
$Date = Get-Date

#------------------------------------------------------------------------------
# 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; }
H2{ color: white; background-color:#385643; 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   "Automatically Forward Mail to another Recipient | 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
    write-host -ForegroundColor green						' Section A: Automatic Mail forwarding to Recipient ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'1)   Forward Email to internal Recipient & save local copy (Default)'
	write-host 												'2)   Forward Email to internal Recipient & DONT save local copy '
	write-host 												'3)   Forward Email to External Recipient & save local copy (Default)'
	write-host 												'4)   Forward Email to External Recipient & DONT save local copy'
	write-host 												'5)   Create external contact with internal Email address and Forward Email address'
    write-host
    write-host -ForegroundColor green						' Section B: Display information about Forwarding rule ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'6)   Display information about Mailbox forwarding rule'
	write-host 												'7)   Find all users with Forwarding Address is set to Internal Recipient'
	write-host 												'8)   Find all users with Forwarding Address is set to Internal + External Recipient'
    write-host
    write-host -ForegroundColor green						' Section C: Remove Forward address ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'9)   Turn off email Automatic Forwarding to Internal Recipient'
	write-host 												'10)  Turn off email Automatic Forwarding to External Recipient'
    write-host
    write-host
    write-host -ForegroundColor green						' Section D: Forward Email of ALL Users to Additional email address(BULK Mode) ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'11)  Create automatic Forwarding rule for all Office365 users to: internal Recipient'
	write-host 												'12)  Create automatic Forwarding rule for all Office365 users to: External Recipient'
	write-host
    write-host -ForegroundColor green						' Section E: Turn off Forwarding rule for ALL Users (BULK Mode) ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'13)  Turn off Forwarding rule for ALL office 365 Users to: Internal Recipient'
	write-host 												'14)  Turn off Forwarding rule for ALL office 365 Users to: External Recipient'
    write-host
    write-host
    write-host -ForegroundColor Red            "15)  Disconnect PowerShell session" 
    write-host
    write-host -ForegroundColor Red            "16)  Exit" 
    write-host

    $opt = Read-Host "Select an option [0-16]"
    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://outlook.office365.com/powershell-liveid/
			$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: Automatic Mail forwarding to Recipient
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	1
	{


		#####################################################################
		#  Forward Email to internal Recipient & save local copy (Default)
		#####################################################################

		# 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  	'Forward each mail that reaches the recipient (Mailbox) to:   '
		write-host  -ForegroundColor white  	'a User (or a Distribution group) in the local organization. '
		write-host  -ForegroundColor white  	'The mail will be copied. the meaning is that the original recipient will have   '
		write-host  -ForegroundColor white  	'the mail message and a copy of the message will be send to the destination recipient.   '
		write-host  -ForegroundColor white		----------------------------------------------------------------------------   
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Set-Mailbox <Mailbox> -ForwardingAddress <user/Distribution Group> '
		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) The first parameter is the User Mailbox name "  
			write-host -ForegroundColor Yellow	"For example: user1"
			write-host
			$MailBox = Read-Host "Type the User Mailbox name "
			write-host
			write-host -ForegroundColor Yellow	"2) The Second parameter is the Mailbox name of the Destination recipient" 
			write-host -ForegroundColor Yellow	"For example: user2"
			write-host
			$MailRecipient =  Read-Host "Type the user That you want that the mail will be forwarded to"


				# Section 3: PowerShell Command

				Set-Mailbox  $MailBox -ForwardingAddress $MailRecipient 

				# 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	"Mail that reach to: " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White	 
					write-host -ForegroundColor Yellow	"will be forwarded to: "	-nonewline; write-host "$MailRecipient".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	Display information about Forwarding rule for: "$MailBox".ToUpper() "Mailbox"
				write-host ---------------------------------------------------------------------------

				Get-Mailbox $MailBox | FT ForwardingAddress | Out-String

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




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

	}


	2
	{


		#####################################################################
		#   Forward Email to internal Recipient & DONT save local copy
		#####################################################################

		# 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  	'Forward each mail that reaches the recipient (Mailbox) to:   '
		write-host  -ForegroundColor white  	'a User (or a Distribution group) in the local organization, '
		write-host  -ForegroundColor white  	'but an email copy will NOT be saved in the Original recipient Mailbox.  '
		write-host  -ForegroundColor white		---------------------------------------------------------------------------- 
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Set-Mailbox -Identity <Mailbox> -ForwardingAddress <user/Distribution Group> -DeliverToMailboxAndForward $False '
		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) The first parameter is the User Mailbox name "  
			write-host -ForegroundColor Yellow	"For example: user1"
			write-host
			$MailBox = Read-Host "Type the User Mailbox name "
			write-host
			write-host -ForegroundColor Yellow	"2) The Second parameter is the Mailbox name of the Destination recipient" 
			write-host -ForegroundColor Yellow	"For example: user2"
			write-host
			$MailRecipient =  Read-Host "Type the user That you want that the mail will be forwarded to"

				# Section 3: PowerShell Command

				Set-Mailbox -Identity $MailBox -ForwardingAddress $MailRecipient -DeliverToMailboxAndForward $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	"Mail that reach to: " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White	 
					write-host -ForegroundColor Yellow	"Will be forwarded to:"	-nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White	
					write-host -------------------------------------------------------------
				}

				# End of Indication 

				# Section 4: Display Information

				write-host
				write-host ---------------------------------------------------------------------------
				write-host -ForegroundColor white	Display information about Forwarding rule for: "$MailBox".ToUpper() "Mailbox"
				write-host ---------------------------------------------------------------------------

				Get-Mailbox $MailBox | FT ForwardingAddress,DeliverToMailboxAndForward -Autosize | Out-String

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


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

	}



	3
	{


		#####################################################################
		#   Forward Email to external Recipient & save local copy (Default)
		#####################################################################

		# 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  	'Forward each mail that reaches the recipient (Mailbox) to:   '
		write-host  -ForegroundColor white  	'EXTERNAL recipient. '
		write-host  -ForegroundColor white  	'The mail will be copied. the meaning is that the original recipient will have   '
		write-host  -ForegroundColor white  	'the mail message and a copy of the message will be send to the destination recipient.   '
		write-host  -ForegroundColor white		---------------------------------------------------------------------------- 
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Set-Mailbox  <Mailbox> - -ForwardingsmtpAddress <User/Distribution Group>  '
		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) The first parameter is the User Mailbox name "  
			write-host -ForegroundColor Yellow	"For example: user1"
			write-host
			$MailBox = Read-Host "Type the User Mailbox name "
			write-host
			write-host -ForegroundColor Yellow	"2) The Second parameter is the External Email Address" 
			write-host -ForegroundColor Yellow	"For example: user@hotmail.com"
			write-host
			$MailRecipient =  Read-Host "Type the Target SMTP Address"


				# Section 3: PowerShell Command

				Set-Mailbox  $MailBox -ForwardingsmtpAddress $MailRecipient 

				# Set-Mailbox  <Mailbox> - -ForwardingsmtpAddress <User/Distribution Group> 




					# 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	"mail that reach to: " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White	 
						write-host -ForegroundColor Yellow	"will be forwarded to: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Address  "
						write-host -------------------------------------------------------------
					}

					# End of Indication 

					# Section 4: Display Information

					write-host
					write-host ---------------------------------------------------------------------------
					write-host -ForegroundColor white	Display information about Forwarding rule for: "$MailBox".ToUpper() "Mailbox"
					write-host ---------------------------------------------------------------------------
					Get-Mailbox -Identity $MailBox | FL  ForwardingSmtpAddress, DeliverToMailboxAndForward | Out-String
					write-host ---------------------------------------------------------------------------


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




	}



	4{

		#####################################################################
		#  Forward Email to external Recipient & DONT save local copy 
		#####################################################################

		# 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		----------------------------------------------------------------------------                                                             
		write-host  -ForegroundColor white  	'This option will '
		write-host  -ForegroundColor white  	'Forward each mail that reaches the recipient (Mailbox) to:   '
		write-host  -ForegroundColor white  	'EXTERNAL recipient. '
		write-host  -ForegroundColor white  	'but an email copy will NOT be saved in the Original recipient Mailbox.  '
		write-host  -ForegroundColor white		---------------------------------------------------------------------------- 
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Set-Mailbox  <Mailbox> - -ForwardingsmtpAddress <User/Distribution Group> -DeliverToMailboxAndForward $False '
		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) The first parameter is the User Mailbox name "  
			write-host -ForegroundColor Yellow	"For example: user1"
			write-host
			$MailBox = Read-Host "Type the User Mailbox name "
			write-host
			write-host -ForegroundColor Yellow	"2) The Second parameter is the External Email Address" 
			write-host -ForegroundColor Yellow	"For example: user@hotmail.com"
			write-host
			$MailRecipient =  Read-Host "Type the Target SMTP Address"



				# Section 3: PowerShell Command

				Set-Mailbox  $MailBox -ForwardingsmtpAddress $MailRecipient -DeliverToMailboxAndForward $False


				# Set-Mailbox  <Mailbox> - -ForwardingsmtpAddress <User/Distribution Group> -DeliverToMailboxAndForward $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	"Mail that reach to: " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White	 
					write-host -ForegroundColor Yellow	"will be forwarded to: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Address  "
					write-host -ForegroundColor Yellow	"(The email will be forwarded without saving a copy in the user Mailbox)" 
					write-host -------------------------------------------------------------
					}


					# End of Indication 

						# Section 4: Display Information

						write-host
						write-host ---------------------------------------------------------------------------
						write-host -ForegroundColor white	Display information about Forwarding rule for: "$MailBox".ToUpper() "Mailbox"
						write-host ---------------------------------------------------------------------------
						Get-Mailbox -Identity $MailBox | FL  ForwardingSmtpAddress, DeliverToMailboxAndForward | Out-String
						write-host ---------------------------------------------------------------------------


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

	}





	5{


	#####################################################################
	#  Create External contact with: internal email address + Forward email address (External Email 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 Assign an internal (Organization) email address to contact  '
	write-host  -ForegroundColor white  	'and automatically forward each email that will sent to the contact  '
	write-host  -ForegroundColor white  	'to external Email address '
	write-host  -ForegroundColor white		---------------------------------------------------------------------------- 
	write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
	write-host  -ForegroundColor Yellow  	'New-Mailcontact -Name "$contactname" -ExternalEmailAddress <External Email Address> '
	write-host  -ForegroundColor Yellow  	'Set-Mailcontact $contactname -emailaddresses SMTP:<Internal Email Address>,<External Email Address> '
	write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
	write-host
	write-host



	# Section 2: user input


	write-host -ForegroundColor Yellow	"You will need to Provide 3 parameters:"  
	write-host
	write-host -ForegroundColor Yellow	"1) The first parameter is the contact name "  
	write-host -ForegroundColor Yellow	"For example: user1"
	write-host
	$contactname = Read-Host "Type the contact name "
	write-host
	write-host -ForegroundColor Yellow	"2) The Second parameter is the contact Internal email address" 
	write-host -ForegroundColor Yellow	"For example: John@o365info.com"
	write-host
	$Internal =  Read-Host "Type the internal SMTP Address"
	write-host
	write-host -ForegroundColor Yellow	"3) The Third parameter is the contact External email address" 
	write-host -ForegroundColor Yellow	"For example: johndoe@hotmail.com"
	write-host
	$External =  Read-Host "Type the Target SMTP Address"



	# Section 3: PowerShell Command

	New-Mailcontact -Name "$contactname" -ExternalEmailAddress $External
	

	Set-Mailcontact $contactname -emailaddresses SMTP:$Internal,$External
	


	# 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	"a new contact name: " -nonewline; write-host "$contactname".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" was created  "	
	write-host -ForegroundColor Yellow	"the contact internal Email Address is: "	-nonewline; write-host "$Internal".ToUpper() -ForegroundColor White 
	write-host -ForegroundColor Yellow	"The mail will be forwarded to : "	-nonewline; write-host "$External".ToUpper() -ForegroundColor White 
	write-host -------------------------------------------------------------
	}


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



	}



#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section B: Display information about forwarding rule
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<




6
{


#####################################################################
#   Display information about Mailbox forwarding rule
#####################################################################

# 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 display information about Forwarding address of a specific Recipient(Mailbox)  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox -Identity <MailBox> | FL DeliverToMailboxAndForward,ForwardingAddress,ForwardingSmtpAddress  '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to Provide 1 parameters:"  
write-host
write-host -ForegroundColor Yellow	"The User Mailbox name "  
write-host -ForegroundColor Yellow	"For example: user1"
$MailBox = Read-Host "Type the User Mailbox name "
write-host


# Section 3: PowerShell Command




# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display information about forwarding rule for "$MailBox".ToUpper() Mailbox
write-host ---------------------------------------------------------------------------

Get-Mailbox -Identity $MailBox | FL ForwardingAddress,ForwardingSmtpAddress ,DeliverToMailboxAndForward | Out-String


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

}


7{


#####################################################################
#   Find all users with Forwarding Address is set to Internal Recipient
#####################################################################

# 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 Display a list of: '
write-host  -ForegroundColor white  	'all users with Forwarding Address  set to Internal Recipient '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox | Where {$_.ForwardingAddress -ne $Null} | Select Name, ForwardingAddress, DeliverToMailboxAndForward '
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 ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display all users with Forwarding rule set to Internal Recipient
write-host ---------------------------------------------------------------------------

Get-Mailbox | Where {$_.ForwardingAddress -ne $Null} | Select Name, ForwardingAddress | Out-String


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

}



8
{


#####################################################################
#    Find all users with Forwarding Address is set to Internal + External Recipient
#####################################################################

# 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 Display a list of: '
write-host  -ForegroundColor white  	'*all users with Forwarding Address  set to Internal Recipient '
write-host  -ForegroundColor white  	'*all users with Forwarding Address  set to External Recipient '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox | Where {($_.ForwardingAddress -ne $Null) -or ($_.ForwardingsmtpAddress -ne $Null)} | Select Name, ForwardingAddress, ForwardingsmtpAddress, DeliverToMailboxAndForward  '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host



# Section 3: PowerShell Command


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 All users with Forwarding Address is set to Internal + External Recipient
write-host ---------------------------------------------------------------------------

Get-Mailbox | Where {($_.ForwardingAddress -ne $Null) -or ($_.ForwardingsmtpAddress -ne $Null)} | Select Name, ForwardingAddress, ForwardingsmtpAddress, DeliverToMailboxAndForward | Out-String


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

}



#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section C: Remove Forward address
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



9
{


#####################################################################
#   Turn off email Automatic forwarding to internal Recipient
#####################################################################

# 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: Turn off email Automatic Forwarding rule to internal Recipient '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <MailBox> -ForwardingAddress $Null  '
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	"Type the Mailbox name "  
write-host -ForegroundColor Yellow	"For example: user1"
write-host
$MailBox = Read-Host "Type the Mailbox name "
write-host


# Section 3: PowerShell Command

Set-Mailbox $MailBox -ForwardingAddress $Null 



# 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	"Automatic forwarding rule for: " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White ; write-host -ForegroundColor Yellow	"Mailbox"		 
	write-host -ForegroundColor Yellow	"was turned off "	
	write-host -------------------------------------------------------------
}


# End of Indication 

# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display information about Forwarding rule for: "$MailBox".ToUpper() "Mailbox"
write-host ---------------------------------------------------------------------------

Get-Mailbox -Identity $MailBox | FL DeliverToMailboxAndForward,ForwardingAddress,ForwardingSmtpAddress | Out-String


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


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

}



10{


#####################################################################
#  Turn off Email Automatic forwarding rule to External Recipient
#####################################################################

# 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: Turn off Email Automatic Forwarding rule to External Recipient '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <MailBox> -ForwardingSmtpAddress $Null  '
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	" Type the Mailbox name "  
write-host -ForegroundColor Yellow	"For example: user1"
write-host
$MailBox = Read-Host "Type the Mailbox name "
write-host

# Section 3: PowerShell Command

Set-Mailbox $MailBox -ForwardingSmtpAddress $Null 


# 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	"Automatic forwarding rule for: " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White ; write-host -ForegroundColor Yellow	" Mailbox  "		 
	write-host -ForegroundColor Yellow	"was turned off "	
	write-host -------------------------------------------------------------
}


# End of Indication 

# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display information about Forwarding rule for: "$MailBox".ToUpper() "Mailbox"
write-host ---------------------------------------------------------------------------
Get-Mailbox -Identity $MailBox | FL DeliverToMailboxAndForward,ForwardingAddress,ForwardingSmtpAddress | Out-String
write-host ---------------------------------------------------------------------------


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

}



#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#  Section D: Forward Email of ALL Users to Additional email address(BULK Mode)
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


11
{


#####################################################################
#  Create automatic forwarding rule for all Office365 users to internal Recipient
#####################################################################

# 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: Create automatic forwarding rule for all Office365 to internal Recipient'
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -DeliverToMailboxAndForward $True  '
write-host  -ForegroundColor Yellow  	'Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -ForwardingAddress <MailRecipient> '
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	"Type User (or the Distribution Group) name "  
write-host -ForegroundColor Yellow	"That you want that the mail will be forwarded to them"
write-host
$MailRecipient = Read-Host "Type theUser (or the Distribution Group) name "
write-host



# Section 3: PowerShell Command

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -DeliverToMailboxAndForward $True 

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -ForwardingAddress $MailRecipient 




# 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	"Automatic forwarding rule for all office 365 users(Mailboxes) was Created "
	write-host -ForegroundColor Yellow	"Each email will be automatically forwarded to the following internal Email address: "	
	write-host -ForegroundColor white	""$MailRecipient".ToUpper() "		 
	write-host -------------------------------------------------------------
}




# End of Indication 

# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 All users with Forwarding Address is set to Internal Recipient
write-host ---------------------------------------------------------------------------

Get-Mailbox | Where {($_.ForwardingAddress -ne $Null) -or ($_.ForwardingsmtpAddress -ne $Null)} | Select Name, ForwardingAddress, ForwardingsmtpAddress, DeliverToMailboxAndForward | Out-String



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

}



12
{


#####################################################################
#Create automatic forwarding rule for all Office365 users to External Recipient
#####################################################################

# 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: Create automatic forwarding rule for all Office 365 to External Email address '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'xxxxxxxxxx '
write-host  -ForegroundColor Yellow  	'xxxxxxxxxx '
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) User Mailbox name "  
			write-host -ForegroundColor Yellow	"For example: user1"
			write-host
			$MailBox = Read-Host "Type the User name that you want that the mail will be forwarded to them "
			write-host


# Section 3: PowerShell Command

Get-Mailbox | Where {$_.RecipientType -eq "$MailBox"}| Set-Mailbox -DeliverToMailboxAndForward $True 

Get-Mailbox | Where {$_.RecipientType -eq "$MailBox"}| Set-Mailbox -ForwardingSmtpAddress  $MailRecipient 

# 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	"Automatic forwarding rule for all office 365 users(Mailboxes) was Created "
	write-host -ForegroundColor Yellow	"Each email will be automatically forwarded to the following External Email address: "	
	write-host -ForegroundColor white	""$MailBox ".ToUpper() "		 
	write-host -------------------------------------------------------------
}


# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	 All users with Forwarding Address is set to External Recipient
write-host ---------------------------------------------------------------------------

Get-Mailbox | Where {($_.ForwardingAddress -ne $Null) -or ($_.ForwardingsmtpAddress -ne $Null)} | Select Name, ForwardingAddress, ForwardingsmtpAddress, DeliverToMailboxAndForward | Out-String


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


}

#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#  Section E: Turn off forwarding rule for ALL Users (BULK Mode)
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



13{


#####################################################################
#   Turn off Forwarding rule for ALL office 365 Users to: internal Recipient
#####################################################################

# 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: Turn off email Automatic Forwarding rule to internal Recipient '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -ForwardingAddress $Null   '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


# Section 3: PowerShell Command

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -ForwardingAddress $Null  

# 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	"Automatic forwarding rule for: " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White ; write-host -ForegroundColor Yellow	" Mailbox  "		 
	write-host -ForegroundColor Yellow	"was turned off "	
	write-host -------------------------------------------------------------
}







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

}



14
{


#####################################################################
#  Turn off Forwarding rule for ALL office 365 Users to: External Recipient
#####################################################################

# 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: Turn off Email Automatic Forwarding rule to External Recipient '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -ForwardingSmtpAddress $Null  '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -ForwardingSmtpAddress $Null 

# 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	"Automatic forwarding rule for: " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White ; write-host -ForegroundColor Yellow	" Mailbox  "		 
	write-host -ForegroundColor Yellow	"was turned off "	
	write-host -------------------------------------------------------------
}

}



 
				#+++++++++++++++++++
				# Step -05 Finish  
				##++++++++++++++++++
				 
				 
				15{

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


				}




				16{

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


				$Loop = $True
				Exit
				}

				}


				}

		