Showing posts with label exchange 2010. Show all posts
Showing posts with label exchange 2010. Show all posts

Thursday, October 1, 2015

Exchange shell script as Scheduled task - mailbox and database statistics to e-mail

If you have a script that you run in Exchange Management Shell, you can schedule the task to run in "Scheduled Tasks".

I had to fumble around with this for some time, so I thought I could share. Maybe this will save you just a few minutes. I saw a few resources on the web on how to perform this task. For some reason or another, most of the guides were incorrect or didn't work on my Exchange server (tried on 2010 and 2013).

this is what DID work:

Create a scheduled task in task scheduler > basic task...
For the program/script:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Add this under ARUGEMENTS:

(For Exchange 2010)

-version 2.0 -NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; <path and name of your existing .ps1 file>"

(For Exchange 2013)

-NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; <path and name of your existing .ps1 file>"

On the Exchange Server I created a folder called "scripts" on C:\
My argurment looks like this:

-version 2.0 -NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\scripts\Send_mailbox_stats.ps1"

Continue to configure your scheduled task. Select "Run wheather user is logged on or not", Select a date\time\recurrence under triggers.



You are all set as far as the scheduled task goes.
Here is an awesome script that will send you an email including all of your mailbox sizes and all of your database sized. In my case I have the report e-mailed weekly.

Enjoy:



# ******** Send mailbox statistics script

$Logfile = "C:\mailboxreport.txt"
$mailboxservername = "<YOUR MAILBOX SERVER NAME>"
$NumOfMailboxes = 40   #number of mailboxes to return

#******** delete the existing file, if exists

remove-item $Logfile | out-null


#********* variables for the mail message values 

$FromAddress = "reports@yourdomain.com"
$ToAddress = "youremailaddress@yourdomain.com"
##$ToAddress2 = "otheremailaddress@yourdomain.com"
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "YourOutboundmailserver.yourdomain.com"


#********** get and write the current date/time to the file
$LogTime = Get-Date -Format "MM-dd-yyyy_hh:mm:ss"
$LogTime >> $logfile

$mailboxservername >> $LogFile


#*********** Formatting for mailbox statistics # adjust the widths if desired

$a = @{Expression={$_.DisplayName};Label="Name";width=28}, `
@{Expression={$_.TotalItemSize.Value.ToMB()};Label="Size (MB)";width=9}, `
@{Expression={$_.itemCount};Label="Items";width=11}

#*********** Now get the stats and send to a text file

write-Output "" >> $Logfile
write-output "Mailbox Information: Top $numOfMailboxes" >> $Logfile

Get-MailboxStatistics -server $mailboxservername | Sort-Object TotalItemSize -Descending | ft $a | select-object -first $NumOfMailboxes >> $Logfile | out-null

#*********** Formatting for database statistics

$a =  @{Expression={$_.Name};Label="Name";width=28}, @{Expression={$_.databasesize.ToGB()};Label="Size (GB)";width=9}, `
@{Expression={$_.Availablenewmailboxspace.toMB()};Label="Avail (MB)";width=11}

#*********** Now get the database stats and send to text file

write-output "" >> $Logfile
write-output "Database Statistics for server $mailboxservername" >> $logfile
Get-MailboxDatabase -Status | sort name | ft $a  >> $Logfile

#********** Create the mail message and add the statistics text file as an attachment

$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, 
$MessageSubject, $MessageBody
$Attachment = New-Object Net.Mail.Attachment($logfile) 
$SMTPMessage.Attachments.Add($Attachment)
#$SMTPMessage.To.Add($ToAddress2)

#*************** Send the message *****************

$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage) | out-null






Monday, September 28, 2015

Exchange 2010 and iPhone, Connect get mail, Connection to the server failed

During an upgrade from Exchange 2007 to Exchange 2010, whilst re-homing the CAS server and re-homing mail flow from 2007 to 2010, all of a sudden some users could not connect to Exchange from their iPhones. Only SOME users were affected and only iPhone users. We have a mix of iPhone and  various Droid phones in use.

iPhone users were receiving:

Cannot get mail the connection to the server failed

tried rebooting phone - no luck

For SOME reason - the issue was fixed for 5 users by turning off SSL and then back on
For SOME reason - the issue was fixed for 3 users by turning on Airplane mode and then off

That still left me with about 25 users that couldn't get e-mail/calendar/contacts on iPhones.

Troubleshooting led me here (solution 3)
http://www.iphonetopics.com/cannot-get-mail-the-connection-to-the-server-failed/

Again, for SOME reason, some users did not have "Include inheritable permissions from this object's parent" enabled (ticked)

Open Active Directory Users and computer
On the top menu choose View > Advanced Features.
Find and right click the user account and choose Properties.
Choose Security tab. Then choose Advanced.
Select the check box ““Include inheritable permissions from this object’s parent”.

Checking this box fixed the issue, but now the bigger issue was how to do this in bulk for all my users.
Here is a powershell script that will enable (tick the box) for all users in AD recursing down an OU structure


Import-Module activedirectory
$Users = Get-ADUser -LDAPFilter “(ObjectClass=User)” -SearchBase “OU=accounts_active_users,DC=***,DC=***"
ForEach($User in $Users)
{
    # Bind users
    $OU = [ADSI](“LDAP://” + $User)
    $SecGroup = $OU.PSBase.ObjectSecurity

    if ($SecGroup.get_AreAccessRulesProtected())
    {
        $isProtected = $false ## Allows inheritance
        $preserveInheritance = $true ## Preserves inheritance
        $SecGroup.SetAccessRuleProtection($isProtected, $preserveInheritance)
        $OU.PSBase.CommitChanges()
        Write-Host “$User inheritance has been set”;
    }
    else
    {
        Write-Host “$User inheritance already set”
    }
}

taken from: http://www.experts-exchange.com/Software/Server_Software/Active_Directory/Q_28553940.html

Friday, February 20, 2015

Error delegating, Outlook 2010, The Delegates were not saved correctly, cannot activate send-on-behalf-of list, KB2593557

Outlook 2010, error delegating AGAIN.

I had a previous post with problems delegating calendar access in Outlook 2007. Now I am having problems with users delegating Inbox access in Outlook 2010.

Error looks like:

Again, KB2593557 claims to fix the problem but it does NOT! It only suppresses the error.

Add "Write personal information" (and Read personal information) to the "SELF" object in AD on the ACL.

As I looked through my users (randomly), I found some user account already had this set properly and others did not. I do not know how or why this came about but I intend on fixing it.

I figured that I would set the settings at once for all users
use this script

--== Begin Script ==--
$mailboxes = Get-Mailbox

foreach ($mailbox in $mailboxes)
 {
 $user = $mailbox.alias
 $mailboxname = $mailbox.name
 Write-Host "Processing... $user,$mailboxname"
 Add-ADPermission -Identity "$mailboxname" -User 'NT Authority\self' `
    -AccessRights ReadProperty, WriteProperty -Properties 'Personal Information'
 }

--== End Script ==--

Save as .ps1, run from Exchange Management Shell



Monday, November 24, 2014

Booking room calendars over 180 days out on Exchange 2010 (affects Exchange 2007 also).

While booking a recurring event with a room calendar, I receive the message "This resource can only be scheduled up to 180 days in advance". Actual e-mail below. I was booking a biweekly event for a year.

-----Original Appointment-----
From: Training Room
Sent: Friday, November 21, 2014 5:16 PM
To: removed
Subject: Declined: Sales Meeting
When: Tuesday, June 09, 2015 8:30 AM-10:00 AM (UTC-05:00) Eastern Time (US & Canada).
Where: Training Room

Your meeting request was declined.

This resource can only be scheduled up to 180 days in advance. The end time should fall before 5/21/2015.

All times listed are in the following time zone: Eastern Standard Time


Come to find out that this is the default setting.

Execute Get-MailboxCalendarSettings "<mailbox alias>" | fl

Look at settings for BookingWindowInDays and EnforceSchedulingHorizon.




Change the setting with:

Set-MailboxCalendarSettings <mailbox alias> -BookingWindowInDays <Days>
OR
Set-MailboxCalendarSettings <mailbox alias> -EnforceSchedulingHorizon  $False

No need to do both.