Posts Tagged ‘powershell’

With this PowerShell command you get an overview of database sizes, last full backups and active servers.

(get-mailboxdatabase -status) | foreach-object {write-host $_Server $_.Name $_.lastfullbackup $_.databasesize}

Cheers,

Chris

A quick powershell command to figure out the number of mailboxes per database:

(get-mailboxdatabase) | foreach-object {write-host $_.name (get-mailbox -database $_.name).count}

Cheers,

Chris

If you want to discover where a specific user has Full Access you can use this PowerShell command:

Get-Mailbox | Get-MailboxPermission -User user@domain.com | where { ($_.AccessRights -eq “FullAccess”) }

Cheers,

Chris

The follwing script generates e-mail statistics of your exchange environment looking like this:
(Download the script HERE!)

Generated on Server: MAILSERVER
Date: 17.01.2012
Sent mails: 532435
Size of sent mails: 4.419,24 MB
Size of biggest mail out: 21,74 MB
Average size out: 217,69 KB
Quantity incoming mails: 66496
Size of received mails : 4.609,09 MB
Size of biggest mail in: 22,52 MB
Average size in : 161,96 KB
Overall quantity : 43172
Overall size : 9.028,33 MB

You have to change the following parameters:

$SmtpClient.Host = “YOUR_HT_SERVER”
$mailmessage.from = “Exchange_2010_NoReply@YOURDOMAIN.COM”
$mailmessage.To.add(“RECIPIENT@YOURDOMAIN.COM”)
# $mailmessage.CC.add(“CC_RECIPIENT@YOURDOMAIN.COM”)
$mailmessage.Subject = “Exchange daily message Report

$Localhost = $env:COMPUTERNAME
#Load Exchange PS Snapin
If ((Get-PSSnapin | Where-Object {$_.Name -eq “Microsoft.Exchange.Management.PowerShell.E2010”} ).name -eq ‘Microsoft.Exchange.Management.PowerShell.E2010’)
{
Write-Host “Exchange Snapin is already loaded….”
}

else
{
Write-Host “Loading Exchange Snapin Please Wait….”; Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
Write-Host “running…”

$hubs = Get-TransportServer

# Get the start date for the tracking log search
$Start = (Get-Date -Hour 00 -Minute 00 -Second 00).AddDays(-1)

# Get the end date for the tracking log search
$End = (Get-Date -Hour 23 -Minute 59 -Second 59).AddDays(-1)

$Datum = $Start.ToShortDateString()

$receive = $hubs | get-messagetrackinglog -Start $Start -End $End -EventID “RECEIVE” -ResultSize Unlimited | select Sender,RecipientCount,TotalBytes,Recipients
$send = $hubs | get-messagetrackinglog -Start $Start -End $End -EventID “SEND” -ResultSize Unlimited | select Sender,RecipientCount,TotalBytes
$mreceive = $receive | Measure-Object TotalBytes -maximum -minimum -average -sum
$msend = $send | Measure-Object TotalBytes -maximum -minimum -average -sum

$anzahl = $mreceive.count + $msend.count
$volumen = ($mreceive.sum + $msend.sum) / (1024 * 1024)

$volumen = “{0:N2}” -f $volumen + ” MB”

$msendmb = $msend.sum / (1024 * 1024)
$vsend = “{0:N2}” -f $msendmb + ” MB”
$bigsend = $msend.maximum / (1024 * 1024)
$avsend = $msend.average / 1024

$bigsendmb = “{0:N2}” -f $bigsend + ” MB”
$avsendkb = “{0:N2}” -f $avsend + ” KB”

$mreceivemb = $mreceive.sum / (1024 * 1024)
$vreceive = “{0:N2}” -f $mreceivemb + ” MB”
$bigreceive = $mreceive.maximum / (1024 * 1024)
$avreceive = $mreceive.average / 1024

$bigreceivemb = “{0:N2}” -f $bigreceive + ” MB”
$avreceivekb = “{0:N2}” -f $avreceive + ” KB”

#$senders = $send | Group-Object Sender | Sort-Object Count -Descending
#$topsender = $senders[0].Name
#$topsender += $senders[0].Count

#$receivers = $receive | Group-Object Recipients | Sort-Object Count -Descending
#$topreceiver = $receivers[0]
#$topreceiver

$computer = gc env:computername
$obj = new-object psObject

$obj |Add-Member -MemberType noteproperty -Name “Generated on server:” -Value $Computer
$obj |Add-Member -MemberType noteproperty -Name “Date :” -Value $Datum
$obj |Add-Member -MemberType noteproperty -Name “Sent mails :” -Value $msend.Count
$obj |Add-Member -MemberType noteproperty -Name “Size of sent mails:” -Value $vsend
$obj |Add-Member -MemberType noteproperty -Name “Size of biggest mail out:” -value $bigsendmb
$obj |Add-Member -MemberType noteproperty -Name “Average size out :” -value $avsendkb
$obj |Add-Member -MemberType noteproperty -Name “Quantity incoming mails :” -Value $mreceive.Count
$obj |Add-Member -MemberType noteproperty -Name “Size of received mails :” -Value $vreceive
$obj |Add-Member -MemberType noteproperty -Name “Size of biggest mail in :” -value $bigreceivemb
$obj |Add-Member -MemberType noteproperty -Name “Average size in :” -value $avreceivekb
$obj |Add-Member -MemberType noteproperty -Name “Overall quantity :” -Value $anzahl
$obj |Add-Member -MemberType noteproperty -Name “Overall size :” -Value $volumen

$out = $Datum + “;” + $msend.count + “;” + $vsend + “;” + $mreceive.count + “;” + $vreceive + “;” + $anzahl + “;” + $volumen
$out | out-file c:\daily.csv -append -encoding default

function sendmail($body)
{
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = “YOUR_HT_SERVER”
$mailmessage.from = “Exchange_2010_NoReply@YOURDOMAIN.COM”
$mailmessage.To.add(“RECIPIENT@YOURDOMAIN.COM”)
# $mailmessage.CC.add(“CC_RECIPIENT@YOURDOMAIN.COM”)
$mailmessage.Subject = “Exchange daily message Report $Datum”
$MailMessage.IsBodyHtml = $false
$mailmessage.Body = $body

$smtpclient.Send($mailmessage)
}

$obj = $obj -replace(“@{“,””)
$obj = $obj -replace(“=”,”:`t”)
$obj = $obj -replace(“; “,”`n”)
$obj = $obj -replace(“}”,”`n”)

sendmail $obj

Cheers,
Chris

You can start PowerShell scripts via taskplaner using a batch file
startscript.bat ->

Powershell.exe -command “.’C:\Scripts\script.ps1′”

script.ps1 ->

$localhost    = $env:COMPUTERNAME
#load exchange ps snapin if necessary
If ((Get-PSSnapin  | Where-Object {$_.Name -eq “Microsoft.Exchange.Management.PowerShell.E2010”} ).name -eq ‘Microsoft.Exchange.Management.PowerShell.E2010’)
{
Write-Host “Exchange Snapin loaded”
}

else
{
Write-Host “Loading Exchange Snapin”; Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
Write-Host “running”

After this you can insert your script code.

For some reasons it is necessarry to enable circular logging on your Exchange databases.
This reasons could be moving many or large mailboxes or perhaps a broken backup which causes the logfile partition to be stuffed with logfiles.

However, you can enable circular logging via Exchange Management Console (EMC) or via PowerShell. With PowerShell you can set it for all databases at once.

Get-Mailboxdatabase | Set-MailboxDatabase -CircularloggingEnabled:$true

I would strongly suggest enabling circular logging should be the last option. After you solve your issue you should immidiately disable circular logging.

Get-Mailboxdatabase | Set-MailboxDatabase -CircularloggingEnabled:$false

Cheers,

Chris

ActiveSync device management through the Exchange Management Console is limited and slow. To quickly get the device access state and set access parameters simple use some PowerShell commands.
First get user’s DeviceId:

Get-ActiveSyncDevice -Mailbox user@domain.com | Fl DeviceId

To allow a specific device:

Set-CASMailbox –Identity user@domain.com –ActiveSyncAllowedDeviceIDs “DeviceID1”, “DeviceID2”

To deny a secific device:

Set-CASMailbox -Identity user@domain.com -ActiveSyncBlockedDeviceIDs “DeviceID1”, “DeviceID2”

Cheers,

Chris

If you want to block RPC over HTTPS you can use PowerShell to get it done quick:

Get-Mailbox -RecipientType ‘UserMailbox’ | Set-CASMailbox -MAPIBlockOutlookRpcHttp:$True

If you want to limit this to a special database:

Get-Mailbox -ResultSize unlimited -Filter ‘((RecipientTypeDetails -like ”*UserMailbox*”) -and (((Database -eq ”CN=DB_NAME,CN=Databases,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=ORGANISATION,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=DOMAIN,DC=COM”))))’ | Set-CASMailbox -MAPIBlockOutlookRpcHttp:$False

You also can run this automatic via task scheduler.

Cheers,

Chris

Every day a new challenge.

A customer requested to set the default message type in OWA to Arial.
Like almost ever you can do this easy with PowerShell:

Get-Mailbox -RecipientType ‘UserMailbox’ | Get-MailboxMessageConfiguration  | Set-MailboxMessageConfiguration -DefaultFontName Arial

You can also do this for various parameters. Take a look at TechNet for a full list of parameters.

Cheers,

Chris

Often I’m confronted with problems of mail submissions in freshly migrated Exchange environments.

In migrated environments it could happen, that the old ExchangeLegacyDN is missing and users can’t answer on old mails. This might happen, when you migrate users between Exchange organizations.

To mitigate this issue, you can add the old ExchangeLegacyDN as X500 proxy address. This fixes the issue and the user’s mailbox is addressable via the old LegacyDN.

You can do this by hand, by ADModify.NET or simple use PowerShell to fix this.

Get-Mailbox -recipienttype ‘usermailbox’ | foreach {$_emailaddress += [microsoft.exchange.data.custom.proxyaddress](“X500:/O=ORG/OU=US/CN=$_.ALIAS”)$_set-mailbox}

Thanks to Frank for this helpful PowerShell cmdlet.

Cheers,

Chris