

#------------------------------------------------------------------------------
# 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-5-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  "Soft delete (Office 365 Recycle bin)  | 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:  Restore Deleted  User account ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 1)   Restore Deleted  User account by using the User UPN'
	write-host 
	write-host                                              ' 2)   Restore Deleted  User account by using the User GUID'
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section B: Display information about Deleted user accounts  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 3)  Display a list of ALL deleted user accounts'
	write-host 
	write-host                                              ' 4)  Display information about Specific deleted User account'
	
	
	
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue 'Section C: Delete (Remove) User account from the Recycle bin  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 5)  Delete (Remove) Specific user account from the Recycle bin'
	write-host 
	write-host                                              ' 6)  Delete (Remove) ALL user account from the Recycle bin'
	write-host 
	
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor Blue  -BackgroundColor Yello ' Exit\Disconnect ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host  -ForegroundColor Yellow                       ' 7)  Disconnect PowerShell session'
	write-host 
	write-host  -ForegroundColor Yellow                       ' 8)  Exit'
	write-host 
	write-host                                          

	

    $opt = Read-Host "Select an option [0-8]"
    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:  Restore deleted User account
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	1
	{


			#####################################################################
			# Restore Deleted  User account by using the User UPN
			#####################################################################

			# 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  	'Restore Deleted  User account by using the User UPN '
			write-host  -ForegroundColor white  	'This option is suitable for “Standard” scenario in which the user account was delete only 1 time.   '
			write-host  -ForegroundColor white  	'In this case we “select” the deleted user account by using the Deleted user UPN '
			write-host  -ForegroundColor white  	'Note ! '
			write-host  -ForegroundColor white  	'In case that you use DirSync this option is not available (the deleted object have read onlyFLag) '
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Get-MsolUser –ReturnDeletedUsers –searchstring <User UPN> |FL UserPrincipalName, ObjectID  '
			write-host  -ForegroundColor Yellow  	'Restore-MsolUser -UserPrincipalName <User UPN> -AutoReconcileProxyConflicts -NewUserPrincipalName <NEW User UPN>  '
			write-host
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host
			write-host


			# Section 2: user input


			write-host -ForegroundColor Yellow	"You will need to Provide 2 parameters:"  
			write-host
			write-host -ForegroundColor Yellow	"1) User UPN name"  
			write-host -ForegroundColor Yellow	"Deleted User UPN name"
			write-host -ForegroundColor Yellow	"For example: John@o365info.com"
			write-host

			$UserUPN = Read-Host "Type the user UPN "


			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	Information about deleted user  "$UserUPN".ToUpper() 
			write-host ---------------------------------------------------------------------------


			Get-MsolUser –ReturnDeletedUsers –searchstring $UserUPN |FL UserPrincipalName,ObjectID | Out-String
			


			write-host
			write-host -ForegroundColor Yellow	"2) New User UPN Name" 
			write-host -ForegroundColor Yellow	"The New User UPN Name" 
			write-host -ForegroundColor Yellow	"For example: user1-new@o365info.com"   
			write-host
			$NewUPN =  Read-Host "Type the New User UPN Name"




			# Section 3: PowerShell Command

			Restore-MsolUser -UserPrincipalName $UserUPN -AutoReconcileProxyConflicts -NewUserPrincipalName $NewUPN
		
			# 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 Deleted User abject named:  " -nonewline; write-host "$UserUPN".ToUpper() -ForegroundColor White 
			write-host -ForegroundColor Yellow	"Was restored using the name: " -nonewline; write-host "$NewUPN".ToUpper() -ForegroundColor White 
			write-host -------------------------------------------------------------
			}

			#———— End of Indication ———————

			# Section 4: Display Information




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

		}




		2
		{


			#####################################################################
			# Restore Deleted  User account by using the User GUID
			#####################################################################

			# 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  	'Restore Deleted  User account by using the User GUID '
			write-host  -ForegroundColor white  	'This option is suitable for scenario in which the user account was delete more than 1 time.  '
			write-host  -ForegroundColor white  	'In this case we will have more them one deleted user account with the same UPN '
			write-host  -ForegroundColor white  	'The only option that we can use for “selecting” a specific user account is by using the User GUID '
			write-host  -ForegroundColor white  	'Note ! '
			write-host  -ForegroundColor white  	'In case that you use DirSync this option is not available (the deleted object have read onlyFLag) '
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Get-MsolUser –ReturnDeletedUsers –searchstring <User UPN> |FL UserPrincipalName, ObjectID  '
			write-host  -ForegroundColor Yellow  	'Restore-MsolUser -ObjectId <GUID> -AutoReconcileProxyConflicts -NewUserPrincipalName <New User name>  '
			write-host
			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) Deleted User UPN name"  
			write-host -ForegroundColor Yellow	"For example: John@o365info.com"
			write-host

			$UserUPN = Read-Host "Type the user UPN "


			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	Information about deleted user  "$UserUPN".ToUpper() 
			write-host ---------------------------------------------------------------------------


			Get-MsolUser –ReturnDeletedUsers –searchstring $UserUPN |FL UserPrincipalName,ObjectID | Out-String
			


			write-host
			write-host -ForegroundColor Yellow	"2) User GUID Address" 
			write-host -ForegroundColor Yellow	"For example: b9e82087-ad92-4632-a219-d779c29d2edd"   
			write-host
			$GUID =  Read-Host "Type the User GUID Address"


			write-host
			write-host -ForegroundColor Yellow	"3) The New User UPN Name" 
			write-host -ForegroundColor Yellow	"For example: user1-new@o365info.com"   
			write-host
			$NewUPN =  Read-Host "Type the New User UPN Name"




			# Section 3: PowerShell Command

			Restore-MsolUser -ObjectId $GUID -AutoReconcileProxyConflicts -NewUserPrincipalName $NewUPN 
		
			# 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 Deleted User abject named:  " -nonewline; write-host "$UserUPN".ToUpper() -ForegroundColor White 
			write-host -ForegroundColor Yellow	"Was restored using the name: " -nonewline; write-host "$NewUPN".ToUpper() -ForegroundColor White 
			write-host -------------------------------------------------------------
			}

			#———— End of Indication ———————

			# Section 4: Display Information




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

	}





#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#Section B: Display information
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



	3
	{


		#####################################################################
		#   Display a list of ALL deleted User 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  	'This option will: '
		write-host  -ForegroundColor white  	'Display a list of ALL Deleted User accounts '
		write-host  -ForegroundColor white		----------------------------------------------------------------------------  
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Get-MsolUser -ReturnDeletedUsers |FL UserPrincipalName, ObjectID '
		write-host
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
		write-host
		write-host


		# Section 2: user input



		# Section 3: PowerShell Command



		write-host
		write-host ---------------------------------------------------------------------------
		write-host -ForegroundColor white	List of ALL Deleted User accounts
		write-host ---------------------------------------------------------------------------

		Get-MsolUser -ReturnDeletedUsers |FL UserPrincipalName,ObjectID | Out-String



		# Section 4: Display Information




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

	}






	4
	{


		#####################################################################
		#   Display information about Specific deleted 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  	'This option will: '
		write-host  -ForegroundColor white  	'Display information about Specific deleted User account '
		write-host  -ForegroundColor white		----------------------------------------------------------------------------  
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Get-MsolUser –ReturnDeletedUsers –searchstring $UserUPN |FL UserPrincipalName, ObjectID | Out-String '
		write-host
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
		write-host
		write-host


		# Section 2: user input


		write-host -ForegroundColor Yellow	"You will need to Provide 2 parameters:"  
		write-host
		write-host -ForegroundColor Yellow	"1) Deleted User UPN name"  
		write-host -ForegroundColor Yellow	"For example: John@o365info.com"
		write-host

		$UserUPN = Read-Host "Type the user UPN "


		write-host
		write-host ---------------------------------------------------------------------------
		write-host -ForegroundColor white	Information about deleted user  "$UserUPN".ToUpper() 
		write-host ---------------------------------------------------------------------------

		Get-MsolUser –ReturnDeletedUsers –searchstring $UserUPN |FL UserPrincipalName, ObjectID | Out-String



		# Section 4: Display Information




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

		}









#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#Section C: Delete (Remove) User account from the Recycle bin
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



	5
	{


			#####################################################################
			#Delete (Remove) Specific user account from the Recycle bin
			#####################################################################

			# 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  	'Delete (Remove) Specific user account from the Recycle bin '
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Get-MsolUser -ReturnDeletedUsers |FL UserPrincipalName, ObjectID  '
			write-host  -ForegroundColor Yellow  	'Remove-MsolUser -ObjectId <GUID> -RemoveFromRecycleBin –Force  '
			write-host
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host
			write-host



			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	List of ALL Deleted User accounts
			write-host ---------------------------------------------------------------------------

			Get-MsolUser -ReturnDeletedUsers |FL UserPrincipalName, ObjectID | Out-String


			# Section 2: user input

			write-host -ForegroundColor Yellow	"You will need to Provide 1 parameter:"  
			write-host
			write-host -ForegroundColor Yellow	"1) Deleted User GUID"  
			write-host -ForegroundColor Yellow	"For example: b9e82087-ad92-4632-a219-d779c29d2edd"
			write-host
			$GUID = Read-Host "Type the user GUID "



			# Section 3: PowerShell Command

			Remove-MsolUser -ObjectId $GUID -RemoveFromRecycleBin –Force | Out-String
			
			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 was deleted from the Recycle bin  "  
			write-host -------------------------------------------------------------
			}

			#———— End of Indication ———————

			# Section 4: Display Information




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

		}






	6
	{


			#####################################################################
			#Delete (Remove) ALL user account from the Recycle bin
			#####################################################################

			# 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  	'Delete (Remove) ALL user account from the Recycle bin '
			write-host  -ForegroundColor white		----------------------------------------------------------------------------  
			write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
			write-host  -ForegroundColor Yellow  	'Get-MsolUser -ReturnDeletedUsers |FL UserPrincipalName, ObjectID  '
			write-host  -ForegroundColor Yellow  	'Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin –Force  '
			write-host
			write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
			write-host
			write-host



			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	List of ALL Deleted User accounts
			write-host ---------------------------------------------------------------------------

			Get-MsolUser -ReturnDeletedUsers |FL UserPrincipalName, ObjectID | Out-String


			# Section 2: user input



			# Section 3: PowerShell Command

			Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin –Force


			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	"All the deleted users accounts was removed from the Recycle bin  "  
			write-host -------------------------------------------------------------
			}

			#———— End of Indication ———————

			# Section 4: Display Information




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

			}




		
						
				 
				#+++++++++++++++++++
				# Step -05 Finish  
				##++++++++++++++++++
				 
				 
				7{

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


				}




				8{

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


				$Loop = $true
				Exit
				}

				}


				}
