

#------------------------------------------------------------------------------
# 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   :-)
# 20-4-2014    
# Version WP- 001
#------------------------------------------------------------------------------



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

}

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

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



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


$FormatEnumerationLimit = -1
$ExportInfo = "The information was exported to the following location C:\INFO"
$settings_array1 = "Received", "SenderAddress","RecipientAddress","Subject","Status", @{Name="size in KB";Expression={Format-BytesInKiloBytes -bytes $_.Size}},"MessageId","FromIP","ToIP"  
$settings_array3 = "Received", "SenderAddress","RecipientAddress","Subject","Status", @{Name="size in KB";Expression={$_.size / 1Kb}},"MessageId", "StartDate","EndDate","FromIP","ToIP" 
$Date = Get-Date

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

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

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

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

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

"@

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


clear-host

$Loop = $true
While ($Loop)
{
write-host 
write-host ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
write-host       Folder Permission: Calendar and Contacts menu 
write-host ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
write-host 
write-host '    Create Remote PowerShell session to Office 365 and Exchange Online' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host '0)  Login in using your Administrator credentials' -ForegroundColor Yellow
write-host
write-host '    Section A: Assign Permission to Calendar folder(Calendar Sharing) ' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host "1)  Assign Publishing Editor Permission to Calendar folder "
write-host "2)  Assign Permission to Mailbox Calendar folder - Choose the permissions  "
write-host "3)  Assign permission to specific user to all existing Calendars (BULK Mode) "
write-host "4)  Set the default permission of Calendar folder to: Publishing Editor "
write-host "5)  Set the default sharing permission for everyone to: Reviewer(BULK Mode) "
write-host
write-host '    Section B: Assign Permissions to Contacts folder (Contacts Sharing)' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host "6)  Assign Publishing Editor Permission to Contacts folder  "
write-host "7)  Assign Permission to Mailbox Contacts folder - Choose the permissions "
write-host "8)  Set the default permission of Contacts folder to: Publishing Editor   "
write-host
write-host '    Section C: Display Folder (Calendar and Contacts) and Mailbox Permissions (FULL ACCESS + SEND AS) ' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host "9)  Display  Calendar + Contacts Folder Permission "
write-host "10) Display FULL ACCESS + SEND AS + SEND ON BEHALF + Calendar Permissions for Mailbox "
write-host
write-host '    Section D: Remove Folder Permissions' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host "11) Remove Permission from a Calendar folder for a specific user "
write-host "12) Remove Permission from a Contacts folder for a specific user "
write-host "13) Remove permission for a specific user from all Calendars (BULK Mode) "
write-host "14) Reassign Publishing Editor calendar permission (Remove + add calendar permissions) for a specific user "
write-host
write-host '    Section E: Working with folder in other Language' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host "15) Assign Publishing Editor Permission to Calendar folder - Different Language "
write-host "16) Display  Calendar + Contacts Folder Permission - Different Language "
write-host "17) Remove Permission from a Calendar folder for a specific user - Different Language"
write-host "18) Reset mailbox folders Language to English "
write-host
write-host '    Section F: Assign Mailbox permissions' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host '19) Assign "FULL ACCESS" Permissions for a Mailbox'
write-host '20) Assign "SEND AS" Permissions for a Mailbox'
write-host '21) Assign "FULL ACCESS + SEND AS" Permissions for a Mailbox'
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host
write-host '    Section G: Assign folder permissions' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host '22) Assign Reviewer Folder Permissions to specific mailbox folder '
write-host '23) Assign Recursive Shared Folder Permissions '
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host
write-host '    Section H: Troubleshooting' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host '24) Toggle calendar folder permissions '
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host
write-host '    Section I: Export Calendar information' -ForegroundColor green
write-host '    --------------------------------------------------------------' -ForegroundColor green
write-host '25) Export folder permission for all of the recipients (Bulk mode)'
write-host '26) Export Calendar information of a specific mailbox'
write-host '    --------------------------------------------------------------' -ForegroundColor green


write-host "30) Disconnect the Current PowerShell session" -ForegroundColor Red
write-host
write-host "31) Exit" -ForegroundColor Red
write-host

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

{





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


		0
        {

            # Specify your administrative user credentials on the line below 

            $user = “Admin@.....”

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

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

            

            #———— Establish an Remote PowerShell Session to Exchange Online ———————

            $msoExchangeURL = “https://outlook.office365.com/powershell-liveid/”
			$connected = $False	
			$i = 0
			while ( -not ($connected)) {
				$i++
				if($i -eq 4){
					
										
					Write-host
					Write-host -ForegroundColor White	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
					Write-host -ForegroundColor Red    "Too many incorrect login attempts. Good bye."	
					Write-host
					Write-host -ForegroundColor White	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
					
					
					exit
				}
				$cred = Get-Credential -Credential $user
				try 
				{
					$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $msoExchangeURL -Credential $cred -Authentication Basic -AllowRedirection  -ErrorAction stop
					Connect-MsolService -Credential $cred -ErrorAction stop
					Import-PSSession $session 
					$connected = $true 
				}
				catch 
				{
					Write-host
					Write-host -ForegroundColor Yellow	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
					Write-host -ForegroundColor Red    "There is something wrong with the global administrator credentials"	
					Write-host
					Write-host -ForegroundColor Yellow	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
				}

			}
            
			$host.ui.RawUI.WindowTitle = ("Windows Azure Active Directory |Connected to Office 365 using: " + $Cred.UserName.ToString()  ) 

            


        }

		
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section A:  Assign Permission to Calendar folder
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


1{


#####################################################################
#   Assign Publishing Editor Permission to Calendar 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  	'Assign Publishing Editor Permissions to User  '
write-host  -ForegroundColor white  	'For a user Calendar folder  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Add-MailboxFolderPermission -Identity <User>:\calendar -AccessRights PublishingEditor -User <User> '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User which want to give permission to his calendar ( The manager )"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
write-host
$MailBox = Read-Host "Type the User name That wants to share his calendar ( The manager ) "
write-host
write-host -ForegroundColor Yellow	"2) The Second parameter is the name of the User ( The assistant ) " 
write-host -ForegroundColor Yellow	"That will have Permission to $MailBox calendar"   
write-host
$MailRecipient =  Read-Host "Type the User name that needs access to the calendar ( The assistant )"

# Section 3: PowerShell Command

$mbox = $MailBox+":\calendar"


Add-MailboxFolderPermission –Identity $mbox -AccessRight PublishingEditor -User $MailRecipient


# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
	write-host -------------------------------------------------------------
	write-host -ForegroundColor Yellow	"The command complete successfully !" 
	write-host
	write-host -ForegroundColor Yellow	"User named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White	 
	write-host -ForegroundColor Yellow	"Have "	-nonewline; write-host "Publishing Editor".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Permission for  "	
  	write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	" Calendar folder" 
	write-host -------------------------------------------------------------
}

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

# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display Calendar Permission for $MailBox.ToUpper() Calendar
write-host ---------------------------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox |  Out-String


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

}


2{


#####################################################################
# Assign Permission to Mailbox Calendar folder - Choose the Calendar permissions
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		--------------------------------------------------------------------                                                           
write-host  -ForegroundColor white  	"This option will:  "
write-host  -ForegroundColor white  	"Assign Chosen Permissions to User "
write-host  -ForegroundColor white  	"For a specific Calendar folder."
write-host  -ForegroundColor white  	"Possible option for permissions are:"
write-host  -ForegroundColor white  	"Owner, PublishingEditor, Editor, PublishingAuthor, Author"
write-host  -ForegroundColor white  	"NonEditingAuthor, Reviewer, Contributor, AvailabilityOnly, LimitedDetails"
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Add-MailboxFolderPermission -Identity <User>:\calendar -AccessRights PublishingEditor -User <User> '
write-host  -ForegroundColor Magenta	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 3 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User which want to give permission to his calendar ( The manager )"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
write-host
$MailBox = Read-Host "Type the User name That wants to share his calendar ( The manager ) "
write-host
write-host -ForegroundColor Yellow	"2) The Second parameter is the name of the User ( The assistant ) " 
write-host -ForegroundColor Yellow	"That will have Permission to $MailBox calendar"   
write-host
$MailRecipient =  Read-Host "Type the User name that needs access to the calendar ( The assistant )"
	
write-host
write-host -ForegroundColor Yellow	"3) The Third parameter is the permission that you want to assign"  
write-host
$prem =  Read-Host "Type the required permission type"	

# Section 3: PowerShell Command

$mbox = $MailBox+":\calendar"	

	
Add-MailboxFolderPermission -Identity $mbox  -AccessRights $prem -User $MailRecipient	
	
# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host -ForegroundColor Yellow	"User/Distribution Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White	 
write-host -ForegroundColor Yellow	"Have "	-nonewline; write-host "$prem".ToUpper() -ForegroundColor White ;write-host -ForegroundColor Yellow	"Permission for "	-nonewline;
write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	" Calendar" 
write-host -------------------------------------------------------------
	
}

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

# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor Yellow  Display of Calendar Permission for $MailBox.ToUpper() Calendar
write-host ---------------------------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName ,user, AccessRights | Out-String


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

}


3{


#####################################################################
#  Assign permission to specific user to all existing Calendars (BULK Mode)
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	"The following option will assign permission for a user or distribution group   "
write-host  -ForegroundColor white  	"for all of the users calendars (Bulk Mode)"
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'$mailboxes = Get-Mailbox '
write-host  -ForegroundColor Yellow  	'$mailboxes | ForEach-Object {Add-MailboxFolderPermission $_":\Calendar" -User $MailRecipient -AccessRights $prem} '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


	
write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter The name of the User or Distribution Group" 
write-host -ForegroundColor Yellow	"   That will have Permission to all users calendar"   
write-host
$MailRecipient =  Read-Host "Type the User or Distribution Group name that needs access to the calendar"
	
write-host
write-host -ForegroundColor Yellow	"2) The Second parameter is the permission that you want to assign to the user/DL"
write-host -ForegroundColor Yellow	"   Possible options for permissions are:" 
write-host -ForegroundColor white	"   Owner, PublishingEditor, Editor, PublishingAuthor, Author"
write-host -ForegroundColor white	"   NonEditingAuthor, Reviewer, Contributor, AvailabilityOnly, LimitedDetails"    
write-host
$prem =  Read-Host "Type the required permission type"		
write-host	


# Section 3: PowerShell Command

$mailboxes = Get-Mailbox
 
$mailboxes | ForEach-Object {Add-MailboxFolderPermission $_":\Calendar" -User $MailRecipient -AccessRights $prem}

# 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	"User/Distribution Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White	 
	write-host -ForegroundColor Yellow	"Have "	-nonewline; write-host "$prem".ToUpper() -ForegroundColor White ;write-host -ForegroundColor Yellow	"Permission for "	-nonewline;
  	write-host -ForegroundColor white	"All users Calendar" 
	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

}


4{


#####################################################################
#   Set the default permission of calendar to: Publishing Editor
#####################################################################

# 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 default calendar folder permissions to: Publishing Editor.'
write-host  -ForegroundColor white  	'The meaning is that: all of the users will have Publishing Editor permission to the calendar folder'
write-host  -ForegroundColor white  	'This option is suitable for “Public Contacts” scenarios.'
write-host  -ForegroundColor white  	'For example: when we use a Resource Mailbox.  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'$mbox = <user>:\calendar '
write-host  -ForegroundColor Yellow  	'Set-MailboxFolderPermission –Identity $mbox –User default –AccessRights PublishingEditor  '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


	
write-host -ForegroundColor Yellow	"You will need to provide 1 parameters"  
write-host
write-host -ForegroundColor Yellow	"1) The User or Distribution Group" 
write-host -ForegroundColor Yellow	"   That will have Permission to all users calendar"   
write-host

write-host
$MailBox = Read-Host "Type the User name his Calendar will be shared " 

# Section 3: PowerShell Command

$mbox = $MailBox+":\calendar"

Set-MailboxFolderPermission –Identity $mbox –User default –AccessRights PublishingEditor   

# 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 permission for " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White ;write-host -ForegroundColor Yellow	"calendar "	-nonewline;	 
	write-host -ForegroundColor Yellow	"was set to: "	-nonewline; write-host "Publishing Editor".ToUpper() -ForegroundColor White 
	write-host -------------------------------------------------------------
}

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

# Section 4: Display Information

write-host
write-host	
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow  Display of Calendar Permission for $MailBox.ToUpper() Calendar
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName ,user, AccessRights | Out-String

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


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

}





5{


#####################################################################
#   Set the default sharing permission for everyone in your organization to: Reviewer(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  	"set the default Calendar permissions to Publishing Editor."
write-host  -ForegroundColor white  	"The meaning is that all of the users will have Publishing Editor permission to the user Calendar"
write-host  -ForegroundColor white  	"This option is suitable for “Public Calendar” scenarios"
write-host  -ForegroundColor white  	"for example: the need to share resource mailbox or shared mailbox Calendar"
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'$mbox = $MailBox+":\calendar" '
write-host  -ForegroundColor Yellow  	'Set-MailboxFolderPermission –Identity $mbox –User default –AccessRights PublishingEditor  '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


# Section 3: PowerShell Command

foreach($user in  Get-Mailbox -RecipientTypeDetails UserMailbox) 
{
 $cal = $user.alias+":\Calendar" 
Set-MailboxFolderPermission -Identity $cal -User Default -AccessRights Reviewer
}

# 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 permission for " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White ;write-host -ForegroundColor Yellow	"calendar "	-nonewline;	 
	write-host -ForegroundColor Yellow	"was set to: "	-nonewline; write-host "Publishing Editor".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:  Assign Permission to Contacts folder
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



6{


#####################################################################
#   Assign Publishing Editor Permission to Contacts 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  	'Assign Publishing Editor Permissions to User or Distribution Group'
write-host  -ForegroundColor white  	'For a specific Contacts folder'
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Add-MailboxFolderPermission -Identity <User>:\Contacts -AccessRights PublishingEditor -User <User> '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User which want to give permission to his Contacts ( The manager )"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
write-host
$MailBox = Read-Host "Type the User name That wants to share his Contacts ( The manager ) "
write-host
write-host -ForegroundColor Yellow	"2) The Second parameter is the name of the User ( The assistant ) " 
write-host -ForegroundColor Yellow	"That will have Permission to $MailBox Contacts"   
write-host
$MailRecipient =  Read-Host "Type the User name that needs access to the Contacts ( The assistant )"


# Section 3: PowerShell Command

$mbox = $MailBox+":\Contacts"


Add-MailboxFolderPermission –Identity $mbox -AccessRight PublishingEditor -User $MailRecipient


# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
	write-host -------------------------------------------------------------
	write-host -ForegroundColor Yellow	"The command complete successfully !" 
	write-host
	write-host -ForegroundColor Yellow	"User/Distribution Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White	 
	write-host -ForegroundColor Yellow	"Have "	-nonewline; write-host "Publishing Editor".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Permission for  "	
  	write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	" Contacts" 
	write-host -------------------------------------------------------------
}

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

# Section 4: Display Information

write-host
write-host
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow  Display of Permission for $MailBox.ToUpper() Contacts folder
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName, user, AccessRights | Out-String

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


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

}


7{


#####################################################################
#   Assign Permission to Mailbox Contacts folder - Choose the Contacts permissions
#####################################################################

# 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  	"Assign Chosen Permissions to User or Distribution Group"
write-host  -ForegroundColor white  	"For the Contacts folder."
write-host  -ForegroundColor white  	"Possible option for permissions are:"
write-host  -ForegroundColor white  	"Owner, PublishingEditor, Editor, PublishingAuthor, Author"
write-host  -ForegroundColor white  	"NonEditingAuthor, Reviewer, Contributor, AvailabilityOnly, LimitedDetails"
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Add-MailboxFolderPermission -Identity <user>:\Contacts -AccessRights PublishingEditor -User <user> '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 3 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User which want to give permission to his Contacts ( The manager )"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
write-host
$MailBox = Read-Host "Type the User name That wants to share his Contacts ( The manager ) "
write-host
write-host -ForegroundColor Yellow	"2) The Second parameter is the name of the User ( The assistant ) " 
write-host -ForegroundColor Yellow	"That will have Permission to $MailBox Contacts"   
write-host
$MailRecipient =  Read-Host "Type the User name that needs access to the Contacts ( The assistant )"
	
write-host
write-host -ForegroundColor Yellow	"3) The Third parameter is the permission that you want to assign"  
write-host
$prem =  Read-Host "Type the required permission type"	



# Section 3: PowerShell Command

$mbox = $MailBox+":\Contacts"	

	
Add-MailboxFolderPermission -Identity $mbox -User $MailRecipient -AccessRights $prem 

	

# 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	"User/Distribution Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White	 
write-host -ForegroundColor Yellow	"Have "	-nonewline; write-host "$prem".ToUpper() -ForegroundColor White ;write-host -ForegroundColor Yellow	"Permission for "	-nonewline;
write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	" Contacts folder " 
write-host -------------------------------------------------------------
		
	
}

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

# Section 4: Display Information

write-host
write-host	
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow  Display of Contacts Permission for $MailBox.ToUpper() Contacts folder
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName ,user, AccessRights | Out-String

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


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

}


8{


#####################################################################
#  Set the default permission for Contacts to: Publishing Editor 
#####################################################################

# 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 default Contacts folder permissions to: Publishing Editor.'
write-host  -ForegroundColor white  	'The meaning is that: all of the users will have Publishing Editor permission to the Contacts folder'
write-host  -ForegroundColor white  	'This option is suitable for “Public Contacts” scenarios.'
write-host  -ForegroundColor white  	'For example: when we use a Resource Mailbox.  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'$mbox = <user>:\Contacts '
write-host  -ForegroundColor Yellow  	'Set-MailboxFolderPermission –Identity $mbox –User default –AccessRights PublishingEditor  '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host

# Section 2: user input
	
write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
write-host
write-host -ForegroundColor Yellow	"1) The User that want to share his contact folder"   
write-host

write-host

write-host
$MailBox = Read-Host "Type the User name his Contacts folder will be shared " 

# Section 3: PowerShell Command

$mbox = $MailBox+":\Contacts"

Set-MailboxFolderPermission –Identity $mbox –User default –AccessRights PublishingEditor   

# 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 permission for " -nonewline; write-host "$MailBox".ToUpper() -ForegroundColor White ;write-host -ForegroundColor Yellow	"Contacts "	-nonewline;	 
	write-host -ForegroundColor Yellow	"was set to: "	-nonewline; write-host "Publishing Editor".ToUpper() -ForegroundColor White 
	write-host -------------------------------------------------------------
}

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

# Section 4: Display Information

write-host
write-host	
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow  Display of Calendar Permission for $MailBox.ToUpper() Calendar
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName ,user, AccessRights | Out-String

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


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

}



#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#  Section C: Display Folder Permissions (Calendar and Contacts)
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



9{


#####################################################################
#   Display  Calendar + Contacts Folder Permission
#####################################################################

# 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  	'Display the Permissions that other users have for the User calendar and Contacts folders '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use are: '
write-host  -ForegroundColor white  	'Calnder Folder Permissions: '
write-host  -ForegroundColor Yellow  	'Get-MailboxFolderPermission -identity <user>:\calendar | Select FolderName, user, AccessRights '
write-host  -ForegroundColor white  	'Contacts Folder Permissions: '
write-host  -ForegroundColor Yellow  	'Get-MailboxFolderPermission -identity <user>:\ContactsDisplay the  | Select FolderName, user, AccessRights '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
write-host
write-host -ForegroundColor Yellow	"provide the user name that you want to display his folder permissions for:  " 
write-host -ForegroundColor Yellow	"calendar and contacts folders."   
write-host -ForegroundColor Yellow	"For example: user1"
write-host
$MailBox = Read-Host "Type the User name that wants to display his folder permissions "
write-host

# Section 3: PowerShell Command

$mbox = $MailBox+":\calendar"

$con = $MailBox+":\Contacts"



write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox.ToUpper() Mailbox
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Out-String


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


write-host -ForegroundColor Yellow Contacts folder Permission for $MailBox.ToUpper() Mailbox
write-host -----------------------------------------------------------------

Get-MailboxFolderPermission -identity $con | Out-String


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


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

}







10{

####################################################################################################
#Display User (or Distribution Group) that have FULL ACCESS + SEND AS permissions for a MailBox  
######################################################################################################

# Section 1: information


clear-host

write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Instructions                                                                                          
write-host  -ForegroundColor white		--------------------------------------------------------------------                                                           
write-host  -ForegroundColor white  	'This option will Display'
write-host  -ForegroundColor white  	'Information about permission for mailbox for: ' 	
write-host  -ForegroundColor white  	'*calendar permission  '
write-host  -ForegroundColor white  	'*Contacts permission  '
write-host  -ForegroundColor white  	'*FULL ACCESS Permissions  '
write-host  -ForegroundColor white  	'*SEND AS Permissions'
write-host  -ForegroundColor white  	'*SEND ON BEHALF'
write-host  -ForegroundColor white  	'For a specific Mailbox '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host

# Section 2: user input	
	

write-host -ForegroundColor Yellow	"You will need to provide 1 parameters:"  
write-host
write-host -ForegroundColor Yellow	"provide the user name that you want to display his folder and mailbox permissions for:  " 
write-host -ForegroundColor Yellow	"calendar and contacts folders +FULL ACCESS and SEND AS Permissions ."   
write-host -ForegroundColor Yellow	"For example: user1"
write-host
$MailBox = Read-Host "Type the User name That wants to display his folder permissions "
write-host
$mbox = $MailBox+":\calendar"

$con = $MailBox+":\Contacts"


# Section 3: PowerShell Command
#Section 3: Display Information


write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	1. Display information about: $Alias.ToUpper() Mailbox "Calendar".ToUpper() Permission
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-MailboxFolderPermission -identity $mbox | Select FolderName, user, AccessRights | Out-String

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




write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	2. Display information about: $Alias.ToUpper() Mailbox "Contacts".ToUpper() Permission
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-MailboxFolderPermission  $con | Select FolderName, user, AccessRights | Out-String
write-host
write-host
write-host  -ForegroundColor white		---------------------------------------------------------------------------- 



write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	3. Display information about: $Alias.ToUpper() Mailbox "FULL ACCESS".ToUpper() Permission
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-mailboxpermission $MailBox | where { ($_.IsInherited -eq $False	) -and -not ($_.User -like “NT AUTHORITY\SELF”) } |Select Identity, user, AccessRights | Out-String
write-host
write-host
write-host  -ForegroundColor white		---------------------------------------------------------------------------- 




write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	4. Display information about: $Alias.ToUpper() Mailbox "SEND AS".ToUpper() Permission
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-RecipientPermission  $MailBox | where { ($_.IsInherited -eq $False	) -and -not ($_.Trustee -like “NT AUTHORITY\SELF”) } | Select Trustee, AccessControlType, AccessRights | Out-String
write-host
write-host
write-host  -ForegroundColor white		---------------------------------------------------------------------------- 



write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	5. Display information about: $Alias.ToUpper() Mailbox "send On Behalf".ToUpper() Permission
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host
Get-Mailbox $MailBox | fl displayname,GrantSendOnBehalfTo | Out-String
# Get-RecipientPermission  $MailBox | where { ($_.IsInherited -eq $False	) -and -not ($_.Trustee -like “NT AUTHORITY\SELF”) } | Select Trustee, AccessControlType, AccessRights | 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 D: Remove Folder Permissions
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


11{


#####################################################################
#   Remove Permission from a Calendar folder for a 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  	"Remove Permissions to User or Distribution Group"
write-host  -ForegroundColor white  	"For a Calendar folder."
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Remove-MailboxFolderPermission  -Identity <user>  -User <user> '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input

write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User which want to remove permission from his calendar ( The manager )"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
write-host
$MailBox = Read-Host "Type the User name User which want to remove permission from his calendar ( The manager ) "
write-host


# Section 3: PowerShell Command


$mbox = $MailBox+":\calendar"


write-host -ForegroundColor Yellow	"This is a list of permissions to $MailBox calendar"
write-host -ForegroundColor Yellow	"Use this list to locate the user name that you want to remove from the list "
write-host -ForegroundColor Yellow	"The list present the display name value of the users that have permission to the calendar "   
write-host
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox mailbox
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Out-String

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

write-host -ForegroundColor Yellow	"2) The Second parameter is the name of the User ( The assistant ) " 
write-host -ForegroundColor Yellow	"That his Permission to $MailBox calendar will be removed"   
write-host
$MailRecipient =  Read-Host "Type the User name his Permission to $MailBox calendar will be removed ( The assistant )"

write-host
$MailRecipient =  Read-Host "Type the User  name "
$mbox = $MailBox+":\calendar"	

Remove-MailboxFolderPermission  -Identity $mbox  -User $MailRecipient  	-Confirm:$False	


# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The permissions of: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White ;	write-host -ForegroundColor Yellow	"for " -nonewline
write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	"  Calendar" 
write-host -ForegroundColor Yellow	"Was removed "
write-host -------------------------------------------------------------
}

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

# Section 4: Display Information

write-host
write-host
write-host -ForegroundColor Yellow	"Use the permission list to verify that the permissions for $MailRecipient was removed"

write-host
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox mailbox
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName, user, AccessRights | Out-String

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


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

}






12{


#####################################################################
#   Remove Permission from a Contacts folder for a 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  	"Remove Permissions of User(or Distribution Group)"
write-host  -ForegroundColor white  	"From a Contacts folder."
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Remove-MailboxFolderPermission  -Identity <user>  -User <user> '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User name which want to remove permission to his Contacts"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
$MailBox = Read-Host "Type the User name "
write-host
write-host


# Section 3: PowerShell Command


$mbox = $MailBox+":\Contacts"


write-host -ForegroundColor Yellow	"This is a list of permissions to $MailBox Contacts"
write-host -ForegroundColor Yellow	"Use this list to locate the user or the distribution group to want to remove from the list "
write-host
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Contacts Permission for $MailBox mailbox
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName, user, AccessRights | Out-String

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

write-host -ForegroundColor Yellow	"2) The Second parameter The name of the User(or Distribution Group)" 
write-host -ForegroundColor Yellow	"That You want to remove there permissions for $MailBox Contacts folder"   
write-host
$MailRecipient =  Read-Host "Type the User or Distribution Group name "
$mbox = $MailBox+":\Contacts"	

Remove-MailboxFolderPermission  -Identity $mbox  -User $MailRecipient  	-Confirm:$False	
	


# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The permissions of: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White ;	write-host -ForegroundColor Yellow	"for " -nonewline
write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	" Calendar" 
write-host -ForegroundColor Yellow	"Was removed "
write-host -------------------------------------------------------------
}

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

# Section 4: Display Information

write-host
write-host
write-host -ForegroundColor Yellow	"Use the permission list to verify that the permissions for $MailRecipient was removed"

write-host
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox mailbox
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName, user, AccessRights | Out-String

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


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

}




13{


#####################################################################
#    Remove permission for a specific user from all Calendars (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 is suitable for scenarios in which a specific user has  '
write-host  -ForegroundColor white  	'permissions to all of the organization users calendars  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox | ForEach-Object {Remove-MailboxFolderPermission $_":\Calendar" -User $MailRecipient  } -Confirm:$False	 '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"Type the name of the User(or Distribution Group)" 
write-host -ForegroundColor Yellow	"That You want to remove there permissions from all mailboxes"  

$MailRecipient =  Read-Host "Type the User( or Distribution Group) name "




# Section 3: PowerShell Command


$mailboxes = Get-Mailbox
 
$mailboxes | ForEach-Object {Remove-MailboxFolderPermission $_":\Calendar" -User $MailRecipient  } 	-Confirm:$False	

# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
	write-host -------------------------------------------------------------
	write-host -ForegroundColor Yellow	"The command complete successfully !" 
	write-host
	write-host -ForegroundColor Yellow	"The permissions of:" -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White	 
	write-host -ForegroundColor Yellow	"Was removed from all users calendars" 
	write-host -------------------------------------------------------------
}


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



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

}





14{


#####################################################################
#   Reassign PublishingEditor  calendar permission (remove + add calendar permissions) for a 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  	"Reassign calendar permission (remove + add calendar permissions) for a specific user"
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User name which want to remove permission to his calendar"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
$MailBox = Read-Host "Type the User name "
write-host
write-host

# Section 3: PowerShell Command

$mbox = $MailBox+":\calendar"

write-host -ForegroundColor Yellow	"This is a list of permissions to $MailBox calendar"
write-host -ForegroundColor Yellow	"Use this list to locate the user or the distribution group to want to remove from the list "
write-host
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox mailbox
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName, user, AccessRights | Out-String

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

write-host -ForegroundColor Yellow	"2) The Second parameter The name of the User " 
write-host -ForegroundColor Yellow	"You want to remove there permissions to $MailBox calendar"   
write-host
$MailRecipient =  Read-Host "Type the User name "
$mbox = $MailBox+":\calendar"	

Remove-MailboxFolderPermission  -Identity $mbox  -User $MailRecipient  	-Confirm:$False	
	
# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The permissions of: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White ;	write-host -ForegroundColor Yellow	"for " -nonewline
write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	"Calendar" 
write-host -ForegroundColor Yellow	"Was removed "
write-host -------------------------------------------------------------
}

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


write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	"In this step we will reassign $MailRecipient  "
write-host  -ForegroundColor white  	"PublishingEditor permissions to $MailBox mailbox"
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host




Add-MailboxFolderPermission –Identity $mbox -AccessRight PublishingEditor -User $MailRecipient



write-host
write-host



# Section 4: Display Information

write-host
write-host
write-host -ForegroundColor Yellow	"Use the permission list to verify that the permissions for $MailRecipient was removed"

write-host
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox mailbox
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName, user, AccessRights | Out-String

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


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

}



	




#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section E: Working with folder in other Language
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


15{


#####################################################################
#  Assign Publishing Editor Permission to Calendar folder - Different Language
#####################################################################

# 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  	'Assign Publishing Editor Permission to Calendar folder - Different Language  '
write-host  -ForegroundColor white  	'For a user Calendar folder  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User name which want to give permission to his calendar"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
write-host
$MailBox = Read-Host "Type the User name That wants to share his calendar "
write-host
write-host -ForegroundColor Yellow	"2) The Second parameter The name of the User or Distribution Group" 
write-host -ForegroundColor Yellow	"That will have Permission to $MailBox calendar"   
write-host
$MailRecipient =  Read-Host "Type the User or Distribution Group name that needs access to the calendar"

# Section 3: PowerShell Command

$mbox = $MailBox+":\calendar"


$id = $MailBox; $id += ":\" + (Get-MailboxFolderStatistics -Identity $id | Where-Object {$_.FolderType -eq "Calendar"}).Name; Add-MailboxFolderPermission $id -User $MailRecipient -AccessRights PublishingEditor 

# 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	"User/Distribution Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White	 
	write-host -ForegroundColor Yellow	"Have "	-nonewline; write-host "Publishing Editor".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Permission for  "	
  	write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	" Calendar folder" 
	write-host -------------------------------------------------------------
}

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

# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display of Calendar Permission for $MailBox Calendar
write-host ---------------------------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Select FolderName ,user, AccessRights | Out-String


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

}





16{


#####################################################################
#   Display  Calendar + Contacts Folder Permission - Different Language
#####################################################################

# 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  Calendar + Contacts Folder Permission - Different Language '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 1 parameters:"  
write-host
write-host -ForegroundColor Yellow	"provide the user name that you want to display his folder permissions for:  " 
write-host -ForegroundColor Yellow	"calendar and contacts folders."   
write-host -ForegroundColor Yellow	"For example: user1"
write-host
$MailBox = Read-Host "Type the User name That wants to display his folder permissions "
write-host

# Section 3: PowerShell Command

$mbox = $MailBox+":\calendar"

$con = $MailBox+":\Contacts"



write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox.ToUpper() Mailbox
write-host -------------------------------------------------------

$id = $MailBox; $id += ":\" + (Get-MailboxFolderStatistics -Identity $id | Where-Object {$_.FolderType -eq "Calendar"}).Name; Get-MailboxFolderPermission $id | Out-String
write-host
write-host -------------------------------------------------------



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

}






17{


#####################################################################
#  Remove Permission from a Calendar folder for a specific user - Different Language
#####################################################################

# 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 Permission from a Calendar folder for a specific user - Different Language"
write-host  -ForegroundColor white  	"For a Calendar folder."
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User name which want to remove permission to his calendar"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
$MailBox = Read-Host "Type the User name "
write-host
write-host


# Section 3: PowerShell Command


$mbox = $MailBox+":\calendar"


write-host -ForegroundColor Yellow	"This is a list of permissions to $MailBox calendar"
write-host -ForegroundColor Yellow	"Use this list to locate the user name that you want to remove from the list "
write-host -ForegroundColor Yellow	"The list present the display name value of the users that have permission to the calendar "   
write-host

write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox.ToUpper() Mailbox
write-host -------------------------------------------------------


$id = $MailBox; $id += ":\" + (Get-MailboxFolderStatistics -Identity $id | Where-Object {$_.FolderType -eq "Calendar"}).Name; Get-MailboxFolderPermission $id | Out-String
write-host
write-host -------------------------------------------------------

write-host

write-host -ForegroundColor Yellow	"2) The Second parameter is the name of the User " 
write-host -ForegroundColor Yellow	"You want to remove there permissions from $MailBox calendar"   

write-host
$MailRecipient =  Read-Host "Type the User  name "
$mbox = $MailBox+":\calendar"	



$id = "$MailBox"; $id += ":\" + (Get-MailboxFolderStatistics -Identity $id | Where-Object {$_.FolderType -eq "Calendar"}).Name; Remove-MailboxFolderPermission $id -User $MailRecipient -Confirm:$False	 


# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The permissions of: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White ;	write-host -ForegroundColor Yellow	"for " -nonewline
write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	"  Calendar" 
write-host -ForegroundColor Yellow	"Was removed "
write-host -------------------------------------------------------------
}

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

# Section 4: Display Information

write-host
write-host
write-host -ForegroundColor Yellow	"Use the permission list to verify that the permissions for $MailRecipient was removed"


write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox.ToUpper() Mailbox
write-host -------------------------------------------------------

$id = $MailBox; $id += ":\" + (Get-MailboxFolderStatistics -Identity $id | Where-Object {$_.FolderType -eq "Calendar"}).Name; Get-MailboxFolderPermission $id | Out-String
write-host
write-host -------------------------------------------------------

write-host


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

}




18{


#####################################################################
# Reset mailbox folders Language to English
#####################################################################

# 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  	'Reset mailbox folders Language to English  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'set-MailboxRegionalConfiguration –identity <MailBox> –Language en-US  '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 1 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User name which we need to reset his folder names to English  "  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
write-host
$MailBox = Read-Host "Type the User name That wants to reset his folder names to English "
write-host

# Section 3: PowerShell Command


set-MailboxRegionalConfiguration –identity $MailBox –Language en-US 



write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display information about Time Zone and Language for $MailBox 
write-host ---------------------------------------------------------------------------

Get-MailboxRegionalConfiguration -identity $MailBox 



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

}






#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Section F: Assign Mailbox permissions
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

19{

####################################################################################################
# Assign "FULL ACCESS" Permissions for a Mailbox
######################################################################################################

# Section 1: information 

clear-host

write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
write-host  -ForegroundColor white		Instructions                                                                                          
write-host  -ForegroundColor white		--------------------------------------------------------------------                                                           
write-host  -ForegroundColor white  	'This option will:  '
write-host  -ForegroundColor white  	'Assign Publishing Editor Permissions to User(or Distribution Group)'
write-host  -ForegroundColor white  	'For a specific Mailbox. '
write-host  -ForegroundColor white  	'For example: Assign permission to assistant "(User B)" that needs permission to'   
write-host  -ForegroundColor white  	'Access the manager Mailbox "(User A)" .'
write-host  -ForegroundColor white  	'The first Variable is the Mailbox name for which we wish to give permission. '
write-host  -ForegroundColor white  	'The Second Variable is the User(or Distribution group) name'
write-host  -ForegroundColor white  	'That will get the permission for the Mailbox.'
write-host  -ForegroundColor white		--------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Add-MailboxPermission <alias> -User <alias> -AccessRights FullAccess -InheritanceType all '
write-host  -ForegroundColor Magenta	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host
write-host

# Section 2: user input	

write-host
write-host -ForegroundColor Yellow 'Type the Mailbox name. For example:  USER-A ( Manager Mailbox ) '
write-host
$MailBox = Read-Host "Type the name of the Mailbox "
write-host
write-host -ForegroundColor Yellow 'Type the user( or the Distribution Group) name '  
write-host -ForegroundColor Yellow 'that will have access to the Mailbox.'  
write-host -ForegroundColor Yellow 'For example:  USER-B ( Assistant )' 
write-host
$MailRecipient =  Read-Host "Type the name"

# Section 3: PowerShell Command


Add-MailboxPermission $MailBox -User $MailRecipient -AccessRights FullAccess -InheritanceType all

# 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 -ForegroundColor Yellow	"The following User/Distribution group:  "
	write-host -ForegroundColor White	$MailRecipient.ToUpper() 
	write-host -ForegroundColor Yellow	"Have FULL ACCESS Permissions on "	
    write-host -ForegroundColor white	$MailBox.ToUpper()
	write-host -ForegroundColor Yellow	"Mailbox" 
	write-host -------------------------------------------------------------
	
}

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


#Section 3: Display Information


write-host ---------------------------------------------------------
write-host List of User/Distribution Groups                        -ForegroundColor Yellow
write-host That have FULL ACCESS permissions for $MailBox MailBox -ForegroundColor Yellow
write-host ---------------------------------------------------------

Get-mailboxpermission $MailBox | where { ($_.IsInherited -eq $False	) -and -not ($_.User -like “NT AUTHORITY\SELF”) } |Select Identity, user, AccessRights | Out-String
write-host
write-host ---------------------------------------------------------


#Section 5: End the Command

write-host
write-host
Read-Host "Press Enter to continue..."
write-host
write-host



}



20{

####################################################################################################
# Assign SEND AS Permissions to specific User or Distribution Group 
######################################################################################################


# Section 1: information 


clear-host

write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
write-host  -ForegroundColor white		Instructions                                                                                          
write-host  -ForegroundColor white		--------------------------------------------------------------------                                                           
write-host  -ForegroundColor white  	'This option will:  '
write-host  -ForegroundColor white  	'Assign SEND AS Permissions to User(or Distribution Group)'
write-host  -ForegroundColor white  	'For a specific Mailbox. '
write-host  -ForegroundColor white  	'For example: Assign permission to assistant "(User B)" that needs permission to'   
write-host  -ForegroundColor white  	'Access the manager Mailbox "(User A)" .'
write-host  -ForegroundColor white  	'The first Variable is the Mailbox name for which we wish to give permission. '
write-host  -ForegroundColor white  	'The Second Variable is the User(or Distribution group) name'
write-host  -ForegroundColor white  	'That will get the permission for the Mailbox.'
write-host  -ForegroundColor white		--------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Add-RecipientPermission <alias> -Trustee <alias> -AccessRights SendAs -Confirm:$False	 '
write-host  -ForegroundColor Magenta	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host
write-host



# Section 2: user input	
	

write-host
write-host -ForegroundColor Yellow 'Type the Mailbox name. For example:  USER-A ( Manager Mailbox ) '
write-host
$MailBox = Read-Host "Type the name of the Mailbox "
write-host
write-host -ForegroundColor Yellow 'Type the user( or the Distribution Group) name '  
write-host -ForegroundColor Yellow 'that will have access to the Mailbox.'  
write-host -ForegroundColor Yellow 'For example:  USER-B ( Assistant )' 
write-host
$MailRecipient =  Read-Host "Type the name"


# Section 3: PowerShell Command

Add-RecipientPermission $MailBox -Trustee $MailRecipient -AccessRights SendAs -Confirm:$False	




# Section 4:  Indication 
write-host 
write-host

if ($lastexitcode -eq 1)
{
	
write-host "The command Failed :-(" -ForegroundColor red	
	
}
else

{
	
	
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow "The command complete successfully !"           
write-host -ForegroundColor Yellow "The following User/Distribution group: "    
write-host -ForegroundColor White  "$MailRecipient"                                
write-host -ForegroundColor Yellow "Have SEND AS Permissions on "                  
write-host -ForegroundColor White  "$MailBox Mailbox "                             	
write-host -------------------------------------------------------------
	
	
	
}

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


#Section 3: Display Information


write-host ---------------------------------------------------------
write-host List of User/Distribution Groups                        -ForegroundColor Yellow
write-host That have SEND AS permissions for $MailBox MailBox -ForegroundColor Yellow
write-host ---------------------------------------------------------

Get-RecipientPermission  $MailBox | where { ($_.IsInherited -eq $False	) -and -not ($_.Trustee -like “NT AUTHORITY\SELF”) } | Select Trustee, AccessControlType, AccessRights | Out-String

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




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


}




21{


####################################################################################################
#Assign FULL ACCESS + SEND AS Rights to specific User or Distribution Group
#####################################################################################################

# Section 1: information 


write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
write-host  -ForegroundColor white		Instructions                                                                                          
write-host  -ForegroundColor white		--------------------------------------------------------------------                                                           
write-host  -ForegroundColor white  	'This option will:  '
write-host  -ForegroundColor white  	'Assign FULL ACCESS + SEND AS Permissions to User(or Distribution Group)'
write-host  -ForegroundColor white  	'For a specific Mailbox. '
write-host  -ForegroundColor white  	'For example: Assign permission to assistant "(User B)" that needs permission to'   
write-host  -ForegroundColor white  	'Access the manager Mailbox "(User A)" .'
write-host  -ForegroundColor white  	'The first Variable is the Mailbox name for which we wish to give permission. '
write-host  -ForegroundColor white  	'The Second Variable is the User(or Distribution group) name'
write-host  -ForegroundColor white  	'That will get the permission for the Mailbox.'
write-host  -ForegroundColor Magenta	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host
write-host



# Section 2: user input	 
	

write-host
write-host -ForegroundColor Yellow 'Type the Mailbox name. For example:  USER-A ( Manager Mailbox ) '
write-host
$MailBox = Read-Host "Type the name of the Mailbox "
write-host
write-host -ForegroundColor Yellow 'Type the user( or the Distribution Group) name '  
write-host -ForegroundColor Yellow 'that will have access to the Mailbox.'  
write-host -ForegroundColor Yellow 'For example:  USER-B ( Assistant )' 
write-host
$MailRecipient =  Read-Host "Type the name"


# Section 3: PowerShell Command

Add-MailboxPermission $MailBox -User $MailRecipient -AccessRights FullAccess -InheritanceType all
Add-RecipientPermission $MailBox -Trustee $MailRecipient -AccessRights SendAs -Confirm:$False	


# Section 4:  Indication 


write-host 
write-host

if ($lastexitcode -eq 1)
{
	
write-host "The command Failed :-(" -ForegroundColor red	
	
}
else

{
	
	
	write-host -------------------------------------------------------------
	write-host -ForegroundColor Yellow "The command complete successfully !"  
    write-host	
	write-host -ForegroundColor Yellow "The following User/Distribution group: "    
    write-host -ForegroundColor White  "$MailRecipient"                                
    write-host -ForegroundColor Yellow "Have FULL ACCESS + SEND AS Permissions on "                  
    write-host -ForegroundColor White  "$MailBox Mailbox "                             	
	write-host -------------------------------------------------------------

	
}


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

#Section 3: Display Information


write-host ---------------------------------------------------------
write-host List of User/Distribution Groups                        -ForegroundColor Yellow
write-host That have FULL ACCESS permissions for $MailBox MailBox -ForegroundColor Yellow
write-host ---------------------------------------------------------

Get-mailboxpermission $MailBox | where { ($_.IsInherited -eq $False	) -and -not ($_.User -like “NT AUTHORITY\SELF”) } |Select Identity, user, AccessRights | Out-String
write-host
write-host ---------------------------------------------------------
write-host
write-host
write-host 
write-host ---------------------------------------------------------
write-host List of User/Distribution Groups                        -ForegroundColor Yellow
write-host That have SEND AS permissions for $MailBox MailBox -ForegroundColor Yellow
write-host ---------------------------------------------------------

Get-RecipientPermission  $MailBox | where { ($_.IsInherited -eq $False	) -and -not ($_.Trustee -like “NT AUTHORITY\SELF”) } | Select Trustee, AccessControlType, AccessRights | Out-String

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



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


}



#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Section G: Assign folder permissions
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



22{


####################################################################################################
#Assign Reviewer Folder Permissions to specific mailbox folder
#####################################################################################################

# Section 1: information 


write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
write-host  -ForegroundColor white		Instructions                                                                                          
write-host  -ForegroundColor white		--------------------------------------------------------------------                                                           
write-host  -ForegroundColor white  	'This option will:  '
write-host  -ForegroundColor white  	'Assign Reviewer Folder Permissions to specific mailbox folder'
write-host  -ForegroundColor white		--------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Add-MailboxFolderPermission  -Identity  <Mailbox>:\inbox\<Folder>  -user <Mailbox>  -AccessRights <Permission> '
write-host  -ForegroundColor Magenta	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host
write-host



# Section 2: user input	 
	
write-host -ForegroundColor Yellow	"You will need to provide 3 parameters:"  
write-host
write-host -ForegroundColor Yellow '1. The Folder name, of the folder that we want to share. '
write-host -ForegroundColor Yellow 'For example:  Folder-A '
write-host
$FOLDER = Read-Host "Type the folder name that you want to share "
write-host


write-host -ForegroundColor Yellow '2. Type the user name (Alias) of the user that want the share his folder.  '
write-host -ForegroundColor Yellow 'For example:  USER-A ( Manager Mailbox ) '
write-host
$MailBox = Read-Host "'Type the user name ( Alias) of the user that want the share his folder "
write-host


write-host -ForegroundColor Yellow '3. Type the user name (Alias) of the user that will get access to the shared folder '  
write-host -ForegroundColor Yellow 'For example:  USER-B ( Assistant )' 
write-host
$MailRecipient =  Read-Host "Type the user name (Alias) of the user that will get access to the shared folder "
	
	
	

$inbox = $MailBox+":\inbox"




# Section 3: PowerShell Command

Add-MailboxFolderPermission  $inbox\$FOLDER  -user $MailRecipient   -AccessRights Reviewer


# Section 4:  Indication 



#Section 3: Display Information



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


}








23{


####################################################################################################
#Assign Recursive Shared Folder Permissions
#####################################################################################################

# Section 1: information 


write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
write-host  -ForegroundColor white		Instructions                                                                                          
write-host  -ForegroundColor white		--------------------------------------------------------------------                                                           
write-host  -ForegroundColor white  	'This option will:  '
write-host  -ForegroundColor white  	'Assign Recursive Shared Folder Permissions'
write-host  -ForegroundColor Magenta	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host
write-host



# Section 2: user input	 
	
write-host -ForegroundColor Yellow	"You will need to provide 3 parameters:"  
write-host
write-host -ForegroundColor Yellow '1. The Folder name, of the folder that we want to share. '
write-host -ForegroundColor Yellow 'For example:  Folder-A '
write-host
$FOLDER = Read-Host "Type the folder name that you want to share "
write-host


write-host -ForegroundColor Yellow '2. Type the user name (Alias) of the user that want the share his folder.  '
write-host -ForegroundColor Yellow 'For example:  USER-A ( Manager Mailbox ) '
write-host
$MailBox = Read-Host "'Type the user name ( Alias) of the user that want the share his folder "
write-host


write-host -ForegroundColor Yellow '3. Type the user name (Alias) of the user that will get access to the shared folder '  
write-host -ForegroundColor Yellow 'For example:  USER-B ( Assistant )' 
write-host
$MailRecipient =  Read-Host "Type the user name (Alias) of the user that will get access to the shared folder "

$mmbox = $MailBox+":"


# Section 3: PowerShell Command

Get-MailboxFolderStatistics $MailBox | Where { $_.FolderPath.Contains($FOLDER) -eq $true }

ForEach($f in (Get-MailboxFolderStatistics $MailBox | Where { $_.FolderPath.Contains("/$FOLDER") -eq $True } ) ) 
{  $fname = "$mmbox" + $f.FolderPath.Replace("/","\");
 Add-MailboxFolderPermission $fname -User $MailRecipient -AccessRights Reviewer }


 
 
# Section 4:  Indication 



#Section 3: Display Information



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


}







#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#section H: Troubleshooting
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


24{


#####################################################################
#  Toggle calendar folder permissions
#####################################################################

# 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  	"Toggle calendar folder permissions "
write-host  -ForegroundColor white  	"Step 1: Remove Permissions to shared calendar"
write-host  -ForegroundColor white  	"Step 2: Re assign the publishing editor Permissions to shared calendar"
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Remove-MailboxFolderPermission  -Identity <user>  -User <user> '
write-host  -ForegroundColor Yellow  	'Add-MailboxFolderPermission –Identity <User>:\calendar  -AccessRight PublishingEditor -User $MailRecipient '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo    
write-host -ForegroundColor Yellow	"STEP1: Remove Permissions to shared calendar "  
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo    
write-host
write-host
write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the User which want to remove permission from his calendar ( The manager )"  
write-host -ForegroundColor Yellow	"Type the user name. For example: user1"
write-host
$MailBox = Read-Host "Type the User name User which want to remove permission from his calendar ( The manager ) "
write-host

# Section 3: PowerShell Command


$mbox = $MailBox+":\calendar"

write-host -ForegroundColor Yellow	"This is a list of permissions to $MailBox calendar"
write-host -ForegroundColor Yellow	"Use this list to locate the user name that you want to remove from the list "
write-host -ForegroundColor Yellow	"The list present the display name value of the users that have permission to the calendar "   
write-host
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox mailbox
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox | Out-String

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

write-host -ForegroundColor Yellow	"2) The Second parameter is the name of the User ( The assistant ) " 
write-host -ForegroundColor Yellow	"That his Permission to $MailBox calendar will be removed"   
write-host
$MailRecipient =  Read-Host "Type the User name his Permission to $MailBox calendar will be removed ( The assistant )"

write-host


Remove-MailboxFolderPermission  -Identity $mbox  -User $MailRecipient  	-Confirm:$False	

# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The permissions of: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White ;	write-host -ForegroundColor Yellow	"for " -nonewline
write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	"  Calendar" 
write-host -ForegroundColor Yellow	"Was removed "
write-host -------------------------------------------------------------
}

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

# Section 4: Display Information


write-host
write-host
write-host -ForegroundColor Yellow	"Use the permission list to verify that the permissions for $MailRecipient was removed"

write-host
write-host ------------------------------------------------------
write-host -ForegroundColor Yellow Calendar Permission for $MailBox mailbox
write-host -------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox |  Out-String

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


#STEP2 Add-MailboxFolderPermission

write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo    
write-host -ForegroundColor Yellow	"    STEP2: Re assign the publishing editor Permissions to shared calendar "  
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo    





Add-MailboxFolderPermission –Identity $mbox -AccessRight PublishingEditor -User $MailRecipient

# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
	write-host -------------------------------------------------------------
	write-host -ForegroundColor Yellow	"The command complete successfully !" 
	write-host
	write-host -ForegroundColor Yellow	"User named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White	 
	write-host -ForegroundColor Yellow	"Have "	-nonewline; write-host "Publishing Editor".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Permission for  "	
  	write-host -ForegroundColor white	"$MailBox".ToUpper() -nonewline; write-host -ForegroundColor Yellow	" Calendar folder" 
	write-host -------------------------------------------------------------
}

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

# Section 4: Display Information

write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display Calendar Permission for $MailBox.ToUpper() Calendar
write-host ---------------------------------------------------------------------------

Get-MailboxFolderPermission -identity $mbox |  Out-String









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

}












#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Section H: Export permissions information
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



25{

####################################################################################################
# Export folder permission for all of the recipients (Bulk mode)
######################################################################################################

# $a= Get-Date -format d ( current day) 
# $b = (get-date).AddDays(-1) ( one day before) 
# 

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



$htstyle = '<style>'
$htstyle = $htstyle + “body{font-family:segoe ui,arial;color:black; }” 
$htstyle = $htstyle + “H1{ color: white; background-color:#385623; font-weight:bold;width: 795px;margin-top:35px;margin-bottom:25px;font-size: 22px;padding:5px 15px 5px 10px; }” 
$htstyle = $htstyle + “table{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}” 
$htstyle = $htstyle + “th{border-width: 1px;padding: 5px;border-style: solid;border-color: #d1d3d4;background-color:#0072c6 ;color:white;}” 
$htstyle = $htstyle + “td{border-width: 1px;padding: 5px;border-style: solid;border-color: #d1d3d4;background-color:white}” 
$htstyle = $htstyle + “</style>” 


$date = Get-Date -format "dd.mm.yyyy hh-mm-ss"

write-host
# Section 2: user input

#----------------------------------------------------------
#######################
# Export content of the administrator audit log (look for specific user ) to file
#######################


###CSV####
Get-Mailbox | Get-MailboxFolderPermission |  Export-CSV C:\INFO\users-perm.csv –NoTypeInformation
#########

###HTML####
Get-Mailbox | Get-MailboxFolderPermission | select Identity,FolderName,User,AccessRights,IsValid,ObjectState |ConvertTo-Html -head $htstyle -Body  "<H1>older permission for all of the recipients</H1>"   | Out-File C:\INFO\users-perm.html
#########

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

}









26{

####################################################################################################
# Export Calendar information of 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  	'Export Calendar information of a specific mailbox  '
write-host  -ForegroundColor white		---------------------------------------------------------------------------- 
write-host  -ForegroundColor white  	'The export command will: '
write-host  -ForegroundColor white  	'1. Create a folder named: C:\INFO\3.USER info '
write-host  -ForegroundColor white  	'2. Save all of the information to diffrent file formats such as: TXT, CSV, HTML and XML '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host


# Section 2: user input

write-host
write-host
write-host -ForegroundColor Yellow	"1. Type the office 365 recipient Email Address"  
write-host -ForegroundColor Yellow	"[For example: John@contoso.com]"
write-host -ForegroundColor Yellow	"2. Press  The Enter Key"
write-host
$Email = Read-Host "Type the office 365 recipient Email Address "
write-host


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



#----------------------------------------------------------
# Exchange_Online_objects

$A50 =    "C:\INFO\3.USER info\$Email\Calendar information"
$A50A1 =  "C:\INFO\3.USER info\$Email\Calendar information\Reports\CSV"
$A50A2 =  "C:\INFO\3.USER info\$Email\Calendar information\Reports\HTML"
$A50A3 =  "C:\INFO\3.USER info\$Email\Calendar information\Reports\XML"



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



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



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



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



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




#----------------------------------------------------------
#####################################
# Exchange Online objects\information 
#####################################
#----------------------------------------------------------


#----------------------------------------------------------
#######################
# Get-mailbox
#######################

###TXT####
Get-Mailbox $Email |FL >$A50\"Get-mailbox-$Email.txt"
#########

###CSV####
Get-Mailbox $Email | Export-CSV $A50A1\"Get-mailbox-$Email.CSV" –NoTypeInformation -Encoding utf8
#########

###HTML####
Get-Mailbox $Email | select UserPrincipalName, DisplayName,Name,Identity, Alias,RecipientTypeDetails, EmailAddresses, PrimarySmtpAddress | ConvertTo-Html -head $htstyle -Body  "<H1>Get-Mailbox for  $Email Mailbox </H1>"   | Out-File $A50A2\"Get-Mailbox-$Email.html"
#########


###XML####
Get-Mailbox $Email | export-clixml $A50A3\"Get-mailbox-$Email.XML"
##########
#----------------------------------------------------------



#######################
#Get-CalendarProcessing
#######################

###TXT####
Get-Mailbox $Email | Get-CalendarProcessing | FL >$A50\"Get-CalendarProcessing-$Email.txt"
#########

###CSV####
Get-Mailbox $Email | Get-CalendarProcessing | Export-CSV $A50A1\"Get-CalendarProcessing-$Email.CSV" –NoTypeInformation -Encoding utf8
#########

###HTML####
Get-Mailbox $Email | Get-CalendarProcessing | ConvertTo-Html -head $htstyle -Body  "<H1>Get CalendarProcessing for $Email Mailbox </H1>"   | Out-File $A50A2\"Get-CalendarProcessing-$Email.html"
#########


###XML####
Get-Mailbox $Email | Get-CalendarProcessing|  export-clixml $A50A3\"Get-CalendarProcessing-$Email.XML"
##########
#----------------------------------------------------------




#######################
#Get-MailboxCalendarConfiguration
#######################

###TXT####
Get-MailboxCalendarConfiguration $Email  | FL >$A50\"Get-MailboxCalendarConfiguration-$Email.txt"
#########

###CSV####
Get-MailboxCalendarConfiguration $Email  | Export-CSV $A50A1\"Get-MailboxCalendarConfiguration-$Email.CSV" –NoTypeInformation -Encoding utf8
#########

###HTML####
Get-MailboxCalendarConfiguration $Email  | ConvertTo-Html -head $htstyle -Body  "<H1>Get Mailbox Calendar Configuration for $Email Mailbox </H1>"   | Out-File $A50A2\"Get-MailboxCalendarConfiguration-$Email.html"
#########


###XML####
Get-MailboxCalendarConfiguration $Email  |  export-clixml $A50A3\"Get-MailboxCalendarConfiguration-$Email.XML"
##########
#----------------------------------------------------------




#######################
#Get-CalendarNotification
#######################

###TXT####
Get-CalendarNotification $Email | FL >$A50\"Get-CalendarNotification-$Email.txt"
#########

###CSV####
Get-CalendarNotification $Email | FL| Export-CSV $A50A1\"Get-CalendarNotification-$Email.CSV" –NoTypeInformation -Encoding utf8
#########

###HTML####
Get-CalendarNotification $Email | FL | ConvertTo-Html -head $htstyle -Body  "<H1>Get Mailbox Calendar Notification for $Email Mailbox </H1>"   | Out-File $A50A2\"Get-CalendarNotification-$Email.html"
#########


###XML####
Get-CalendarNotification $Email | FL |  export-clixml $A50A3\"Get-CalendarNotification-$Email.XML"
##########
#----------------------------------------------------------







#----------------------------------------------------------
#######################
# Mailbox Folder Statistics
#######################

###TXT####
Get-MailboxFolderStatistics -Identity $Email |fl  >$A50\"Mailbox_Folder_Statistics-$Email.txt"
#########

######################### CSV ############################################
Get-MailboxFolderStatistics -Identity $Email| Export-CSV $A50A1\"Mailbox_Folder_Statistics-$Email.CSV" –NoTypeInformation -Encoding utf8

##Filterd CSV
Get-MailboxFolderStatistics -Identity $Email| select Name, FolderPath,FolderType,ItemsInFolder,DeletedItemsInFolder,FolderSize,DeletedItemsInFolderAndSubfolders,FolderAndSubfolderSize,Identity | Export-CSV $A50A1\"Mailbox_Folder_Statistics-$Email filterd.CSV" –NoTypeInformation -Encoding utf8

#####################################################################

######################### HTML ############################################
Get-MailboxFolderStatistics -Identity $Email | ConvertTo-Html -head $htstyle -Body  "<H1> Mailbox Folder Statistics  for  $Email Mailbox </H1>"   | Out-File $A50A2\"Mailbox_Folder_Statistics-$Email.html"

##Filterd HTML
Get-MailboxFolderStatistics -Identity $Email | select   Name,FolderSize,ItemsinFolder | ConvertTo-Html -head $htstyle -Body  "<H1> Mailbox Folder Statistics  for  $Email Mailbox </H1>"   | Out-File $A50A2\"Mailbox_Folder_Statistics-$Email Summary-02.html"
#####################################################################


##Filterd HTML
Get-MailboxFolderStatistics -Identity $Email | select Name, FolderPath,FolderType,ItemsInFolder,DeletedItemsInFolder,FolderSize,DeletedItemsInFolderAndSubfolders,FolderAndSubfolderSize,Identity | ConvertTo-Html -head $htstyle -Body  "<H1> Mailbox Folder Statistics  for  $Email Mailbox </H1>"   | Out-File $A50A2\"Mailbox_Folder_Statistics-$Email Summary-01.html"
#####################################################################


###XML####
Get-MailboxFolderStatistics -Identity $Email | export-clixml $A50A3\"Mailbox_Folder_Statistics-$Email.xml"
##########

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


#----------------------------------------------------------
#######################
#Mailbox Statistics
#######################

###TXT####
Get-MailboxStatistics -Identity $Email  |fl  >$A50\"Mailbox-Statistics-$Email.txt"
#########

###CSV####
Get-MailboxStatistics -Identity $Email | Export-CSV $A50A1\"Mailbox-Statistics-$Email.CSV" –NoTypeInformation -Encoding utf8
#########

###HTML####
Get-MailboxStatistics -Identity $Email | Format-List StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount | ConvertTo-Html -head $htstyle -Body  "<H1>Get-Mailbox Statistics for $Email Mailbox </H1>"   | Out-File $A50A2\"Mailbox-Statistics-$Email.html"
#########

###XML####
Get-MailboxStatistics -Identity $Email | export-clixml $A50A3\"Mailbox-Statistics-$Email.XML"
##########
#----------------------------------------------------------

#######################
# Get-USER
#######################

###TXT####
Get-user $Email |FL >$A50\"Get-user-$Email.txt"
#########

###CSV####
Get-user $Email | Export-CSV $A50A1\"Get-user-$Email.CSV" –NoTypeInformation
#########

###HTML####
Get-user $Email | select  UserPrincipalName, DisplayName,Name,Identity, Alias,RecipientTypeDetails | ConvertTo-Html -head $htstyle -Body  "<H1>Information about $Alias user(GET-USER)</H1>"   | Out-File $A50A2\"Get-user-$Email.html"
#########

###XML####
Get-user $Email | export-clixml $A50A3\"Get-user-$Email.XML"
##########

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




}



















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


 
#+++++++++++++++++++
#  Finish  
##++++++++++++++++++
 
 
30{

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


Get-PSsession | Remove-PSsession

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



#———— Indication ———————
write-host 
if ($lastexitcode -eq 1)
{
	
	
	write-host "The command Failed :-(" -ForegroundColor red
	
	
}
else

{
	write-host "The command complete successfully !" -ForegroundColor Yellow
	write-host "The remote PowerShell session to Exchange Online was disconnected" -ForegroundColor Yellow
	
}

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



}
31{

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


$Loop = $true
Exit
}

}


}




		
		