

#------------------------------------------------------------------------------
# THIS CODE AND ANY ASSOCIATED INFORMATION ARE PROVIDED “AS IS” WITHOUT
# WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
# FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE, INABILITY TO USE, OR 
# RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#
# AUTHOR(s):
#       Eyal Doron (o365info.com)
#------------------------------------------------------------------------------
# Hope that you enjoy it ! 
# And May the force of PowerShell will be with you   :-)
# 01-05-2014    
# Version WP- 001 
#------------------------------------------------------------------------------


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

}

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

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


$FormatEnumerationLimit = -1


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

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

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

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

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

"@

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



$Loop = $True
While ($Loop)
{
    write-host 
    write-host ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    write-host    "Manage Mailbox Audit using PowerShell  | PowerShell Script menu"  
    write-host ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    write-host
    write-host -ForegroundColor green  'Connect PowerShell session to AD Azure and Exchange Online' 
    write-host -ForegroundColor green  '--------------------------------------------------------------' 
    write-host -ForegroundColor Yellow ' 0)   Login in using your Office 365 Administrator credentials' 
    write-host
    write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' A: Enable/Disable Non-Owner-Mailbox-Access Report (Audit logging) ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 1)   Enable Non-Owner-Mailbox-Access Report (Audit logging)for User mailbox - Default options'
	write-host                                              ' 2)   Enable Non-Owner-Mailbox-Access Report (Audit logging)for User mailbox - ALL of the available options'
	write-host                                              ' 3)   Enable Non-Owner-Mailbox-Access Report (Audit logging) for ALL users mailboxes in your organization (bulk)'
	write-host                                              ' 4)   Disable Non-Owner-Mailbox-Access Report (Audit logging) for User mailbox'
	write-host                                              ' 5)   Disable Non-Owner-Mailbox-Access Report (Audit logging) for ALL user mailboxes in your organization (bulk)'
	write-host                                              ' 6)   Enable Non-Owner-Mailbox-Access Report (Audit logging)for User mailbox – AuditAdmin'
	write-host                                              ' 7)   Enable Non-Owner-Mailbox-Access Report (Audit logging)for User mailbox – AuditDelegate '
	write-host 
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' B: Display information about Audit settings  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 8)   Display information about Audit settings- AuditDelegate + AuditAdmin for a specific mailbox'
	write-host                                              ' 9)   Display all of the information about mailbox Audit settings for: a specific mailbox'
	write-host                                              ' 10)  Display a list of all of the mailboxes that are audited'
	write-host                                              ' 11)  Display information about recipient audit folder'
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue 'C: Display information about mailbox and folder permissions  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 12)   Display FULL ACCESS + SEND AS + SEND ON BEHALF + Calendar Permissions for Mailbox'
	write-host                                              ' 13)   Display information about folder permissions'
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' D: Search for information in the Audit Log  ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host                                              ' 14)   Search for information in the Audit log of a specific mailbox (All audit log)'
	write-host                                              ' 15)   Search for information in the Audit log of a specific mailbox - “Send As” activities'
	write-host                                              ' 16)   Search for information in the Audit log of a specific mailbox - choose the activity'
	write-host                                              ' 17)   Search for information in the Audit log of a specific mailbox from specific date range'
	write-host                                              ' 18)   Search for information in the Audit log of a specific mailbox from specific date range choose the activity'
	write-host  
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' E: Audit General Settings   ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 19)   Configure Outlook Web App to allow XML attachments'
	write-host                                              ' 20)   Set Audit retention number of days'
	write-host                                              ' 21)   Suppressing Audits for Specific Mailboxes'
	write-host  
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor white  -BackgroundColor Blue ' F: Export Audit information to file   ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host
    write-host                                              ' 22)   Export ALL Audit information about a Mailbox to file'
	write-host                                              ' 23)   Export Audit information of Mailbox About specific operations to files'
	write-host                                              ' 24)   Export content of the administrator audit log (show all events) to file'
	write-host                                              ' 25)   Export content of the administrator audit log (look for specific user ) to file'
	write-host                                              ' 26)   Ask for a report about - Audit information ( XML report File taht will Send the result to Email address)'
	write-host                                              ' 27)   Export information about Mailbox and folder permissions to file'
	write-host         
	write-host -ForegroundColor green  '---------------------------' 
    write-host -ForegroundColor Blue  -BackgroundColor Yello ' Exit\Disconnect ' 
    write-host -ForegroundColor green  '---------------------------' 
    write-host
    write-host  -ForegroundColor Yellow                       ' 28) Disconnect PowerShell session'
	write-host 
	write-host  -ForegroundColor Yellow                       ' 29)  Exit'
	write-host 
	write-host                                          

	

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


{


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


		0
        {

            # Specify your administrative user credentials on the line below 

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

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

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

            

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

            $msoExchangeURL = “https://ps.outlook.com/powershell/”
			$connected = $false
			$i = 0
			while ( -not ($connected)) {
				$i++
				if($i -eq 4){
					
										
					Write-host
					Write-host -ForegroundColor White	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
					Write-host -ForegroundColor Red    "Too many incorrect login attempts. Good bye."	
					Write-host
					Write-host -ForegroundColor White	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
					
					
					exit
				}
				$cred = Get-Credential -Credential $user
				try 
				{
					$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $msoExchangeURL -Credential $cred -Authentication Basic -AllowRedirection  -ErrorAction stop
					Connect-MsolService -Credential $cred -ErrorAction stop
					Import-PSSession $session 
					$connected = $True 
				}
				catch 
				{
					Write-host
					Write-host -ForegroundColor Yellow	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
					Write-host -ForegroundColor Red    "There is something wrong with the global administrator credentials"	
					Write-host
					Write-host -ForegroundColor Yellow	ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
					Write-host
				}
			}
            
			$host.ui.RawUI.WindowTitle = ("Windows Azure Active Directory |Connected to Office 365 using: " + $Cred.UserName.ToString()  ) 
        }



		


#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#A: Enable/Disable Non-Owner-Mailbox-Access Report (Audit logging) 
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




1{


#####################################################################
#   Enable Non-Owner-Mailbox-Access Report (Audit logging)for User mailbox
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Enable Mailbox Audit (Non-Owner-Mailbox-Access Report) for a specific mailbox using the Default Audit options.  '
write-host  -ForegroundColor white  	'(Non-Owner-Mailbox-Access = Delegate access and Administrator access to mailbox )  '
write-host  -ForegroundColor white  	'When enabling to audit option, the following options are activated:   '
write-host  -ForegroundColor white  	'AuditAdmin + AuditDelegate   '
write-host  -ForegroundColor white  	'The audit information will be saved by default for 90 days  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <Mailbox> -AuditEnabled $True '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host
					# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host


# Section 3: PowerShell Command


Set-Mailbox $Alias -AuditEnabled $True



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

Get-Mailbox $Alias | FL UserPrincipalName, AuditEnabled,AuditLogAgeLimit, AuditAdmin,AuditDelegate,AuditOwner | Out-String

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


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

}




2{


################################################################################################
# Enable Non-Owner-Mailbox-Access Report (Audit logging)for User mailbox - all of the available options
################################################################################################

# 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  	'Enable Non-Owner-Mailbox-Access Report (Audit logging)for User mailbox - all of the available options  '
write-host  -ForegroundColor white  	'When enabling to audit option, the following options are activated:   '
write-host  -ForegroundColor white  	'AuditAdmin + AuditDelegate   '
write-host  -ForegroundColor white  	'When using the default audit not all the option are selected.    '
write-host  -ForegroundColor white  	'The following operations are not audited by default if auditing is enabled for a mailbox    '
write-host  -ForegroundColor white  	'Copy (Delegate and Administrator) , MessageBind (Administrator), Move (Delegate), MoveToDeletedItems (Delegate), SendOnBehalf (Delegate)  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-mailbox <Mailbox> -AuditEnabled $True -AuditDelegate <list of operations> -AuditAdmin <list of operations>  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host
					# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host


# Section 3: PowerShell Command


Set-mailbox $Alias -AuditEnabled $True -AuditDelegate Create,FolderBind,SendAs,SendOnBehalf,SoftDelete,HardDelete,Update,Move,MoveToDeletedItems -AuditAdmin Create,FolderBind,SendAs,SendOnBehalf,SoftDelete,HardDelete,Update,Move,MoveToDeletedItems 



write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display Audit information about: "$Alias".ToUpper() Mailbox - AuditDelegate settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias| Select-Object –ExpandProperty AuditDelegate   | Out-String

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


write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display Audit information about: "$Alias".ToUpper() Mailbox - MailboxAuditAdmin settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias| Select-Object –ExpandProperty AuditAdmin   | Out-String

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


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

}






3{


##################################################################################################
#  Enable Mailbox Audit (Non-Owner-Mailbox-Access Report) for ALL mailboxes (Bulk mode)
##################################################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Enable Mailbox Audit (Non-Owner-Mailbox-Access Report) for ALL mailboxs (Bulk mode)  '

write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} '
write-host  -ForegroundColor Yellow  	'$UserMailboxes | ForEach {Set-Mailbox $_.Identity -AuditEnabled $True} '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

# Section 2: user input


$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
$UserMailboxes | ForEach {Set-Mailbox $_.Identity -AuditEnabled $True}



# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display Audit settings information for all Mailboxes  
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox | FL UserPrincipalName, AuditEnabled ,AuditLogAgeLimit, AuditAdmin,AuditDelegate, AuditOwner | Out-String

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


# Section 4: export info



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

}



4{


################################################################################################
#   Disable Mailbox Audit (Non-Owner-Mailbox-Access Report) for a specific mailbox 
################################################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Disable Mailbox Audit (Non-Owner-Mailbox-Access Report) for a specific mailbox   '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <Mailbox> -AuditEnabled $False '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

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


# Section 3: PowerShell Command


Set-Mailbox $Alias -AuditEnabled $False



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

Get-Mailbox $Alias | FL UserPrincipalName, AuditEnabled ,AuditLogAgeLimit, AuditAdmin,AuditDelegate, AuditOwner | Out-String

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


# Section 4: export info



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

}




5{


##################################################################################################
#  Disable Mailbox Audit (Non-Owner-Mailbox-Access Report) for ALL mailboxs (Bulk mode)
##################################################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Disable Mailbox Audit (Non-Owner-Mailbox-Access Report) for ALL mailboxs (Bulk mode) '

write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} '
write-host  -ForegroundColor Yellow  	'$UserMailboxes | ForEach {Set-Mailbox $_.Identity -AuditEnabled $False} '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

# Section 2: user input


$UserMailboxes = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
$UserMailboxes | ForEach {Set-Mailbox $_.Identity -AuditEnabled $False}



# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display Audit settings  information for all Mailboxes  
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox | FL UserPrincipalName, AuditEnabled ,AuditLogAgeLimit, AuditAdmin,AuditDelegate, AuditOwner | Out-String

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


# Section 4: export info



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

}






#+++++++++++++++++++++++++++++++++++++++++++++++++
# B: Set the Type of Mailbox Audit + Non default Audit operations
#+++++++++++++++++++++++++++++++++++++++++++++++++




6{


################################################################################################
#  Set Mailbox Audit – AuditAdmin 
################################################################################################

# 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 Mailbox Audit – Only for AuditAdmin ( administrator access) for all of the available options   '
write-host  -ForegroundColor white  	'The additional actions are:  Copy (Administrator) , MessageBind (Administrator) '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <Mailbox> –AuditAdmin <list of operations>  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

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

# Section 3: PowerShell Command

Set-Mailbox $Alias -AuditAdmin Create,FolderBind,SendAs,SendOnBehalf,SoftDelete,HardDelete,Update,Move,MoveToDeletedItems 

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display Audit information about: "$Alias".ToUpper() Mailbox - MailboxAuditAdmin settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias| Select-Object –ExpandProperty AuditAdmin   | Out-String

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


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

}



7{


################################################################################################
#   Set Mailbox Audit – AuditAdmin 
################################################################################################

# 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 Mailbox Audit – Only for AuditDelegate ( Delegate  access) for all of the available options   '
write-host  -ForegroundColor white  	'The additional actions are:  Copy (Delegate ) , Move (Delegate), MoveToDeletedItems (Delegate), SendOnBehalf (Delegate) '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <Mailbox> –AuditDelegate  <list of operations>  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

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


# Section 3: PowerShell Command


Set-Mailbox $Alias –AuditDelegate  Create,FolderBind,SendAs,SendOnBehalf,SoftDelete,HardDelete,Update,Move,MoveToDeletedItems 



write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display Audit information about: "$Alias".ToUpper() Mailbox - AuditDelegate settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias| Select-Object –ExpandProperty AuditDelegate   | Out-String

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


# Section 4: export info



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

}



#+++++++++++++++++++++++++++++++++++++++++++++++++
#B: Display information about Audit settings 
#+++++++++++++++++++++++++++++++++++++++++++++++++


8{

################################################################################################
#   Display information about Audit logging for a specific mailbox - AuditDelegate 
################################################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display information about AuditDelegate + AuditAdmin Audit logging for a specific mailbox - AuditDelegate    '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox <Mailbox> | Select-Object –ExpandProperty AuditDelegate   '
write-host  -ForegroundColor Yellow  	'Get-Mailbox <Mailbox> | Select-Object –ExpandProperty AuditAdmin   '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host
					# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host


# Section 3: PowerShell Command
write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display Audit information about: "$Alias".ToUpper() Mailbox - AuditDelegate settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias| Select-Object –ExpandProperty AuditDelegate   | Out-String

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


write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display Audit information about: "$Alias".ToUpper() Mailbox - MailboxAuditAdmin settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias| Select-Object –ExpandProperty AuditAdmin   | Out-String

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


# Section 4: export info

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

}


9{

################################################################################################
# Display information about mailbox Audit settings   
################################################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display information about mailbox Audit settings      '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
# write-host  -ForegroundColor Yellow  	'Get-Mailbox <Mailbox> | FL *audit*    '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host
					# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host
# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about: "$Alias".ToUpper() Audit settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host
#$FormatEnumerationLimit = -1
# Get-Mailbox <Mailbox> | Select-Object –ExpandProperty AuditDelegate
Get-Mailbox $Alias | FL AuditEnabled,AuditLogAgeLimit,AuditAdmin,AuditDelegate, AuditOwner   | Out-String

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

Get-Mailbox $Alias| Select-Object –ExpandProperty AuditDelegate   | Out-String

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

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about: "$Alias".ToUpper() MailboxAuditAdmin  settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias| Select-Object –ExpandProperty AuditAdmin   | Out-String

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

# Section 4: export info

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

}






10{

################################################################################################
# Display list of all of the mailboxes that are audited 
################################################################################################

# 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 list of all of the mailboxes that are audited      '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox| Where {$_.AuditEnabled –eq “$True”}   '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host


# Section 3: PowerShell Command
write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display list of all of the mailboxes that are audited 
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox| Where {$_.AuditEnabled –eq “$True”}  | FL DisplayName  |  Out-String

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


# Section 4: export info



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

}







11{

####################################################################################################
#Display information about recipient audit folder 
######################################################################################################

# 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  	'Display information about recipient audit folder  ' 	
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-MailboxFolderStatistics <mailbox> |  ? {$_.Name -eq "Audits" -and $_.FolderType -eq "Audits"} | FT   '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host

					# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host
#Section 3: Display Information


write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about: $Alias.ToUpper() Mailbox Audit folder
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-MailboxFolderStatistics $Alias |  ? {$_.Name -eq "Audits" -and $_.FolderType -eq "Audits"} |    Format-Table Identity, ItemsInFolder, FolderSize -AutoSize | 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


}




#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# C: Display information about mailbox and folder permissions
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



12{

####################################################################################################
#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  $mbox | Select Identity,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


}




13{

################################################################################################
# Display information about 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  	'Display information about folder permissions     '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'get-mailboxfolder <mailbox> -GetChildren | Get-MailboxFolderPermission | Where-Object {-not ($_.AccessRights -like '*None*')}     '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

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

# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about: "$Alias".ToUpper() folder permissions  
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

get-mailboxfolder $Alias -GetChildren | Get-MailboxFolderPermission | Where-Object {-not ($_.AccessRights -like '*None*')}  | Out-String

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


# Section 4: export info

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

}




#+++++++++++++++++++++++++++++++++++++++++++++++++
#D: Search for information in the Audit Log  
#+++++++++++++++++++++++++++++++++++++++++++++++++


14{

################################################################################################
# Display all the Audit information that was collected for a specific mailbox
################################################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Display all the Audit information that was collected for a specific mailbox      '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Search-MailboxAuditLog  <Mailbox> -LogonTypes Admin,Delegate -ShowDetails     '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

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

# Section 3: PowerShell Command

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

Search-MailboxAuditLog  $Alias -LogonTypes Admin,Delegate -ShowDetails    | Out-String

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


# Section 4: export info

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

}



15{

################################################################################################
# Display Audit information for “Send As” activities 
################################################################################################

# 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 all the Audit information that was collected for a specific mailbox      '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Search-MailboxAuditLog -Identity John -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Sendas"} |select <oprations>     '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

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

# Section 3: PowerShell Command

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

Search-MailboxAuditLog $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Sendas"} |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,MailboxOwnerUPN,LogonUserDisplayName,ItemSubject,ClientInfoString    | Out-String

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


# Section 4: export info

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

}




16{

################################################################################################
# Display Audit information for selected activities 
################################################################################################

# 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 all the Audit information that was collected for a specific mailbox for selected activities      '
write-host  -ForegroundColor white  	'You can choose one of the following options:     '
write-host  -ForegroundColor white  	'Update, move, MoveToDeletedItems, SoftDelete, HardDelete, SendAs, SendOnBehalf, Create, FolderBind     '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Search-MailboxAuditLog <mailbox> -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq <oprations>} |select <Data field>     '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

					# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host
					write-host -ForegroundColor Yellow	"2. Required operation "  
					write-host
					write-host -ForegroundColor Yellow	"Choose the required operation such as: "  
					write-host -ForegroundColor Yellow	"Update, move, MoveToDeletedItems, SoftDelete, HardDelete, SendAs, SendOnBehalf, Create, FolderBind"
					write-host
					$operation = Read-Host "Choose the required operation "
					write-host


# Section 3: PowerShell Command

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

Search-MailboxAuditLog $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "$operation"} |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,MailboxOwnerUPN,LogonUserDisplayName,ItemSubject,ClientInfoString    | Out-String

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


# Section 4: export info

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

}



17{

################################################################################################
# Display Audit information about a mailbox from specific date range 
################################################################################################

# 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 Audit information about a mailbox from specific date range     '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Search-MailboxAuditLog  <Mailbox> -LogonTypes Admin,Delegate –StartDate <mm/dd/yyyy> –EndDate <mm/dd/yyyy> –ResultSize <Number>      '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

					# Section 2: user input

				
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 3 parameters:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host
					write-host -ForegroundColor Yellow	"2. Start date "  
					write-host -ForegroundColor Yellow	"Type the End date in mm/dd/yyyy format"  
					write-host -ForegroundColor Yellow	"For example: 05/22/2013"
					write-host
					$StartDate = Read-Host "Type the start date in mm/dd/yyyy format "
					write-host
					write-host -ForegroundColor Yellow	"3. End date "  
					write-host -ForegroundColor Yellow	"Type the End date in mm/dd/yyyy format"  
					write-host -ForegroundColor Yellow	"For example: 05/25/2013"
					write-host
					$EndDate = Read-Host "Type the End date in mm/dd/yyyy format "
					write-host




# Section 3: PowerShell Command

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

#$a= Get-Date 
#$b = (get-date).AddDays(-10) 

#Search-MailboxAuditLog john -LogonTypes Admin,Delegate –StartDate $b –EndDate $a –ResultSize 400


Search-MailboxAuditLog $Alias -LogonTypes Admin,Delegate –StartDate $StartDate –EndDate $EndDate –ResultSize 2000    | Out-String

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


# Section 4: export info

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

}




18{

################################################################################################
# Display Audit information about a mailbox from specific date range choose the activities 
################################################################################################

# 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 Audit information about a mailbox from specific date range and the activities will be selected by the user     '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Search-MailboxAuditLog <Mailbox> -LogonTypes Admin,Delegate -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yy> -ResultSize 2000  | Where-Object {$_.Operation -eq "HardDelete"}      '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host



					# Section 2: user input

				
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 4 parameters:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host
					write-host -ForegroundColor Yellow	"2. Start date "  
					write-host -ForegroundColor Yellow	"Type the End date in mm/dd/yyyy format"  
					write-host -ForegroundColor Yellow	"For example: 05/22/2013"
					write-host
					$StartDate = Read-Host "Type the start date in mm/dd/yyyy format "
					write-host
					write-host -ForegroundColor Yellow	"3. End date "  
					write-host -ForegroundColor Yellow	"Type the End date in mm/dd/yyyy format"  
					write-host -ForegroundColor Yellow	"For example: 05/25/2013"
					write-host
					$EndDate = Read-Host "Type the End date in mm/dd/yyyy format "
					write-host
					write-host -ForegroundColor Yellow	"4. Required operation "  
					write-host -ForegroundColor Yellow	"Choose the required operation such as: "  
					write-host -ForegroundColor Yellow	"Update, move, MoveToDeletedItems, SoftDelete, HardDelete, SendAs, SendOnBehalf, Create, FolderBind"
					write-host
					$operation = Read-Host "Choose the required operation "
					write-host







# Section 3: PowerShell Command

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display Audit information about: "$Alias".ToUpper() Mailbox about "$operation".ToUpper() operation date range $StartDate to $EndDate
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Search-MailboxAuditLog $Alias -LogonTypes Admin,Delegate -StartDate $StartDate -EndDate $EndDate -ResultSize 2000  | Where-Object {$_.Operation -eq "$operation"}     | Out-String

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


# Section 4: export info

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

}




#+++++++++++++++++++++++++++++++++++++++++++++++++
#E: Audit General Settings 
#+++++++++++++++++++++++++++++++++++++++++++++++++


19{


#####################################################################
#   configure Outlook Web App to allow XML attachments
#####################################################################

# 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  	'configure Outlook Web App to allow XML attachments  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-OwaMailboxPolicy -Identity OwaMailboxPolicy-Default -AllowedFileTypes ".Suffix1",".Suffix2"      '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

# Section 3: PowerShell Command


Set-OwaMailboxPolicy -Identity OwaMailboxPolicy-Default -AllowedFileTypes '.rpmsg','.xlsx','.xlsm','.xlsb','.tiff','.pptx','.pptm','.ppsx','.ppsm','.docx','.docm','.zip','.xls','.wmv','.wma','.wav','.vsd','.txt','.tif','.rtf','.pub','.ppt','.png','.pdf','.one','.mp3','.jpg','.gif','.doc','.bmp','.avi','.xml'
# Section 4: export info


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

}




20{


#####################################################################
#   Set Audit retention number of days
#####################################################################

# 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 Audit retention number of days  '
write-host  -ForegroundColor white  	'The default retention policy for audit items is 90 days   '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <Mailbox> –AuditLogAgeLimit <Days>      '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host

					# Section 2: user input

				
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about: "$Alias".ToUpper() Audit settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias | FL AuditEnabled,AuditLogAgeLimit    | Out-String

write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host
write-host -ForegroundColor Yellow	"Type the number of dyas"  
write-host -ForegroundColor Yellow	"For example: 10"
write-host
$days = Read-Host "Type the number of dyas "
write-host


# Section 3: PowerShell Command


Set-Mailbox $Alias –AuditLogAgeLimit $days

# Section 4: export info


write-host
write-host
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	Display information about: "$Alias".ToUpper() Audit settings
write-host  -ForegroundColor white		----------------------------------------------------------------------------
write-host
write-host

Get-Mailbox $Alias | FL AuditEnabled,AuditLogAgeLimit    | 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

}



21{


#####################################################################
#   Suppressing Audits for Specific Mailboxes
#####################################################################

# 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  	'Suppressing Audits for Specific Mailboxes  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-MailboxAuditBypassAssociation <Mailbox> -AuditBypassEnabled $True      '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

# Section 2: user input

				
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host

# Section 3: PowerShell Command


Set-MailboxAuditBypassAssociation $Alias -AuditBypassEnabled $True

# Section 4: export info


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

}






#+++++++++++++++++++++++++++++++++++++++++++++++++
#F: Export Audit information to file
#+++++++++++++++++++++++++++++++++++++++++++++++++


22{

####################################################################################################
# Export ALL Audit information about a Mailbox to file
######################################################################################################

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

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


if (!(Test-Path -path C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access))
{
New-Item C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access -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

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


#----------------------------------------------------------
#######################
#Export ALL Audit information of Mailbox to file
#######################

###TXT####
$FormatEnumerationLimit = -1
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails  >C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\All-Audit-INFO-for-$Alias.txt
#########

###CSV####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Export-CSV C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\All-Audit-INFO-for-$Alias.csv –NoTypeInformation
#########

###HTML####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,LogonUserDisplayName,LogonType ,ItemSubject,FolderPathName,InternalLogonType,SourceItemSubjectsList,SourceItemFolderPathNamesList,ClientProcessName,ClientInfoString | ConvertTo-Html -head $htstyle -Body  "<H1>Display Audit information about SendAs activities for $Alias Mailbox</H1>"   | Out-File C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\All-Audit-INFO-for-$Alias.html
#########

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

}



23{

####################################################################################################
# Export Audit information of Mailbox to file
######################################################################################################

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

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


if (!(Test-Path -path C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access))
{
New-Item C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access -type directory
}



if (!(Test-Path -path C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\HTML))
{
New-Item C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\HTML -type directory
}


if (!(Test-Path -path C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\CSV))
{
New-Item C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\CSV -type directory
}


if (!(Test-Path -path C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\TXT))
{
New-Item C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\TXT -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

				
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host


#----------------------------------------------------------
#######################
# Display Audit information about “SendAs” activities
#######################

###TXT####
$FormatEnumerationLimit = -1
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Sendas"}  |FL >C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\TXT\SENDAS-$Alias.txt
#########

###CSV####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Sendas"} | Export-CSV C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\CSV\SENDAS-$Alias-csv.csv –NoTypeInformation
#########

###HTML####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Sendas"} |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,LogonUserDisplayName,LogonType ,ItemSubject,FolderPathName,InternalLogonType,SourceItemSubjectsList,SourceItemFolderPathNamesList,ClientProcessName,ClientInfoString| ConvertTo-Html -head $htstyle -Body  "<H1>Display Audit information about SendAs activities for $Alias Mailbox</H1>"   | Out-File C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\HTML\SENDAS-$Alias-HTML.html

#########

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




#----------------------------------------------------------
#######################
# Display Audit information about “Create” activities
#######################

###TXT####
$FormatEnumerationLimit = -1
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "create"}  |FL >C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\TXT\CREATE-$Alias.txt
#########

###CSV####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "create"} | Export-CSV C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\CSV\CREATE-$Alias-csv.csv –NoTypeInformation
#########

###HTML####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "create"} |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,LogonUserDisplayName,LogonType ,ItemSubject,FolderPathName,InternalLogonType,SourceItemSubjectsList,SourceItemFolderPathNamesList,ClientProcessName,ClientInfoString| ConvertTo-Html -head $htstyle -Body  "<H1>Display Audit information about CREATE activities for $Alias Mailbox</H1>"   | Out-File C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\HTML\CREATE-$Alias-HTML.html

#########

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



#----------------------------------------------------------
#######################
# Display Audit information about SoftDelete activities
#######################

###TXT####
$FormatEnumerationLimit = -1
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "SoftDelete"}  |FL >C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\TXT\SoftDelete-$Alias.txt
#########

###CSV####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "SoftDelete"} | Export-CSV C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\CSV\SoftDelete-$Alias-csv.csv –NoTypeInformation
#########

###HTML####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "SoftDelete"} |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,LogonUserDisplayName,LogonType ,ItemSubject,FolderPathName,InternalLogonType,SourceItemSubjectsList,SourceItemFolderPathNamesList,ClientProcessName,ClientInfoString | ConvertTo-Html -head $htstyle -Body  "<H1>Display Audit information about SOFT-DELETE activities for $Alias Mailbox</H1>"   | Out-File C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\HTML\SoftDelete-$Alias-HTML.html
#########
#----------------------------------------------------------

#----------------------------------------------------------
#######################
# Display Audit information about “HardDelete” activities
#######################

###TXT####
$FormatEnumerationLimit = -1
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "HardDelete"} |FL >C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\TXT\HardDelete-$Alias.txt
#########

###CSV####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "HardDelete"} | Export-CSV C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\CSV\HardDelete-$Alias-csv.csv –NoTypeInformation
#########

###HTML####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "HardDelete"} |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,LogonUserDisplayName,LogonType ,ItemSubject,FolderPathName,InternalLogonType,SourceItemSubjectsList,SourceItemFolderPathNamesList,ClientProcessName,ClientInfoString | ConvertTo-Html -head $htstyle -Body  "<H1>Display Audit information about HARD DELETE activities for $Alias Mailbox</H1>"   | Out-File C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\HTML\HardDelete-$Alias-HTML.html
#########

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

#----------------------------------------------------------
#######################
# Display Audit information about “Update” activities
#######################

###TXT####
$FormatEnumerationLimit = -1
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Update"}  |FL >C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\TXT\Update-$Alias.txt
#########

###CSV####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Update"} | Export-CSV C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\CSV\Update-$Alias-csv.csv –NoTypeInformation
#########

###HTML####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Update"} |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,LogonUserDisplayName,LogonType ,ItemSubject,FolderPathName,InternalLogonType,SourceItemSubjectsList,SourceItemFolderPathNamesList,ClientProcessName,ClientInfoString | ConvertTo-Html -head $htstyle -Body  "<H1>Display Audit information about UPDATE activities for $Alias Mailbox</H1>"  | Out-File C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\HTML\Update-$Alias-HTML.html
#########

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

#----------------------------------------------------------
#######################
# Display Audit information about “Move” activities
#######################

###TXT####
$FormatEnumerationLimit = -1
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Move"}  |FL >C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\TXT\Move-$Alias.txt
#########

###CSV####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Move"} | Export-CSV C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\CSV\Move-$Alias-csv.csv –NoTypeInformation
#########

###HTML####
Search-MailboxAuditLog -Identity $Alias -LogonTypes Admin,Delegate -ShowDetails | Where-Object {$_.Operation -eq "Move"} |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,LogonUserDisplayName,LogonType ,ItemSubject,FolderPathName,InternalLogonType,SourceItemSubjectsList,SourceItemFolderPathNamesList,ClientProcessName,ClientInfoString | ConvertTo-Html -head $htstyle -Body  "<H1>Display Audit information about MOVE activities for $Alias Mailbox</H1>"   | Out-File C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\HTML\Move-$Alias-HTML.html
#########

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

#----------------------------------------------------------
#######################
# Display Audit information about “MoveToDeletedItems ” activities
#######################



###TXT####
$FormatEnumerationLimit = -1
$searchAudit | Where-Object {$_.Operation -eq "MoveToDeletedItems "} |FL > C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\TXT\MoveToDeletedItems-$Alias.txt
#########

###CSV####
$searchAudit | Where-Object {$_.Operation -eq "MoveToDeletedItems "} | Export-CSV C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\CSV\MoveToDeletedItems-$Aliascsv.csv –NoTypeInformation
#########

###HTML####
$searchAudit | Where-Object {$_.Operation -eq "MoveToDeletedItems "} |select MailboxResolvedOwnerName, LastAccessed, Operation,OperationResult,LogonUserDisplayName,LogonType ,ItemSubject,FolderPathName,InternalLogonType,SourceItemSubjectsList,SourceItemFolderPathNamesList,ClientProcessName,ClientInfoString | ConvertTo-Html -head $htstyle -Body  "<H1>Display Audit information about MOVE TO DELETED ITEMS activities for $Alias Mailbox</H1>"   | Out-File C:\INFO\Audit-INFO\Non-Owner-Mailbox-Access\HTML\MoveToDeletedItems-$Alias-HTML.html
#########

#----------------------------------------------------------
}



24{

####################################################################################################
# Export content of the Administrator audit log (show all events) to file
######################################################################################################

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

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


if (!(Test-Path -path C:\INFO\Audit-INFO\Admin-LOG))
{
New-Item C:\INFO\Audit-INFO\Admin-LOG -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


#----------------------------------------------------------
#######################
# content of the administrator audit log -show all events
#######################


###TXT####
Search-AdminAuditLog   >C:\INFO\Audit-INFO\Admin-LOG\All-admin-operations-LOG.txt
#########

###CSV####
Search-AdminAuditLog | Export-CSV C:\INFO\Audit-INFO\Admin-LOG\All-admin-operations-LOG.csv –NoTypeInformation
#########

###HTML####
Search-AdminAuditLog | select ObjectModified,CmdletName,CmdletParameters,Succeeded,Error,RunDate,IsValid,ObjectState | ConvertTo-Html -head $htstyle -Body  "<H1>Display content of the administrator audit log -show all events</H1>"   | Out-File C:\INFO\Audit-INFO\Admin-LOG\All-admin-operations-LOG.html
#########

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

}


25{

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

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

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


if (!(Test-Path -path C:\INFO\Audit-INFO\Admin-LOG))
{
New-Item C:\INFO\Audit-INFO\Admin-LOG -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

				
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the Recipient name "
					write-host



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

###TXT####
search-AdminAuditLog –UserIds $Alias              >C:\INFO\Audit-INFO\Admin-LOG\admin-LOG-for-$Alias.txt
#########

###CSV####
search-AdminAuditLog –UserIds $Alias  | Export-CSV C:\INFO\Audit-INFO\Admin-LOG\admin-LOG-for-$Alias.csv –NoTypeInformation
#########

###HTML####
search-AdminAuditLog –UserIds $Alias  | select ObjectModified,CmdletName,CmdletParameters,Succeeded,Error,RunDate,IsValid,ObjectState | ConvertTo-Html -head $htstyle -Body  "<H1>Display content of the administrator audit log for: $Alias Mailbox</H1>"   | Out-File C:\INFO\Audit-INFO\Admin-LOG\admin-LOG-for-$Alias.html
#########

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

}


26{

################################################################################################
# Export Audit information to XML File + Send the result to Email address 
################################################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will: '
write-host  -ForegroundColor white  	'Export Audit information to XML File + Send the result to Email address      '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'New-MailboxAuditLogSearch –Name <String> -LogonTypes Admin,Delegate –StartDate <mm/dd/yyyy> –EndDate <mm/dd/yyyy> –StatusMailRecipients <Email Address>     '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host
write-host
write-host

# Section 2: user input

write-host
write-host -ForegroundColor Yellow	"Type the string value of title"  
write-host -ForegroundColor Yellow	"For example: This is my report"
write-host
$Title = Read-Host "Type the string value of title "
write-host

write-host
write-host -ForegroundColor Yellow	"Type the start date in mm/dd/yyyy format"  
write-host -ForegroundColor Yellow	"For example: 05/25/2013"
write-host
$StartDate = Read-Host "Type the start date in mm/dd/yyyy format "
write-host

write-host
write-host -ForegroundColor Yellow	"Type the End date in mm/dd/yyyy format"  
write-host -ForegroundColor Yellow	"For example: 05/25/2013"
write-host
$EndDate = Read-Host "Type the end date in mm/dd/yyyy format "
write-host

write-host
write-host -ForegroundColor Yellow	"Type the name the recipient email address That will get the mail "  
write-host -ForegroundColor Yellow	"For example: John@contoso.com"
write-host
$Email = Read-Host "Type the name the recipient Alias That will get the mail "
write-host


# Section 3: PowerShell Command




New-MailboxAuditLogSearch –Name "$Title " -LogonTypes Admin,Delegate –StartDate "$StartDate" –EndDate "$EndDate" –StatusMailRecipients $Email

# Section 4: export info

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

}





27{

####################################################################################################
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
######################################################################################################

# 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 export '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host


# Section 2: user input	
					
					write-host -ForegroundColor white	'User input '
					write-host -ForegroundColor white	---------------------------------------------------------------------------- 
					write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
					write-host
					write-host -ForegroundColor Yellow	"1. Recipient name "  
					write-host -ForegroundColor Yellow	"For example:  John@o365info.com "
					write-host
					$Alias  = Read-Host "Type the User name That wants to display his folder permissions "
					write-host	
						
						
						# Section 3: PowerShell Command
						$Alias = Read-Host "Type the User name That wants to display his folder permissions "
						write-host
						$mbox = $Alias+":\calendar"

						$con = $Alias+":\Contacts"



#Section 3: Display Information


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

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




New-Item -ItemType file -Path C:\INFO\Mailbox_and_folder_permissions\permissions.txt 

Set-content  -value "--------------------------" -path C:\INFO\Mailbox_and_folder_permissions\permissions.txt 
Set-content  -value " Display information about Calendar Permission" -path C:\INFO\Mailbox_and_folder_permissions\permissions.txt 
Set-content  -value "--------------------------" -path C:\INFO\Mailbox_and_folder_permissions\permissions.txt 




Get-MailboxFolderPermission  $mbox | Select Identity,FolderName, user, AccessRights |  ForEach {$_} -end  {"`r`n---`r`n"} | out-file C:\INFO\Mailbox_and_folder_permissions\permissions.txt  -append




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 $Alias | 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  $Alias | 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 $Alias | FL displayname,GrantSendOnBehalfTo | 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


}



						
				 
				#+++++++++++++++++++
				# Step -05 Finish  
				##++++++++++++++++++
				 
				 
				28{

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


				write-host -ForegroundColor Yellow Choosing this option will Disconnect the current PowerShell session 

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

				write-host
				write-host

				#———— Indication ———————

				if ($lastexitcode -eq 0)
				{
					write-host -------------------------------------------------------------
					write-host "The command complete successfully !" -ForegroundColor Yellow
					write-host "The PowerShell session is disconnected" -ForegroundColor Yellow
					write-host -------------------------------------------------------------
				}
				else

				{
					write-host "The command Failed :-(" -ForegroundColor red
					
				}

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


				}




				29{

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


				$Loop = $True
				Exit
				}

				}


				}
