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 = Get–Date # Todays Date $NoDays = “7“ $xUser = [System.Security.Principal.WindowsIdentity]::GetCurrent() $xUser = $xUser.Name $evt = new–object 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) { Write–Host “Number of Arguments: “ –NoNewLine Write–Host $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} } Write–Debug $Args[$i] } } If ($doHelp) { Write–host $AppName –NoNewLine –foregroundcolor Green Write–host “ – HELP!“ Write–Host $CmdLineOptions Exit } Start–Transcript –Path “$AppName.log“ $xComp = (Get–Date).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 = New–Object DirectoryServices.DirectoryEntry $Dom $selector = New–Object DirectoryServices.DirectorySearcher $selector.PageSize = 1000$selector.SearchRoot = $root $objs= $selector.findall() ######################################################################################### #Display script name and version ######################################################################################### Write–host “ “ $AppName –NoNewLine –foregroundcolor Green Write–Host “: “ $AppVer –foregroundcolor Green Write–host “`n Run on $ServerName at $Today by $xUser“ –foregroundcolor Yellow Write–Host “|——————————————————————-|`n“ Write–Host $Dom –foregroundcolor Yellow Write–Host “`nExchange Active Directory Objects that have changed… “Write–Host “..in the last “ –nonewline Write–Host $NoDays –foregroundcolor red –nonewline Write–Host “ days [since $xcomp]“ $i=0Write–Host “`nTotal number objects found: “ –nonewline Write–Host $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++ Write–Host “`nName: $xName“ –foregroundcolor Yellow Write–host “Path: $xads“ Write–Host “Last Changed : $xChange“ } } Write–Host “$i objects modified in the last $NoDays days“ –foregroundcolor Yellow Stop–Transcript ########################################
################################################# #Read in Transcript and add to Message Body ######################################################################################### $TranscriptOutput = Get–Content “$AppName.log“Write–Debug “Adding transcript to Email Message Body“ForEach ($xLine in $TranscriptOutput) { $MsgBody += “$xLine`n`n“} ######################################################################################### #Send email with attachments ######################################################################################### If ($InServer –ne $Null) {$MsgSubject += “ for $InServer“} IF ($doEmail) { .send–mail.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 #########################################################################################
################################################# #Read in Transcript and add to Message Body ######################################################################################### $TranscriptOutput = Get–Content “$AppName.log“Write–Debug “Adding transcript to Email Message Body“ForEach ($xLine in $TranscriptOutput) { $MsgBody += “$xLine`n`n“} ######################################################################################### #Send email with attachments ######################################################################################### If ($InServer –ne $Null) {$MsgSubject += “ for $InServer“} IF ($doEmail) { .send–mail.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