Set-Mailbox -Identity username -ForwardingAddress $null
Exchange
Get-Recipient -resultSize unlimited | select name -expand emailAddresses | where {$_.smtpAddress -match ".*scs*"} | Format-Table name, smtpaddress Search-Mailbox -Identity “USERNAME” -DeleteContent
Enable modern authentication in Exchange Online:
Set-OrganizationConfig -OAuth2ClientProfileEnabled $trueDisable modern authentication in Exchange Online:
Set-OrganizationConfig -OAuth2ClientProfileEnabled $falseTo verify that the change was successful, run this command:
Get-OrganizationConfig | Format-Table -Auto Name,OAuth*
$Mailboxes = Get-Mailbox -id Deborah_Polen-Pitman
$Results = foreach( $Mailbox in $Mailboxes ){
$Folders = $MailBox |
Get-MailboxFolderStatistics |
Measure-Object |
Select-Object -ExpandProperty Count
New-Object -TypeName PSCustomObject -Property @{
Username = $Mailbox.Alias
FolderCount = $Folders
}
}
$Results |
Select-Object -Property Username, FolderCount Get-MailboxFolderStatistics -Identity USERNAME | Select Name,FolderPath,FolderSize,ItemsInFolder
Get-ExchangeServer | ?{$_.IsHubTransportServer -eq $true} | Get-Queue | get-message | ? {$_.fromAddress -eq "<>"} | remove-message Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize -First 10
function check_queue
{
$QueueCount = get-transportserver | get-queue | measure-object MessageCount -max
# Set the limit here
if ($QueueCount.Maximum -gt 20)
{
send_email $QueueCount.Maximum
exit
}
# How often to check
start-sleep -s 300
check_queue
}
function send_email
{param ($queue_size)
$emailFrom = "from@who.com"
$emailTo = "to@who.com"
$subject = "Exchange queue at $queue_size"
$body = "Mail queues are high, last seen at $queue_size"
$smtpServer = "smtp.mydomain.net"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
}
check_queue
Use the start-job command.
start-job ./CheckQueue.ps1
># Setting the parameters
Param (
[Parameter(Mandatory=$true)]
[string]$Username
)
# Import the tools to work with AD.
Import-Module ActiveDirectory
# Get Primary Proxy Address.
$user = Get-ADUser -Identity $username -Properties proxyAddresses
$primarySMTPAddress = ""
foreach ($address in $user.proxyAddresses)
{
if (($address.Length -gt 5) -and ($address.SubString(0,5) -ceq 'SMTP:'))
{
$primarySMTPAddress = $address.SubString(5)
break
}
}
$primarySMTPAddress