Number of active active sync devices connected to Exchange

Happy Monday everyone,  I haven’t posted anything in a while so I thought I would do a quick post of a short script I wrote the other day.  I was curious how many ActiveSync devices connected that were actively being used in our Exchange.  So after scouring around and discovering the get-mobiledevicestatistics cmdlet for Exchange I came up with the below.


get-mailbox -resultsize unlimited | foreach {Get-MobileDeviceStatistics -mailbox $_.Identity  | Where-Object {$_.LastSuccessSync -gt "06/01/2017"} | select-object identity, LastSuccessSync }

This will give you the identity of the device and the last successful sync time.  You could then pipe this into a export-csv to get a copy of the report or measure-object  to get a count of the objects.   Make sure to change the LastSuccessSync date.

Have a great week everyone.

Finding messages sent to a distribution group in Exchange message tracking.

It’s pretty easy to use the get-messagetrackinglog cmdlet to find what mail was sent to a particular mailbox and by whom but what if you wanted to search for emails sent to a distribution list to make sure they were indeed being sent there.  I had a distribution list today that someone said they weren’t receiving any emails sent to it.  It was caused by another issue but the message tracking log allowed me to get a better idea of what was actually being sent to the distribution group.

capture

So if for some reason you want to find out what is being sent to a distribution group
see the PowerShell below.

Get-MessageTrackingLog -resultsize unlimited -EventID Expand | ? {$_.RelatedRecipientAddress -like "distributiongroup@domain.com"} | ft Timestamp,Sender,MessageSubject -Autosize

Mail-enable already created distribution group.

Today I had an AD administrator create a distribution group and add all the members to it in Active Directory.  They needed it enabled in Exchange so I thought easy just go into the EAC (Exchange Administrative Center) and add an existing group.  This was the case in Exchange 2007 and 2010 but not in 2013.  In order to add an existing group so you don’t have to recreate it from the EAC and add all the users back you go into EMC (Exchange Management Console).  Then once in Powershell type in the command belowmail-enable.

Enable-DistributionGroup -Identity “groupnameinAD” -Alias “groupname”
-DisplayName “displayname"

 

 

Simple RoboCopy Function for quick transfers

A couple of weeks ago I got to thinking, I do these little robocopy transfers all the time why not write a function so I can do a transfer and I don’t have to go looking up all the parameters.  So after a few minutes, the below script was born.  Simply run the script in Powershell, and it will prompt for the old folder (source) and the new folder (destination).  Once the copy is complete it will monitor the source directory and copy any changes until you exit the script which is great when a user is still working in the source directory such as when you need to move a home directory.  It also sticks a log file in the directory you ran the script.  Just keep in mind that this is setup to be a mirror copy and if you reverse the source and destination you will copy the blank destination to your source and end up with a blank directory.

It’s an extremely simple script but maybe it will save someone a little time.  Also in case you haven’t aren’t familiar with robocopy it is the best folder syncing tool out there and has been available since Windows Server 2003.  It won’t sync single files but will sync folders up wherever you need them, resume transfers where they left off on flaky network connections, allows throttling and much more.

function fun-robocopy {
$ScriptPath = (Get-Item -Path ".\" -Verbose).FullName
$Logfile = $ScriptPath+"\Robocopy Logfile.log"
$OLDFolder = Read-Host -Prompt 'Input Old folder to move'
$NewFolder = Read-Host -Prompt 'Input New folder to move to'
Robocopy $OldFolder $NewFolder /MIR /COPYALL /V /FP /XO /LOG+:$Logfile /TEE /Z /MON:1 /MOT:30 /W:5 /R:2
}
fun-robocopy
snip_20160531170841