Documente Academic
Documente Profesional
Documente Cultură
<#
.SYNOPSIS
Get-EASDeviceReport.ps1 - Exchange Server ActiveSync device report
.DESCRIPTION
Produces a report of ActiveSync device associations in the organization.
.OUTPUTS
Results are output to screen, as well as optional log file, HTML report, and HTML
email
.PARAMETER SendEmail
Sends the HTML report via email using the SMTP configuration within the script.
.EXAMPLE
.\Get-EASDeviceReport.ps1
Produces a CSV file containing stats for all ActiveSync devices.
.EXAMPLE
.\Get-EASDeviceReport.ps1 -SendEmail
-MailFrom:exchangeserver@exchangeserverpro.net
-MailTo:paul@exchangeserverpro.com -MailServer:smtp.exchangeserverpro.net
Sends an email report with CSV file attached for all ActiveSync devices.
.EXAMPLE
.\Get-EASDeviceReport.ps1 -Age 30
Limits the report to devices that have not attempted synced in more than 30 days.
.NOTES
Written by: Paul Cunningham
Find me on:
* My Blog:
http://paulcunningham.me
* Twitter:
https://twitter.com/paulcunningham
* LinkedIn:
http://au.linkedin.com/in/cunninghamp/
* Github:
https://github.com/cunninghamp
* Website:
http://exchangeserverpro.com
* Twitter:
http://twitter.com/exchservpro
Change Log
V1.00, 25/11/2013 - Initial version
V1.01, 11/02/2014 - Added parameters for emailing the report and specifying an
"age" to report on
V1.02, 17/02/2014 - Fixed missing $mydir variable and added UTF8 encoding to
Export-CSV and Send-MailMessage
#>
#requires -version 2
[CmdletBinding()]
param (
[Parameter( Mandatory=$false)]
[switch]$SendEmail,
[Parameter( Mandatory=$false)]
[string]$MailFrom,
[Parameter( Mandatory=$false)]
[string]$MailTo,
[Parameter( Mandatory=$false)]
[string]$MailServer,
[Parameter( Mandatory=$false)]
[int]$Age = 0
#...................................
# Variables
#...................................
$now = Get-Date
#Used for timestamps
$date = $now.ToShortDateString()
format for email message subject
$report = @()
$stats = @("DeviceID",
"DeviceAccessState",
"DeviceAccessStateReason",
"DeviceModel"
"DeviceType",
"DeviceFriendlyName",
"DeviceOS",
"LastSyncAttemptTime",
"LastSuccessSync"
)
#...................................
# Email Settings
#Short date
#...................................
$smtpsettings = @{
To = $MailTo
From = $MailFrom
Subject = $reportemailsubject
SmtpServer = $MailServer
}
#...................................
# Initialize
#...................................
#Add Exchange 2010/2013 snapin if not already loaded in the PowerShell session
if (!(Get-PSSnapin | where {$_.Name -eq
"Microsoft.Exchange.Management.PowerShell.E2010"}))
{
try
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
-ErrorAction STOP
}
catch
{
#Snapin was not loaded
Write-Warning $_.Exception.Message
EXIT
}
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -auto -AllowClobber
}
#...................................
# Script
#...................................
$lastsyncattempt = ($EASDevice.LastSyncAttemptTime)
$report += $reportObj
}
}
}
if ($SendEmail)
{
$htmlhead="<html>
<style>
$htmltail = "</body></html>"