

#------------------------------------------------------------------------------
# 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 ()
#------------------------------------------------------------------------------
# Hope that you enjoy it ! 
# And May the force of PowerShell will be with you   :-)
# 20-4-2014    
# Version WP-001
#------------------------------------------------------------------------------



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

}

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

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



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


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

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

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

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

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

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

"@

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

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Export information: Exchange Online + Office 365 ( AD Azure) objects PowerShell Script menu  
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$Loop = $true
While ($Loop)
{
    write-host 
    write-host +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    write-host   "Shared-Mailbox |  PowerShell Script menu"
    write-host +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    write-host
    write-host -ForegroundColor green  'Connect PowerShell session to AD Azure and Exchange Online' 
    write-host -ForegroundColor green  '--------------------------------------------------------------' 
    write-host -ForegroundColor Yellow ' 0)   Login in using your Office 365 Administrator credentials' 
    write-host
    write-host
    write-host -ForegroundColor green						' Section A: Create Shared Mailbox and Distribution group ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'1)  Create new Shared Mailbox'
	write-host 												'2)  Create new Security Distribution Group'
	write-host
    write-host -ForegroundColor green						'  Section B: Assign permissions to Shared Mailbox  ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'3)  Assign FULL ACCESS permissions for Shared Mailbox'
	write-host 												'4)  Assign SEND AS permissions for Shared Mailbox'
	write-host 												'5)  Assign FULL ACCESS + SEND AS permissions for Shared Mailbox + AutoMAP'
	write-host 												'6)  Assign Access permissions to the Shared Mailbox Calendar'
    write-host
    write-host -ForegroundColor green						' Section C: Display permissions and Information ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'7)  Display FULL ACCESS and SEND AS permissions for Shared Mailbox'
	write-host 												'8)  Display all of the existing Shared Mailboxes'
	write-host
    write-host -ForegroundColor green						' Section D: Revoke permissions ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'9)   Revoke FULL ACCESS permissions for Shared Mailbox '
	write-host 												'10)  Revoke SEND AS permissions for Shared Mailbo'
	write-host
    write-host -ForegroundColor green						' Section E: Convert Mailbox ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'11)  Convert Regular mailbox to Shared Mailbox'
	write-host 												'12)  Convert Shared MailBox to Regular Mailbox'
	write-host
    write-host -ForegroundColor green						' Section F: Shared Mailbox Settings ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'13)  Set Shared mailbox size to 10 GB'
	write-host
    write-host -ForegroundColor green						' Section G: all in one ' 
	write-host -ForegroundColor green  '--------------------------------------------------------------' 
	write-host 												'14)  Create shared Mailbox + Distribution Group + Assign permission '
	write-host
    write-host -ForegroundColor Red            "15)  Disconnect PowerShell session" 
    write-host
    write-host -ForegroundColor Red            "16)  Exit" 
    write-host

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


{


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


		0
        {

            # Specify your administrative user credentials on the line below 

            $user = Admin@.....

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

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

            

            # Establish an Remote PowerShell Session to Exchange Online 

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

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

            


        }



		
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section A: Create Shared Mailbox and Distribution group
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


1
{

#####################################################################
#  Create NEW Shared 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  	'* Create NEW Shared Mailbox '

write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'New-Mailbox -Name <Shared Mailbox Name> -Shared  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input

write-host -ForegroundColor Yellow	"You will need to provide 1 parameter:"  
write-host
write-host -ForegroundColor Yellow	"1) The Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host


# Section 3: PowerShell Command


New-Mailbox -Name $SMBNAME -Shared 

# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"A new Shared Mailbox Named: "	-nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" was created  " 
write-host -------------------------------------------------------------
}

# End of Indication 


# Section 4: Display Information
write-host
write-host
write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display information for: "$SMBNAME".ToUpper() Shared Mailbox
write-host ---------------------------------------------------------------------------

Get-Mailbox "$SMBNAME" |FL  DisplayName, alias, EmailAddresses ,ProhibitSendQuota  | Out-String

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

}




2
{

#####################################################################
#   Create NEW Security Distribution Group
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'This option will create new Security Distribution Group '
write-host  -ForegroundColor white  	'And assign Email Address to the group  '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'New-DistributionGroup -Name <Group Name> -Type "Security" -PrimarySmtpAddress <Group Name>@<Domain Name>  '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host



# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is the name of the Distribution Group"  
write-host -ForegroundColor Yellow	"   For example: DL-03"
write-host
$MailRecipient = Read-Host "Type the name of the Distribution Group "

write-host
write-host -ForegroundColor Yellow	"2) The second parameter is The Email Address Suffix" 
write-host -ForegroundColor Yellow	"For example: o365info.com"   
write-host
$DomainName =  Read-Host "Type the Email Domain name Suffix"
write-host
write-host

# Section 3: PowerShell Command

$temp = New-DistributionGroup -Name $MailRecipient -Type "Security" -PrimarySmtpAddress $MailRecipient@$DomainName 


# Section 4: Display Information
write-host
write-host
write-host
write-host ---------------------------------------------------------------------------
write-host -ForegroundColor white	Display information for: "$MailRecipient".ToUpper() Distrabution Group
write-host ---------------------------------------------------------------------------

Get-DistributionGroup "$MailRecipient" |FL  DisplayName, name, PrimarySmtpAddress ,GroupType  | Out-String



# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"A new Distribution Group Named: "	-nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" was created  "	 
write-host -ForegroundColor Yellow	"with the following Email address: "	-nonewline; write-host "$MailRecipient@$DomainName".ToUpper() -ForegroundColor White 
write-host -------------------------------------------------------------
}
# End of Indication 


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

}


#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section B: Assign permissions to Shared Mailbox
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


3
{


####################################################################################################
#Assign FULL Access permissions to user/Distribution Group for Shared 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  	'The following option will: '
write-host  -ForegroundColor white  	'Grant "Full Access" permissions to users or groups for a selected Shared Mailbox '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Add-MailboxPermission <Shared Mailbox>  -User <Mail Recipient> -AccessRights FullAccess -InheritanceType all '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is: the Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host
write-host -ForegroundColor Yellow	"2) The second parameter is the name of the user ( or Group)" 
write-host -ForegroundColor Yellow	"   That will have Full access Permission for the Shared Mailbox" 
write-host -ForegroundColor Yellow	"   For example: User1"   
write-host
$MailRecipient =  Read-Host "Type the User/Group name"


# Section 3: PowerShell Command

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

# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The User/Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White  
write-host -ForegroundColor Yellow	"Have Full access Permission for " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Shared Mailbox"	
write-host -------------------------------------------------------------
}


# End of Indication 

# Section 4: Display Information

write-host
write-host
write-host
write-host ------------------------------------------------------
write-host List of FULL ACCESS permissions for $SMBNAME.ToUpper() Shared Mailbox -ForegroundColor white
write-host -------------------------------------------------------

Get-MailboxPermission $SMBNAME | Where { ($_.IsInherited -eq $False) -and -not ($_.User -like NT AUTHORITY\SELF) } |FL Identity,user,AccessRights | Out-String



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


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

}


4
{


#####################################################################
#  Assign SEND AS permissions to User/Distribution Group for Shared 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  	'The following option will: '
write-host  -ForegroundColor white  	'Grant "Send As" permissions to users or groups for a selected Shared Mailbox '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Add-MailboxPermission <Shared Mailbox>  -Trustee  <Mail Recipient> -AccessRights SendAs -confirm:$False '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is: the Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host
write-host -ForegroundColor Yellow	"2) The second parameter is the name of the user ( or Group)" 
write-host -ForegroundColor Yellow	"   That will have "Send As" Permission for the Shared Mailbox" 
write-host -ForegroundColor Yellow	"   For example: User1"   
write-host
$MailRecipient =  Read-Host "Type the User/Group name"

# Section 3: PowerShell Command

Add-RecipientPermission $SMBNAME -Trustee $MailRecipient -AccessRights SendAs -confirm:$False

# Section 4:  Indication 

write-host
write-host

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

write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The User/Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White  
write-host -ForegroundColor Yellow	"Have Send As Permission for " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Shared Mailbox"	
write-host -------------------------------------------------------------
	
}

# End of Indication 

# Section 4: Display Information
write-host
write-host
write-host ----------------------------------------------------
write-host List of Send As permissions for $SMBNAME.ToUpper() -ForegroundColor white
write-host ----------------------------------------------------


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

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

write-host
write-host


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

}



5
{


####################################################################################################
# Assign FULL ACCESS + SEND AS permissions to User/Distribution Group for Shared Mailbox + AutoMap
######################################################################################################

# Section 1: information 

clear-host
write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'The following option will: '
write-host  -ForegroundColor white  	'Grant "Full Access" permissions + "Send As" permissions '
write-host  -ForegroundColor white  	'To Group for a selected Shared Mailbox '
write-host  -ForegroundColor white  	'We use PowerShell parameter that will '
write-host  -ForegroundColor white  	'Run the AutoMap Option for each of the distribution group members '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host

# Section 2: user input

write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is: the Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host
write-host -ForegroundColor Yellow	"2) The second parameter is the name of the Group" 
write-host -ForegroundColor Yellow	"   That will have "Send As" + "Full Access" Permission for the Shared Mailbox" 
write-host -ForegroundColor Yellow	"   For example: DL-05"   
write-host
$DLNAME =  Read-Host "Type the Group name"



# Section 3: PowerShell Command


$DL = Get-distributiongroupmember $DLNAME | Select-Object -ExpandProperty Name
 
foreach ($S in $DL ) 
{
 
Add-MailboxPermission -Identity $SMBNAME -User $S -AccessRights FullAccess
 

 # Section 4:  Indication 

write-host
write-host

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

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

write-host
write-host $S is a member of the distribution group $DLNAME has been given FULL ACCESS permission to $SMBNAME mailbox -ForegroundColor Yellow
write-host -------------------------------------------------------------

	
}
 

}



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

}




6
{


####################################################################################################
# Assign Publishing Editor Permission to Shared MailBox Calendar
######################################################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'The following option will: '
write-host  -ForegroundColor white  	'Grant "Publishing Editor" permissions '
write-host  -ForegroundColor white  	'To users or groups for a selected Shared Mailbox Calendar '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input

write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is: the Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host
write-host -ForegroundColor Yellow	"2) The second parameter is the name of the user ( or Group)" 
write-host -ForegroundColor Yellow	"   That will have "Send As" + "Full Access" Permission for the Shared Mailbox" 
write-host -ForegroundColor Yellow	"   For example: User1"   
write-host
$MailRecipient =  Read-Host "Type the User/Group name"


# Section 3: PowerShell Command

$mbox = $SMBNAME+":\calendar"

Add-MailboxFolderPermission Identity $mbox -AccessRight ReadItems -User $MailRecipient


# 


# Section 4:  Indication 

write-host
write-host

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

write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The User/Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White   
write-host -ForegroundColor Yellow	"Have Publishing Editor Permission for: " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Shared Mailbox Calendar"	
write-host -------------------------------------------------------------
	
}



# Section 4: Display Information

write-host
write-host
write-host ------------------------------------------------------------------
write-host List of Send As permissions for $SMBNAME.ToUpper() Shared Mailbox Calendar -ForegroundColor white
write-host ------------------------------------------------------------------


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

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

write-host
write-host


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

}




#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#Section C: Display permissions and Information 
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


7
{


####################################################################################################
#Display Full Access and send as permissions for Shared 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  	'The following option will: '
write-host  -ForegroundColor white  	'Display Full Access and send as permissions for a selected Shared Mailbox '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailboxpermission <Shared Mailbox > | Where { ($_.IsInherited -eq $False) -and -not ($_.User -like NT AUTHORITY\SELF) } |Select Identity, user, AccessRights  '
write-host  -ForegroundColor Yellow  	'Get-RecipientPermission  <Shared Mailbox >  | Where { ($_.IsInherited -eq $False) -and -not ($_.Trustee -like NT AUTHORITY\SELF) } | Select Trustee, AccessControlType, AccessRights   '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host



# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 1 parameters"  
write-host
write-host -ForegroundColor Yellow	"1) The Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host



# Section 3: PowerShell Command




# Section 4: Display Information

write-host
write-host
write-host ------------------------------------------------------------------
write-host List of Full Access permissions for $SMBNAME.ToUpper() Shared Mailbox  -ForegroundColor white
write-host ------------------------------------------------------------------

Get-MailboxPermission $SMBNAME | Where { ($_.IsInherited -eq $False) -and -not ($_.User -like NT AUTHORITY\SELF) } |Select Identity,user,AccessRights | Out-String


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

write-host
write-host
write-host ------------------------------------------------------------------
write-host List of Send As permissions for $SMBNAME.ToUpper() Shared Mailbox  -ForegroundColor white
write-host ------------------------------------------------------------------


Get-RecipientPermission $SMBNAME | Where { ($_.IsInherited -eq $False) -and -not ($_.Trustee -like NT AUTHORITY\SELF) } | Select Trustee,AccessControlType,AccessRights | Out-String
# Get-RecipientPermission  <Shared Mailbox >  | Where { ($_.IsInherited -eq $False) -and -not ($_.Trustee -like NT AUTHORITY\SELF) } | Select Trustee, AccessControlType, AccessRights | Out-String
write-host
write-host ------------------------------------------------------------------
write-host
write-host


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

}


8
{


####################################################################################################
# Display all the Shared 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  	'The following option will: '
write-host  -ForegroundColor white  	'Display list of all the Shared Mailbox '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Get-Mailbox -RecipientTypeDetails SharedMailbox | Select alias '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 4: Display Information

write-host 
write-host -------------------------------------------------
write-host -ForegroundColor white	List of existing Shared Mailboxs 
write-host -------------------------------------------------


Get-Mailbox -RecipientTypeDetails SharedMailbox | Select Alias  | Out-String

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


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

}

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




#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section D: Remove permissions 
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



9
{


#####################################################################
#   Revoke "Full Access" permissions for Shared 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  	'The following option will: '
write-host  -ForegroundColor white  	'Revoke "FULL ACCESS" permissions for a Shared Mailbox '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Remove-MailboxPermission <Shared Mailbox >  -User <Mail Recipient> -AccessRights FullAccess -confirm:$False '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is: the Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host
write-host -ForegroundColor Yellow	"2) The second parameter is the name of the user ( or Group)" 
write-host -ForegroundColor Yellow	"   There permissions will be revoked" 
write-host -ForegroundColor Yellow	"   For example: User1"   
write-host
$MailRecipient =  Read-Host "Type the User/Group name"



# Section 3: PowerShell Command

Remove-MailboxPermission $SMBNAME -User $MailRecipient -AccessRights FullAccess -confirm:$False

# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The FULL ACCESS Permission of: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White  
write-host -ForegroundColor Yellow	"for a Shred Mailbox named: " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" was revoked"	
write-host -------------------------------------------------------------
}




# End of Indication 

# Section 4: Display Information

write-host
write-host
write-host

write-host ------------------------------------------------------------------
write-host List of Full Access permissions for $SMBNAME.ToUpper() Shared Mailbox  -ForegroundColor white
write-host ------------------------------------------------------------------

Get-Mailboxpermission $SMBNAME | Where { ($_.IsInherited -eq $False) -and -not ($_.User -like NT AUTHORITY\SELF) } |Select Identity, user, AccessRights | Out-String

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


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

}




10
{


#####################################################################
#   Revoke "Send As" permissions for Shared 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  	'The following option will: '
write-host  -ForegroundColor white  	'Revoke "Send As" permissions for a Shared Mailbox '
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Remove-RecipientPermission <Shared Mailbox >  -AccessRights SendAs -Trustee  <Mail Recipient>  -confirm:$False '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 2 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is: the Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host
write-host -ForegroundColor Yellow	"2) The second parameter is the name of the user ( or Group)" 
write-host -ForegroundColor Yellow	"   There "Send As" permissions will be revoked" 
write-host -ForegroundColor Yellow	"   For example: User1"   
write-host
$MailRecipient =  Read-Host "Type the User/Group name"



# Section 3: PowerShell Command

Remove-RecipientPermission $SMBNAME -AccessRights SendAs -Trustee  $MailRecipient -confirm:$False


# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The Send As Permission of: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White  
write-host -ForegroundColor Yellow	"for a Shred Mailbox named: " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" was revoked"	
write-host -------------------------------------------------------------
}




# End of Indication 

# Section 4: Display Information

write-host
write-host
write-host ------------------------------------------------------------------
write-host List of Send As permissions for $SMBNAME.ToUpper() Shared Mailbox  -ForegroundColor white
write-host ------------------------------------------------------------------


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

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


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

}



#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section E: Convert Mailbox
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



11
{


####################################################################################################
# Convert Regular mailbox to Shared 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  	'The following option will: '
write-host  -ForegroundColor white  	'Convert Regular Mailbox to Shared Mailbox'
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <Mailbox > -Type:shared '
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 1 parameters"  
write-host
write-host -ForegroundColor Yellow	"1) The Regular Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: user01"
write-host
$SMBNAME = Read-Host "Type the name of the Regular Mailbox  "
write-host

# Section 3: PowerShell Command

Set-Mailbox $SMBNAME -Type:shared


# Section 4:  Indication 

write-host
write-host

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

write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"Regular Mailbox: " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Was converted to: "	 
write-host -ForegroundColor Yellow	"Shared Mailbox " 
write-host -ForegroundColor Yellow	"TIP!" 
write-host -ForegroundColor Yellow	"To avoid from assign license to the Shared Mailbox" 
write-host -ForegroundColor Yellow	"Its recommended to set the Shared Mailbox size to 10 GB" 
write-host -ForegroundColor Yellow	"The PowerShell command is: " 
write-host -ForegroundColor white	"Set-Mailbox <MailBox>  -ProhibitSendReceiveQuota 10GB -ProhibitSendQuota 9.75GB -IssueWarningQuota 9.5GB " 
write-host
write-host
write-host -------------------------------------------------------------

	
}

# End of Indication 

# Section 4: Display Information

write-host
write-host
write-host ------------------------------------------------------------------
write-host information about $SMBNAME.ToUpper()  Mailbox  -ForegroundColor white
write-host ------------------------------------------------------------------

Get-Mailbox $SMBNAME | FL DisplayName,RecipientTypeDetails |Out-String


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

}






12
{


####################################################################################################
# Convert Shared MailBox to Regular 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  	'The following option will: '
write-host  -ForegroundColor white  	'Convert Shared Mailbox to Regular Mailbox'
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <Shared Mailbox > -Type:Regular '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 1 parameters"  
write-host
write-host -ForegroundColor Yellow	"1) The Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host

# Section 3: PowerShell Command

Set-Mailbox $SMBNAME -Type:Regular

# Section 4:  Indication 

write-host
write-host

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

write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"Regular Mailbox: " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Was converted to: "	 
write-host -ForegroundColor Yellow	"Shared Mailbox " 
write-host -------------------------------------------------------------

	
}

# End of Indication 

# Section 4: Display Information

write-host
write-host
write-host ------------------------------------------------------------------
write-host information about $SMBNAME.ToUpper()  Mailbox  -ForegroundColor white
write-host ------------------------------------------------------------------

Get-Mailbox $SMBNAME | FL DisplayName , RecipientTypeDetails |Out-String


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

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

}





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

#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section F: Shared Mailbox Settings
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


13{


#####################################################################
#   Set Shared mailbox size to 5GBx
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'The following option will: '
write-host  -ForegroundColor white  	'Set Shared mailbox size to 10 GB'
write-host  -ForegroundColor white		----------------------------------------------------------------------------  
write-host  -ForegroundColor white  	'The PowerShell command that we use is: '
write-host  -ForegroundColor Yellow  	'Set-Mailbox <Shared Mailbox> -ProhibitSendReceiveQuota 10GB -ProhibitSendQuota 9.75GB -IssueWarningQuota 9.5GB '
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host


# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 1 parameters"  
write-host
write-host -ForegroundColor Yellow	"1) The Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host



# Section 3: PowerShell Command

Set-Mailbox $SMBNAME -ProhibitSendReceiveQuota 10GB -ProhibitSendQuota 9.75GB -IssueWarningQuota 9.5GB

# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"The size of Shared Mailbox Named: " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" is: 10GB "	 
write-host -------------------------------------------------------------
}



# End of Indication 

# Section 4: Display Information

write-host
write-host
write-host ------------------------------------------------------------------
write-host information about $SMBNAME.ToUpper()  Mailbox  -ForegroundColor white
write-host ------------------------------------------------------------------


Get-Mailbox $SMBNAME | FL DisplayName,ProhibitSendQuota |Out-String


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



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

}


#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Section G: all in one
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


14
{


#####################################################################
#   all in one
#####################################################################

# Section 1: information 

clear-host

write-host
write-host
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                         
write-host  -ForegroundColor white		Information                                                                                          
write-host  -ForegroundColor white		----------------------------------------------------------------------------                                                             
write-host  -ForegroundColor white  	'The following option will: '
write-host  -ForegroundColor white  	'* Create NEW Shared Mailbox'
write-host  -ForegroundColor white  	'* Assign Email address to the Shared Mailbox' 
write-host  -ForegroundColor white  	'* Set Shared mailbox size to 10GB'
write-host  -ForegroundColor white  	'* Create NEW security Distribution Group'
write-host  -ForegroundColor white  	'* Assign the Distribution Groups FULL ACCESS and SEND AS permissions'
write-host  -ForegroundColor white  	'* Display the User/Distribution group permissions for the Shared Mailbox'
write-host  -ForegroundColor Magenta	oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
write-host
write-host






# Section 2: user input


write-host -ForegroundColor Yellow	"You will need to provide 3 parameters:"  
write-host
write-host -ForegroundColor Yellow	"1) The first parameter is: the Shared Mailbox name"  
write-host -ForegroundColor Yellow	"   For example: Office-Mailbox"
write-host
$SMBNAME = Read-Host "Type the name of the Shared Mailbox  "
write-host
write-host -ForegroundColor Yellow	"2) The second parameter is the name of the user ( or Group)" 
write-host -ForegroundColor Yellow	"   That we be granted with FULL ACCESS and SEND AS permissions" 
write-host -ForegroundColor Yellow	"   For example: User1"   
write-host
$MailRecipient =  Read-Host "Type the User/Group name"
write-host
write-host -ForegroundColor Yellow	"3) The Third parameter is the Email Domain name Suffix" 
write-host -ForegroundColor Yellow	"   That will be assigned to the group and the Shared Mailbox" 
write-host -ForegroundColor Yellow	"   For example: o365info.com"   
write-host
$DomainName =  Read-Host "Type the Email Domain name Suffix"


# Section 3: PowerShell Command

$sec = New-DistributionGroup -Name $MailRecipient -Type "Security" -PrimarySmtpAddress $MailRecipient@$DomainName -notes "This Distribution Group have Full access Permissions and send as Permissions to $SMBNAME Shared MailBox"

# Creating Shared Mail Box

$newmb = New-Mailbox -Name $SMBNAME -Alias $SMBNAME -Shared -PrimarySmtpAddress $SMBNAME@$DomainName
$newmb1 = Set-Mailbox $SMBNAME -ProhibitSendReceiveQuota 10GB -ProhibitSendQuota 9.75GB -IssueWarningQuota 9.5GB
Add-MailboxPermission $SMBNAME -User $MailRecipient -AccessRights FullAccess
Add-RecipientPermission $SMBNAME -Trustee $MailRecipient -AccessRights SendAs -confirm:$False

# Section 4:  Indication 

write-host
write-host

if ($lastexitcode -eq 1)
{
	write-host "The command Failed :-(" -ForegroundColor red
}
else
{
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow	"The command complete successfully !" 
write-host
write-host -ForegroundColor Yellow	"A new Shared mailbox named: " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" was created"	 
write-host -ForegroundColor Yellow	"with the following Email address: " -nonewline; write-host "$SMBNAME@$DomainName".ToUpper() -ForegroundColor White 
write-host -ForegroundColor Yellow	"A new Distribution Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" was created"	 
write-host -ForegroundColor Yellow	"with the following Email address: " -nonewline; write-host "$MailRecipient@$DomainName".ToUpper() -ForegroundColor White 
write-host
write-host -ForegroundColor Yellow	"The User/Distribution Group named: " -nonewline; write-host "$MailRecipient".ToUpper() -ForegroundColor White 
write-host -ForegroundColor Yellow	"Have FULL ACCESS + SEND AS permissions for : " -nonewline; write-host "$SMBNAME".ToUpper() -ForegroundColor White -nonewline; write-host -ForegroundColor Yellow	" Shared Mailbox"	
write-host -------------------------------------------------------------
}


# End of Indication 

# Section 4: Display Information




write-host
write-host
write-host ------------------------------------------------------------------
write-host List of Full Access permissions for $SMBNAME.ToUpper()  Shared Mailbox  -ForegroundColor white
write-host ------------------------------------------------------------------


Get-Mailboxpermission $SMBNAME | Where { ($_.IsInherited -eq $False) -and -not ($_.User -like NT AUTHORITY\SELF) } |Select Identity, user, AccessRights | Out-String


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

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

write-host
write-host
write-host ------------------------------------------------------------------
write-host List of Send As permissions for $SMBNAME.ToUpper()  Shared Mailbox  -ForegroundColor white
write-host ------------------------------------------------------------------


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

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


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

}



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

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


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

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

				write-host
				write-host

				# Indication 

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

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

				# End of Indication 


				}




				16{

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


				$Loop = $True
				Exit
				}

				}


				}

		