

#------------------------------------------------------------------------------
# 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  "Retention Policy + Deleted items policy Script | 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:  Apply Retention Policy ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 1)  Apply Retention policy for a Mailbox - Choose the Retention Policy'
	write-host                                              ' 2)  Apply Default Retention policy for a Mailbox '
	write-host                                              ' 3)  Apply the Default Retention Policy to ALL Office 365 Mailboxes (BULK Mode)'
	write-host 
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section B:  Remove Retention Policy  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 4)   Remove Retention Policy for a Mailbox (set to NULL)'
	write-host                                              ' 5)   Remove Retention Policy for a Mailbox  Retention policy to ALL Office 365 users Mailboxes (BULK Mode)'
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue 'Section C: Display Retention Policy  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 6)   Display the Retention Policy applied to a user Mailbox'
	write-host                                              ' 7)   Display the Retention Policy applied to all Office 365 users Mailboxes'
	write-host
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section D: Default Retention Policy Tags settings  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 8)   Set the number of days for Deleted items Tag'
	write-host                                              ' 9)   Disable Deleted items Tag'
	write-host                                              ' 10)  Set the number of days for Junk Email Tag'
	
	write-host  
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section E: create NEW Retention Policy Tags  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 11)   Create NEW tag for Sync Issues Folder'
	
	write-host  
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section F: Managed Folder Assistant ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 12)   Run the Managed Folder Assistant for a specific Mailbox'
	write-host                                              ' 13)   Run the Managed Folder Assistant for all Office 365 Mailboxes (BULK Mode)'
	
	write-host  
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' Section G: Managed Deleted items policy  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 14)   Set Deleted items policy for 30 days for spesfic user'
	write-host                                              ' 15)   Set Deleted items policy for 30 days for ALL user (BULK)'
	write-host                                              ' 16)   Display information about Deleted items policy for spesfic user'
	write-host                                              ' 17)   Display information about Deleted items policy for ALL users'
	
	write-host  
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue '  Section H:  Export data  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 18)   Export data about Retention policy'
	write-host                                              ' 19)   Export data about Deleted items policy'

	
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor Blue  -BackgroundColor Yello ' Exit\Disconnect ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host  -ForegroundColor Yellow                       ' 20)  Disconnect PowerShell session'
	write-host 
	write-host  -ForegroundColor Yellow                       ' 21)  Exit'
	write-host 
	write-host                                          

	

    $opt = Read-Host "Select an option [0-21]"
    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:  Apply Retention policy
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	1
	{


				#####################################################################
				# Apply Retention policy for a Mailbox - Choose the Retention Policy 
				#####################################################################

				# 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  	'Apply the Retention Policy that you choose for a Mailbox. '
				write-host  -ForegroundColor white		--------------------------------------------------------------------  
				write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
				write-host  -ForegroundColor Yellow  	'Set-Mailbox <Mailbox> -RetentionPolicy <Policy Name> '
				write-host
				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 2 parameters:"  
					write-host
					write-host -ForegroundColor Yellow	"1.  Recipient name  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com"
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host
					write-host
					
					write-host ---------------------------------------------------------------------------
					write-host -ForegroundColor white	List of existing Retention Policys
					write-host ---------------------------------------------------------------------------

					Get-RetentionPolicy | FL Name   | Out-String

					write-host ---------------------------------------------------------------------------
					write-host
					write-host -ForegroundColor Yellow	"2) Retention Policy name"  
					write-host -ForegroundColor Yellow	"   For example: VIP Users"
					write-host
					$Rpolicy = Read-Host "Type the Retention Policy name "
					write-host
					write-host


					# Section 3: PowerShell Command

					Set-Mailbox $Alias -RetentionPolicy "$Rpolicy" 


				# 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 Retention Policy named: " -nonewline; write-host "$Rpolicy".ToUpper() -ForegroundColor White 
						write-host -ForegroundColor Yellow	"Is applied to: " -nonewline; write-host "$Alias".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 the Retention Policy for: "$Alias".ToUpper() Mailbox
						write-host ---------------------------------------------------------------------------

						Get-Mailbox "$Alias" | FL RetentionPolicy  | Out-String

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


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

	}




	2
	{


		#####################################################################
		#  Apply Default Retention policy for a Mailbox
		#####################################################################

		# Section 1: information 

		clear-host

		write-host
		write-host
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
		write-host  -ForegroundColor white		Information                                                                                          
		write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
		write-host  -ForegroundColor white  	'This option will: '
		write-host  -ForegroundColor white  	'Apply the default Retention Policy for a Mailbox '
		write-host  -ForegroundColor white		--------------------------------------------------------------------  
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Set-Mailbox <Alias> -RetentionPolicy "Default MRM Policy" '
		write-host
		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.  Recipient name  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com"
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host
					write-host

							# Section 3: PowerShell Command

							Set-Mailbox $Alias -RetentionPolicy "Default MRM Policy" 

							# 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 Default Retention Policy (Default MRM Policy) is applied to: " -nonewline; write-host "$Alias".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 the Retention Policy for: "$Alias".ToUpper() Mailbox
							write-host ---------------------------------------------------------------------------

							Get-Mailbox $Alias | FL RetentionPolicy  | Out-String


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

	}



	3
	{


	#####################################################################
	# Apply the Default Retention Policy to ALL Office 365 Mailboxes (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  	'This option will: '
	write-host  -ForegroundColor white  	'Apply the Default Retention Policy to ALL Office 365 Mailboxs (BULK Mode). '
	write-host  -ForegroundColor white		--------------------------------------------------------------------  
	write-host  -ForegroundColor white  	'The PowerShell command that we use are: '
	write-host  -ForegroundColor Yellow  	'$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} '
	write-host  -ForegroundColor Yellow  	'$UserMailboxes | Set-Mailbox RetentionPolicy "Default MRM Policy" '
	write-host
	write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
	write-host
	write-host


	# Section 2: user input



			# Section 3: PowerShell Command

			$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
			$UserMailboxes | Set-Mailbox RetentionPolicy "Default MRM Policy"


			$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
			$UserMailboxes | ForEach {Start-ManagedFolderAssistant $_.Identity}


			# 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 Retention Policy named: " -nonewline; write-host "Default MRM Policy".ToUpper() -ForegroundColor White 
			write-host -ForegroundColor Yellow	"Is applied to: ALL Office 365 Mailboxes  " 
			write-host -------------------------------------------------------------
			}

			# End of Indication 

			# Section 4: Display Information

			write-host
			write-host ---------------------------------------------------------------------------
			write-host -ForegroundColor white	Display information about Retention Policy to ALL Office 365 Mailboxs
			write-host ---------------------------------------------------------------------------

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

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


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

	}





#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section B:  Remove Retention policy
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	4
	{


		#####################################################################
		# Remove Retention Policy for a Mailbox (set to NULL)
		#####################################################################

		# 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  	'Remove Retention Policy for a Mailbox (set to NULL). '
		write-host  -ForegroundColor white		--------------------------------------------------------------------  
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Set-Mailbox <Alias> -RetentionPolicy $null '
		write-host
		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.  Recipient name  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com"
					write-host
					$Alias  = Read-Host "Type the Recipient name  "
					write-host
					write-host


					# Section 3: PowerShell Command

					Set-Mailbox $Alias -RetentionPolicy $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	"The Retention Policy for: " -nonewline; write-host "$Alias".ToUpper() -ForegroundColor White 
					write-host -ForegroundColor Yellow	"Was set to NULL " 
					write-host -------------------------------------------------------------
					}

					# End of Indication 

					# Section 4: Display Information

					write-host
					write-host ---------------------------------------------------------------------------
					write-host -ForegroundColor white	Display information about the Retention Policy for: "$UserAlias".ToUpper() Mailbox
					write-host ---------------------------------------------------------------------------

					Get-Mailbox "$UserAlias" | FL RetentionPolicy  | Out-String

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


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

	}



	5
	{


		#####################################################################
		#Remove Retention Policy for a Mailbox  Retention policy to ALL Office 365 Mailboxs (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  	'This option will: '
		write-host  -ForegroundColor white  	'Remove Retention Policy for ALL Office 365 Mailboxs (set to NULL). '
		write-host  -ForegroundColor white		--------------------------------------------------------------------  
		write-host  -ForegroundColor white  	'The PowerShell command that we use are: '
		write-host  -ForegroundColor Yellow  	'$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} '
		write-host  -ForegroundColor Yellow  	'$UserMailboxes | Set-Mailbox RetentionPolicy $null ' 
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
		write-host
		write-host

		# Section 2: user input

		# Section 3: PowerShell Command

		$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
		$UserMailboxes | Set-Mailbox RetentionPolicy $null


		$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
		$UserMailboxes | ForEach {Start-ManagedFolderAssistant $_.Identity}


		# 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 Retention Policy for ALL Office 365 user Mailboxes: " 
		write-host -ForegroundColor Yellow	"Was set to NULL " 
		write-host -------------------------------------------------------------
		}

		# End of Indication 

		# Section 4: Display Information

		write-host
		write-host ---------------------------------------------------------------------------
		write-host -ForegroundColor white	Display information about Retention Policy to ALL Office 365 Mailboxs
		write-host ---------------------------------------------------------------------------

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

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


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

	}





#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#  Section C: Display Retention Policy
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<




	6
	{


		#####################################################################
		# Display the Retention Policy applied to a User Mailbox 
		#####################################################################

		# Section 1: information 

		clear-host

		write-host
		write-host
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
		write-host  -ForegroundColor white		Information                                                                                          
		write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
		write-host  -ForegroundColor white  	'This option will: '
		write-host  -ForegroundColor white  	'Display the Retention Policy applied to a user Mailbox. '
		write-host  -ForegroundColor white		--------------------------------------------------------------------  
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Get-Mailbox <Alias> | FL RetentionPolicy '
		write-host
		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 2 parameters:"  
					write-host
					write-host -ForegroundColor Yellow	"1.  Recipient name  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com"
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host
					write-host

		

		# Section 4: Display Information

		write-host
		write-host ---------------------------------------------------------------------------
		write-host -ForegroundColor white	Display information about the Retention Policy for: "$Alias".ToUpper() Mailbox
		write-host ---------------------------------------------------------------------------

		Get-Mailbox $Alias | FL RetentionPolicy  | Out-String

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


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

	}







	7
	{


		#####################################################################
		#Display the Retention Policy applied to all Office 365 users Mailboxs
		#####################################################################

		# Section 1: information 

		clear-host

		write-host
		write-host
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
		write-host  -ForegroundColor white		Information                                                                                          
		write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
		write-host  -ForegroundColor white  	'This option will: '
		write-host  -ForegroundColor white  	'Display the Retention Policy applied to all Office 365 users Mailboxs. '
		write-host  -ForegroundColor white		--------------------------------------------------------------------  
		write-host  -ForegroundColor white  	'The PowerShell command that we use are: '
		write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'} | Select Alias, RetentionPolicy '
		write-host  
		write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
		write-host
		write-host



		# Section 2: user input



		# Section 3: PowerShell Command


		# Section 4:  Indication 


		# Section 4: Display Information

		write-host
		write-host ---------------------------------------------------------------------------
		write-host -ForegroundColor white	Display information about Retention Policy to ALL Office 365 Mailboxs
		write-host ---------------------------------------------------------------------------

		Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'} | Select Alias, RetentionPolicy | 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: Default Retention Policy Tags settings
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



	8
	{


		#####################################################################
		# Set the number of days for Deleted items Tag
		#####################################################################

		# 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  	'Set the number of days for Deleted items Tag '
		write-host  -ForegroundColor white  	'The default value for Deleted items tag: 30 Days '
		write-host  -ForegroundColor white  	'(Additional PowerShell command will run the Managed Folder Assistant) '
		write-host  -ForegroundColor white		--------------------------------------------------------------------  
		write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
		write-host  -ForegroundColor Yellow  	'Set-RetentionPolicyTag "Deleted Items" -AgeLimitForRetention <Days> '
		write-host
		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.  Number of days  "  
							write-host -ForegroundColor Yellow	"For example:  120"
							write-host
							$days  = Read-Host "Type the Number of days "
							write-host
							write-host

		# Section 3: PowerShell Command

		Set-RetentionPolicyTag "Deleted Items" -AgeLimitForRetention $days

		# Set-RetentionPolicyTag "Deleted Items" -AgeLimitForRetention <Days>

		$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
		$UserMailboxes | ForEach {Start-ManagedFolderAssistant $_.Identity}




		# 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	"Deleted items Tag is: " -nonewline; write-host "$days".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Days"
		write-host -------------------------------------------------------------
		}

		# End of Indication 

		# Section 4: Display Information

		write-host
		write-host ---------------------------------------------------------------------------
		write-host -ForegroundColor white	Display information about Deleted items Tag
		write-host ---------------------------------------------------------------------------

		Get-RetentionPolicyTag  "Deleted Items"   | FL Name , Type, Description , AgeLimitForRetention  | Out-String


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

	}




	9
	{


#####################################################################
# Disable Deleted items Tag
#####################################################################

# 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  	'Disable Deleted items Tag '
write-host  -ForegroundColor white  	'(Additional PowerShell command will run the Managed Folder Assistant) '
write-host  -ForegroundColor white		--------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-RetentionPolicyTag "Deleted Items" -RetentionEnabled $false '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command

Set-RetentionPolicyTag "Deleted Items" -RetentionEnabled $false
 


$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
$UserMailboxes | ForEach {Start-ManagedFolderAssistant $_.Identity}




# 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	"Deleted items Tag is Disabled " 
write-host -------------------------------------------------------------
}

# End of Indication 

# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display information about Deleted items Tag
write-host ---------------------------------------------------------------------------

Get-RetentionPolicyTag  "Deleted Items"   | FL Name , Type, Description , AgeLimitForRetention ,RetentionEnabled | Out-String


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

}




10{


#####################################################################
# Set the number of days for Junk Email Tag
#####################################################################

# 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  	'Set the number of days for Junk Email Tag '
write-host  -ForegroundColor white  	'The default value for Deleted items tag: 30 Days '
write-host  -ForegroundColor white  	'(Additional PowerShell command will run the Managed Folder Assistant) '
write-host  -ForegroundColor white		--------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-RetentionPolicyTag "Junk Email" -AgeLimitForRetention <Days> '
write-host
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.  Number of days  "  
					write-host -ForegroundColor Yellow	"For example:  120"
					write-host
					$days  = Read-Host "Type the Number of days "
					write-host
					write-host




# Section 3: PowerShell Command

Set-RetentionPolicyTag "Junk Email" -AgeLimitForRetention $days



$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
$UserMailboxes | ForEach {Start-ManagedFolderAssistant $_.Identity}


# 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	"Deleted items Tag is: " -nonewline; write-host "$days".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Days"
write-host -------------------------------------------------------------
}

# End of Indication 

# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display information about Deleted items Tag
write-host ---------------------------------------------------------------------------

Get-RetentionPolicyTag  "Deleted Items"   | FL Name , Type, Description , AgeLimitForRetention  | Out-String


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

}



#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section E: create NEW Retention Policy Tags
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<





11{


#####################################################################
# Create NEW tag for Sync Issues Folder
#####################################################################

# 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  	'Create NEW tag for Sync Issues Folder '
write-host  -ForegroundColor white  	'Set the Number of Days Value: 30 Days '
write-host  -ForegroundColor white  	'(Additional PowerShell command will run the Managed Folder Assistant) '
write-host  -ForegroundColor white		--------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'New-RetentionPolicyTag -Name <Tag name> -Type 'SyncIssues' -AgeLimitForRetention <days> -RetentionAction 'DeleteAndAllowRecovery' -RetentionEnabled $true '
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 parameter:"  
write-host
write-host -ForegroundColor Yellow	"1) The name for the Tag"  
write-host -ForegroundColor Yellow	"   For example: Sync Issues"
write-host
$TagName = Read-Host "Type the name for the Tag "
write-host
write-host -ForegroundColor Yellow	"1) The name for the Tag"  
write-host -ForegroundColor Yellow	"   For example: Sync Issues"
write-host
$days = Read-Host "Type the name for the Tag "

# Section 3: PowerShell Command

New-RetentionPolicyTag -Name $TagName -Type 'SyncIssues' -AgeLimitForRetention $days -RetentionAction 'DeleteAndAllowRecovery' -RetentionEnabled $true


# New-RetentionPolicyTag -Name <Tag name> -Type 'SyncIssues' -AgeLimitForRetention <Days> -RetentionAction 'DeleteAndAllowRecovery' -RetentionEnabled $true

$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
$UserMailboxes | ForEach {Start-ManagedFolderAssistant $_.Identity}




# 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 Tag Named: " -nonewline; write-host "$TagName".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" was created"
write-host -ForegroundColor Yellow	"The number of days value is:: " -nonewline; write-host "$days".ToUpper() -ForegroundColor White 
write-host -------------------------------------------------------------
}

# End of Indication 

# Section 4: Display Information



write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display information about: "$TagName".ToUpper() 
write-host ---------------------------------------------------------------------------

Get-RetentionPolicyTag  $TagName   | FL Name , Type, Description , AgeLimitForRetention  | Out-String | Out-String

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



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

}




#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section F: Managed Folder Assistant
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<




12{


#####################################################################
# Run the Managed Folder Assistant for a specific Mailbox
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Run the Managed Folder Assistant for a specific Mailbox. '
write-host  -ForegroundColor white  	'The Managed Folder Assistant runs at regular intervals,  '
write-host  -ForegroundColor white  	'And process the Retention settings applied to a Mailbox.  '
write-host  -ForegroundColor white  	'If you change a retention tag or apply a different retention policy to a Mailbox, '
write-host  -ForegroundColor white  	'you can wait for the next scheduled running of the Managed Folder Assistant, '
write-host  -ForegroundColor white  	'or "Activate" the Managed Folder Assistant, '
write-host  -ForegroundColor white  	'for Enforcing the update on the Mailbox.  '
write-host  -ForegroundColor white		--------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Start-ManagedFolderAssistant  <Alias> '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host
write-host -ForegroundColor Yellow	"Type the name the recipent Alias"  
write-host -ForegroundColor Yellow	"For example: John"
write-host
$Alias = Read-Host "Type the name the recipent Alias "
write-host

# Section 3: PowerShell Command

Start-ManagedFolderAssistant  $Alias




# 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 Managed Folder Assistant run for: " -nonewline; write-host "$Alias".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Mailbox"
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

}







13{


#####################################################################
#Run the Managed Folder Assistant for all Office 365 Mailboxes (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  	'This option will: '
write-host  -ForegroundColor white  	'Run the Managed Folder Assistant for all Office 365 Mailboxs. '
write-host  -ForegroundColor white  	'The Managed Folder Assistant runs at regular intervals,  '
write-host  -ForegroundColor white  	'And process the Retention settings applied to a Mailbox.  '
write-host  -ForegroundColor white  	'If you change a retention tag or apply a different retention policy to a Mailbox, '
write-host  -ForegroundColor white  	'you can wait for the next scheduled running of the Managed Folder Assistant, '
write-host  -ForegroundColor white  	'or "Activate" the Managed Folder Assistant, '
write-host  -ForegroundColor white  	'for Enforcing the update on ALL Office 365 Mailboxs.  '
write-host  -ForegroundColor white		--------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} '
write-host  -ForegroundColor Yellow  	'$UserMailboxes | ForEach {Start-ManagedFolderAssistant $_.Identity} '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input



# Section 3: PowerShell Command

$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
$UserMailboxes | ForEach {Start-ManagedFolderAssistant $_.Identity}


# Start-ManagedFolderAssistant Identity <MailBox>



# 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 Managed Folder Assistant run for all Office 365 Mailboxes (BULK Mode) " 
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 G:  Deleted items policy
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



14{


#####################################################################
#   Set Deleted items policy for 30 days for specific user
#####################################################################

# 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  	'Set Deleted items policy for 30 days for spesfic user  '

write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox <Alias> |Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor 30  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
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.  Recipient name  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com"
					write-host
					$Alias  = Read-Host "Type the Recipient name  "
					write-host
					write-host

# Step 1 : Display information before change


# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about Deleted items policy for: "$Alias".ToUpper() Mailbox
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias |FL alias,RetainDeletedItemsFor | Out-String

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  

# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information Display information for: "$Alias".ToUpper() Mailbox
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias |Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor 30 | Out-String

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  


# Step 3 : Display information after update 


# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about Deleted items policy for: "$Alias".ToUpper() Mailbox
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias |FL alias,RetainDeletedItemsFor | Out-String

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  


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

}



15{


#####################################################################
#  Set Deleted items policy for 30 days for ALL user (BULK)
#####################################################################

# 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  	'Set Deleted items policy for 30 days for ALL user (BULK)  '

write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-User -ResultSize Unlimited |Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor 30  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

# Section 2: user input


# Step 1 : Display information before change


# Section 3: PowerShell Command


# Section 3: PowerShell Command

write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
Get-Mailbox -ResultSize Unlimited |Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor 30  | Out-String

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  


# Section 4: export info



# Step 3 : Display information after update 


# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about Deleted items policy for: "$Alias".ToUpper() Mailbox
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox -ResultSize Unlimited |FL alias,RetainDeletedItemsFor | Out-String

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  




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

}



16{


#####################################################################
#  Display information about Deleted items policy for specific user
#####################################################################

# 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 Deleted items policy for spesfic user  '

write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox <Alias> |FL alias,RetainDeletedItemsFor  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
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.  Recipient name  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com"
					write-host
					$Alias  = Read-Host "Type the Recipient name  "
					write-host
					write-host


# Step 1 : Display information before change


# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about Deleted items policy for: "$Alias".ToUpper() Mailbox
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias |FL alias,RetainDeletedItemsFor | Out-String

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  


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

}







17{


#####################################################################
# Display information about Deleted items policy for ALL user
#####################################################################

# 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 Deleted items policy for ALL users  '

write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox |FL alias,RetainDeletedItemsFor  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
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.  Recipient name  "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com"
					write-host
					$Alias  = Read-Host "Type the Recipient name  "
					write-host
					write-host

# Step 1 : Display information before change


# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about Deleted items policy for ALL users
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox |FL alias,RetainDeletedItemsFor | Out-String

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  


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

}



#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#  Section H:  Export data
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



18{


#----------------------------------------------------------
$A1 =   "C:\INFO\1. Retention Policy "
$A11 =  "C:\INFO\1. Retention Policy\Reports "


if (!(Test-Path -path $A11))
{
New-Item $A11 -type directory
}


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


#####################################################################
#  Export data about Retention Policy
#####################################################################

# 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  	'Export data about Retention Policy  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited |Select alias,RetentionPolicy  '
write-host  -ForegroundColor white		---------------------------------------------------------------------------- 
write-host  -ForegroundColor white  	'The export command will create a folder named: INFO in c:\ drive '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

# Section 2: user input






#----------------------------------------------------------
# 1.Exchange Online objects - Mailbox
#----------------------------------------------------------


###TXT####
Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'} |FL alias,RetentionPolicy  >$A1\"RetentionPolicy.txt"
##########


###CSV####
Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'} |Select alias,RetentionPolicy | Export-CSV $A11\"RetentionPolicy.CSV" NoTypeInformation
##########


###HTML####
Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'} |Select alias,RetentionPolicy | ConvertTo-Html -head $htstyle -Body  "<H1> List of Retention Policy</H1>"  | Out-File $A11\"RetentionPolicy.HTML"
##########

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

}




19{


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

$A2 =   "C:\INFO\2. Deleted items policy "
$A21 =  "C:\INFO\2. Deleted items policy\Reports "


if (!(Test-Path -path $A21))
{
New-Item $A21 -type directory
}

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





#####################################################################
#  Export data about Deleted items policy
#####################################################################

# 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  	'Export data about Deleted items policy  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox -ResultSize Unlimited |Select alias,RetainDeletedItemsFor  '
write-host  -ForegroundColor white		---------------------------------------------------------------------------- 
write-host  -ForegroundColor white  	'The export command will create a folder named: INFO in C:\ drive '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

# Section 2: user input

#----------------------------------------------------------
# 1.Exchange Online objects - Mailbox
#----------------------------------------------------------


###TXT####
Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'} |FL  alias,RetainDeletedItemsFor  >$A2\"Deleted items policy.txt"
##########


###CSV####
Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'} |Select alias,RetainDeletedItemsFor | Export-CSV $A21\"Deleted items policy.CSV" NoTypeInformation
##########


###HTML####
Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'} |Select alias,RetainDeletedItemsFor | ConvertTo-Html -head $htstyle -Body  "<H1> List of Deleted items policy</H1>"  | Out-File $A21\"Deleted items policy.HTML"
##########

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


}




						
				 
				#+++++++++++++++++++
				# Step -05 Finish  
				##++++++++++++++++++
				 
				 
				20{

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


				}




				21{

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


				$Loop = $true
				Exit
				}

				}


				}
