Remove/Add Rights to Shared O365 Mailbox

Full access rights

Add-MailboxPermission -Identity shared@domain.com -User user@domain.com -AccessRights FullAccess -InheritanceType All
Remove-MailboxPermission -Identity shared@domain.com -User user@domain.com -AccessRights FullAccess -IneritanceType All

Send As

Add-RecipientPermission -Identity shared@domain.com -AccessRights SendAs -Trustee user@domain.com
Remove-MailboxPermission -Identity shared@domain.com -AcccessRights SendAs -Trustee user@domain.com

Send on Behalf


Set-Mailbox -Identity shared@domain.com -GrantSendOnBehalfTo @{remove="user@domain.com"}
Set-Mailbox -Identity shared@domain.com -GrantSendOnBehalfTo @{add="user@domain.com"}

Function to add all permissions for User to Shared Mailbox

function addperms ($sharedmb, $user)
{
Add-MailboxPermission -Identity $sharedmb -User $user -AccessRights FullAccess -InheritanceType All
Add-RecipientPermission -Identity $sharedmb -AccessRights SendAs -Trustee $user
Set-Mailbox -Identity $sharedmb -GrantSendOnBehalfTo @{add="$user"}}

Function to remove all permissions for User to Shared Mailbox

function remperms ($sharedmb, $user)
{
Remove-MailboxPermission -Identity $sharedmb -User $user -AccessRights FullAccess -InheritanceType All
Remove-RecipientPermission -Identity $sharedmb -AccessRights SendAs -Trustee $user
Set-Mailbox -Identity $sharedmb -GrantSendOnBehalfTo @{remove="$user"}}

Remove/Add Email Address O365

Connect to O365 Exchange Online

Then confirm that the user doesn’t already have the email address

Get-Mailbox user_alias@domain.com



Set-Mailbox user@domain.com -EmailAddresses @{add="user_alias@domain.com"}


Review the assigned addresses



$userAcc = Get-Mailbox user@domain.com


$userAcc.EmailAddresses | fl

To remove an address


Set-Mailbox user@domain.com -EmailAddresses @{remove="user_alias@domain.com"}

Send alert for Windows Service Error

First, we need to create the Powershell script (Source from HowToGeek.com):

$EmailFrom = "emailID@emaildomain.com"
$EmailTo = "destination@somedomain.com"
$Subject = "The subject of your email"
$Body = "What do you want your email to say"
$SMTPServer = "smtp.email.server.address"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("usr", "pass");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Then we need a script to invoke the powershell script

powershell & "C:\PathToPowerShellScript\myPowerShellEmailScript.ps1"

Finally, modify the service to execute a command on failure:

SC failure serviceName command="C:\PathToBat\MyScript.bat"

Power Query VLOOKUP Function

<pThis is a custom VLOOKUP function for Power Query, created by Ken Puls

let pqVLOOKUP = (lookup_value as any, table_array as table, col_index_number as number, optional approximate_match as logical ) as any =>
let
/*Provide optional match if user didn't */
matchtype =
if approximate_match = null
then true
else approximate_match,
/*Get name of return column */
Cols = Table.ColumnNames(table_array),
ColTable = Table.FromList(Cols, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ColName_match = Record.Field(ColTable{0},"Column1"),
ColName_return = Record.Field(ColTable{col_index_number - 1},"Column1"),
/*Find closest match */
SortData = Table.Sort(table_array,{{ColName_match, Order.Descending}}),
RenameLookupCol = Table.RenameColumns(SortData,{{ColName_match, "Lookup"}}),
RemoveExcess = Table.SelectRows(RenameLookupCol, each [Lookup] <= lookup_value),
ClosestMatch=
if Table.IsEmpty(RemoveExcess)=true
then "#N/A"
else Record.Field(RemoveExcess{0},"Lookup"),
/*What should be returned in case of approximate match? */
ClosestReturn=
if Table.IsEmpty(RemoveExcess)=true
then "#N/A"
else Record.Field(RemoveExcess{0},ColName_return),
/*Modify result if we need an exact match */
Return =
if matchtype=true
then ClosestReturn
else
if lookup_value = ClosestMatch
then ClosestReturn
else "#N/A"
in Return
in pqVLOOKUP

Grant rights to Active Directory Group on SQL Server

Rather than adding each user from an AD security group, use that group to globally manage rights on SQL Server to all of those users, where appropriate, of course.

USE master;
GO
CREATE LOGIN [DOMAIN\Group Name] FROM WINDOWS;
GO
USE DatabaseName;
GO
CREATE USER [DOMAIN\Group Name] FROM LOGIN [DOMAIN\Group Name];
GO
-- assign the user a role
EXEC sp_addrolemember db_datareader, [DOMAIN\Group Name];
GO