Get-ExchangeADChanges.ps1

So I  needed a way to check what has changed in the Exchange Configuration container … basically if something stopped worked ;-)

So I came up with this.  I run it once a week, and it checks for changes in the last 7 days.

It has one command line option and that is –email to email the results :-D

 


$Error.Clear() ######################################################################################### $AppName = Get-ExchangeADChanges.ps1$AppVer = v1.0 [11 September 2008]#v1.0 11 September 2008 : A script is Born # #This script looks the the configuration container in the AD and lists objects that # that have changed in the last x days # By default it is the last 7 days # # #Written By Paul Flaherty #blogs.flaphead.com # #Common Variables $ServerName = hostname # Server Name $ServerName = $ServerName.ToUpper() $Today = GetDate # Todays Date $NoDays = 7 $xUser = [System.Security.Principal.WindowsIdentity]::GetCurrent() $xUser = $xUser.Name $evt = newobject System.Diagnostics.EventLog(Application) $Warnevent = [System.Diagnostics.EventLogEntryType]::Warning $evt.Source = PowerShellMonitoring$MsgBody = Exchange Server 2007 Change Status`n`n$MsgFrom = $ServerName@NoReply.local$MsgSubject = PSM: Exchange 2007 Server AD Change Status as of $Today $WarningPreference = silentlyContinue######################################################################################### #Command Line Options ######################################################################################### $CmdLineOptions = @” COMMANDLINE OPTIONS No Commandline .. Default to a 7 day Check -EMAIL ………. Send an Email -? ………….. Displays this Help Text @ ######################################################################################### #Parse the Commnd Line ######################################################################################### $doEmail = $False $DelimitedArgs = $False If ($Args.count ge 1) { WriteHost Number of Arguments: NoNewLine WriteHost $Args.count $Args[0] = $Args[0].ToSTring() If ($Args[0].Contains()) {$DelimitedArgs = $True} if (($DelimitedArgs eq $False) AND ($Args.count ge 1)){$NoDays = $Args[0]} For($i=0;$i le $Args.Count 1; $i++) { $xArgs = $Args[$i] $xArgs = $xArgs.ToUpper() Switch ($xArgs) { -EMAIL {$doEmail = $True} -? {$doHelp = $True} } WriteDebug $Args[$i] } } If ($doHelp) { Writehost $AppName NoNewLine foregroundcolor Green Writehost – HELP! WriteHost $CmdLineOptions Exit } StartTranscript Path $AppName.log $xComp = (GetDate).AddDays($NoDays) $currentdom = [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain() $Forest = $currentdom.Forest.ToString() $Forest = $Forest.Replace(., ,DC=) $Forest = DC= + $Forest $Dom = LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration,$Dom += $Forest $Root = NewObject DirectoryServices.DirectoryEntry $Dom $selector = NewObject DirectoryServices.DirectorySearcher $selector.PageSize = 1000$selector.SearchRoot = $root $objs= $selector.findall() ######################################################################################### #Display script name and version ######################################################################################### Writehost $AppName NoNewLine foregroundcolor Green WriteHost : $AppVer foregroundcolor Green Writehost `n Run on $ServerName at $Today by $xUser foregroundcolor Yellow WriteHost |——————————————————————-|`n WriteHost $Dom foregroundcolor Yellow WriteHost `nExchange Active Directory Objects that have changed… WriteHost ..in the last nonewline WriteHost $NoDays foregroundcolor red nonewline WriteHost days [since $xcomp] $i=0WriteHost `nTotal number objects found: nonewline WriteHost $objs.count foregroundcolor Green ForEach($obj in $objs) { #adspath #distinguishedname #name $xADS = $obj.Properties.adspath $xName = $obj.Properties.name $xChange = $obj.properties.whenchanged if ($xChange ge $xComp) { $i++ WriteHost `nName: $xName foregroundcolor Yellow Writehost Path: $xads WriteHost Last Changed : $xChange } } WriteHost $i objects modified in the last $NoDays days foregroundcolor Yellow StopTranscript ########################################
################################################# #Read
in Transcript and add to Message Body ######################################################################################### $TranscriptOutput = GetContent $AppName.logWriteDebug Adding transcript to Email Message BodyForEach ($xLine in $TranscriptOutput) { $MsgBody += $xLine`n`n} ######################################################################################### #Send email with attachments ######################################################################################### If ($InServer ne $Null) {$MsgSubject += for $InServer} IF ($doEmail) { .sendmail.ps1 Server AutoDiscover tocsv c:ps_emailAlertList1.txt from $MsgFrom Subject $MsgSubject body $MsgBody attachment C:PS$AppName.log} $evt.WriteEntry($ServiceStatus,$infoevent,1000) ######################################################################################### #End #########################################################################################

 

The file is attached

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.